From ef8d09e2f2782ba2b2deb7f116d38269d5aeab32 Mon Sep 17 00:00:00 2001
From: Ajay Bura <32841439+ajbura@users.noreply.github.com>
Date: Wed, 18 Dec 2024 21:21:03 +0530
Subject: [PATCH] add developer tools settings
---
src/app/features/settings/Settings.tsx | 4 +
.../settings/developer-tools/DevelopTools.tsx | 166 ++++++++++++++++++
.../settings/developer-tools/index.ts | 1 +
src/app/state/settings.ts | 4 +
4 files changed, 175 insertions(+)
create mode 100644 src/app/features/settings/developer-tools/DevelopTools.tsx
create mode 100644 src/app/features/settings/developer-tools/index.ts
diff --git a/src/app/features/settings/Settings.tsx b/src/app/features/settings/Settings.tsx
index 3b28aad2..4a55265b 100644
--- a/src/app/features/settings/Settings.tsx
+++ b/src/app/features/settings/Settings.tsx
@@ -11,6 +11,7 @@ import { useMediaAuthentication } from '../../hooks/useMediaAuthentication';
import { UserAvatar } from '../../components/user-avatar';
import { nameInitials } from '../../utils/common';
import { Notifications } from './notifications';
+import { DeveloperTools } from './developer-tools';
import { About } from './about';
enum SettingsPages {
@@ -169,6 +170,9 @@ export function Settings({ initialPage, requestClose }: SettingsProps) {
{activePage === SettingsPages.NotificationPage && (
)}
+ {activePage === SettingsPages.DeveloperToolsPage && (
+
+ )}
{activePage === SettingsPages.AboutPage && }
);
diff --git a/src/app/features/settings/developer-tools/DevelopTools.tsx b/src/app/features/settings/developer-tools/DevelopTools.tsx
new file mode 100644
index 00000000..1b657e16
--- /dev/null
+++ b/src/app/features/settings/developer-tools/DevelopTools.tsx
@@ -0,0 +1,166 @@
+import React, { MouseEventHandler, useCallback, useState } from 'react';
+import {
+ Box,
+ Text,
+ IconButton,
+ Icon,
+ Icons,
+ Scroll,
+ Switch,
+ Overlay,
+ OverlayBackdrop,
+ OverlayCenter,
+ Modal,
+ Chip,
+ config,
+} from 'folds';
+import { MatrixEvent } from 'matrix-js-sdk';
+import FocusTrap from 'focus-trap-react';
+import { Page, PageContent, PageHeader } from '../../../components/page';
+import { SequenceCard } from '../../../components/sequence-card';
+import { SequenceCardStyle } from '../styles.css';
+import { SettingTile } from '../../../components/setting-tile';
+import { useSetting } from '../../../state/hooks/settings';
+import { settingsAtom } from '../../../state/settings';
+import { useMatrixClient } from '../../../hooks/useMatrixClient';
+import { useAccountDataCallback } from '../../../hooks/useAccountDataCallback';
+import { TextViewer } from '../../../components/text-viewer';
+import { stopPropagation } from '../../../utils/keyboard';
+
+function AccountData() {
+ const mx = useMatrixClient();
+ const [accountData, setAccountData] = useState(() => Array.from(mx.store.accountData.values()));
+ const [selectedEvent, selectEvent] = useState();
+
+ useAccountDataCallback(
+ mx,
+ useCallback(
+ () => setAccountData(Array.from(mx.store.accountData.values())),
+ [mx, setAccountData]
+ )
+ );
+
+ const handleView: MouseEventHandler = (evt) => {
+ const target = evt.currentTarget;
+ const eventType = target.getAttribute('data-event-type');
+ if (eventType) {
+ const mEvent = accountData.find((mEvt) => mEvt.getType() === eventType);
+ selectEvent(mEvent);
+ }
+ };
+
+ const handleClose = () => selectEvent(undefined);
+
+ return (
+
+ Account Data
+
+
+
+ Types
+
+ {accountData.map((mEvent) => (
+
+
+ {mEvent.getType()}
+
+
+ ))}
+
+
+
+
+ {selectedEvent && (
+ }>
+
+
+
+
+
+
+
+
+ )}
+
+ );
+}
+
+type DeveloperToolsProps = {
+ requestClose: () => void;
+};
+export function DeveloperTools({ requestClose }: DeveloperToolsProps) {
+ const [developerTools, setDeveloperTools] = useSetting(settingsAtom, 'developerTools');
+
+ return (
+
+
+
+
+
+ Developer Tools
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Options
+
+
+ }
+ />
+
+
+ {developerTools && }
+
+
+
+
+
+ );
+}
diff --git a/src/app/features/settings/developer-tools/index.ts b/src/app/features/settings/developer-tools/index.ts
new file mode 100644
index 00000000..1fcceff5
--- /dev/null
+++ b/src/app/features/settings/developer-tools/index.ts
@@ -0,0 +1 @@
+export * from './DevelopTools';
diff --git a/src/app/state/settings.ts b/src/app/state/settings.ts
index 4d495690..ac47e78b 100644
--- a/src/app/state/settings.ts
+++ b/src/app/state/settings.ts
@@ -32,6 +32,8 @@ export interface Settings {
showNotifications: boolean;
isNotificationSounds: boolean;
+
+ developerTools: boolean;
}
const defaultSettings: Settings = {
@@ -58,6 +60,8 @@ const defaultSettings: Settings = {
showNotifications: true,
isNotificationSounds: true,
+
+ developerTools: false,
};
export const getSettings = () => {