2025-03-19 23:14:54 +11:00
|
|
|
import React, { useCallback, useState } from 'react';
|
2025-02-27 19:34:55 +11:00
|
|
|
import { Box, Text, IconButton, Icon, Icons, Scroll, Switch, Button } from 'folds';
|
2025-02-10 16:49:47 +11:00
|
|
|
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';
|
2025-03-19 23:14:54 +11:00
|
|
|
import {
|
|
|
|
|
AccountDataEditor,
|
|
|
|
|
AccountDataSubmitCallback,
|
|
|
|
|
} from '../../../components/AccountDataEditor';
|
2025-02-10 16:49:47 +11:00
|
|
|
import { copyToClipboard } from '../../../utils/dom';
|
2025-02-27 19:34:55 +11:00
|
|
|
import { AccountData } from './AccountData';
|
2025-02-10 16:49:47 +11:00
|
|
|
|
|
|
|
|
type DeveloperToolsProps = {
|
|
|
|
|
requestClose: () => void;
|
|
|
|
|
};
|
|
|
|
|
export function DeveloperTools({ requestClose }: DeveloperToolsProps) {
|
|
|
|
|
const mx = useMatrixClient();
|
|
|
|
|
const [developerTools, setDeveloperTools] = useSetting(settingsAtom, 'developerTools');
|
2025-02-27 19:34:55 +11:00
|
|
|
const [expand, setExpend] = useState(false);
|
|
|
|
|
const [accountDataType, setAccountDataType] = useState<string | null>();
|
|
|
|
|
|
2025-03-19 23:14:54 +11:00
|
|
|
const submitAccountData: AccountDataSubmitCallback = useCallback(
|
|
|
|
|
async (type, content) => {
|
|
|
|
|
await mx.setAccountData(type, content);
|
|
|
|
|
},
|
|
|
|
|
[mx]
|
|
|
|
|
);
|
|
|
|
|
|
2025-02-27 19:34:55 +11:00
|
|
|
if (accountDataType !== undefined) {
|
|
|
|
|
return (
|
|
|
|
|
<AccountDataEditor
|
|
|
|
|
type={accountDataType ?? undefined}
|
2025-03-19 23:14:54 +11:00
|
|
|
content={accountDataType ? mx.getAccountData(accountDataType)?.getContent() : undefined}
|
|
|
|
|
submitChange={submitAccountData}
|
2025-02-27 19:34:55 +11:00
|
|
|
requestClose={() => setAccountDataType(undefined)}
|
|
|
|
|
/>
|
|
|
|
|
);
|
|
|
|
|
}
|
2025-02-10 16:49:47 +11:00
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<Page>
|
|
|
|
|
<PageHeader outlined={false}>
|
|
|
|
|
<Box grow="Yes" gap="200">
|
|
|
|
|
<Box grow="Yes" alignItems="Center" gap="200">
|
|
|
|
|
<Text size="H3" truncate>
|
|
|
|
|
Developer Tools
|
|
|
|
|
</Text>
|
|
|
|
|
</Box>
|
|
|
|
|
<Box shrink="No">
|
|
|
|
|
<IconButton onClick={requestClose} variant="Surface">
|
|
|
|
|
<Icon src={Icons.Cross} />
|
|
|
|
|
</IconButton>
|
|
|
|
|
</Box>
|
|
|
|
|
</Box>
|
|
|
|
|
</PageHeader>
|
|
|
|
|
<Box grow="Yes">
|
|
|
|
|
<Scroll hideTrack visibility="Hover">
|
|
|
|
|
<PageContent>
|
|
|
|
|
<Box direction="Column" gap="700">
|
|
|
|
|
<Box direction="Column" gap="100">
|
|
|
|
|
<Text size="L400">Options</Text>
|
|
|
|
|
<SequenceCard
|
|
|
|
|
className={SequenceCardStyle}
|
|
|
|
|
variant="SurfaceVariant"
|
|
|
|
|
direction="Column"
|
|
|
|
|
gap="400"
|
|
|
|
|
>
|
|
|
|
|
<SettingTile
|
|
|
|
|
title="Enable Developer Tools"
|
|
|
|
|
after={
|
|
|
|
|
<Switch
|
|
|
|
|
variant="Primary"
|
|
|
|
|
value={developerTools}
|
|
|
|
|
onChange={setDeveloperTools}
|
|
|
|
|
/>
|
|
|
|
|
}
|
|
|
|
|
/>
|
|
|
|
|
</SequenceCard>
|
|
|
|
|
{developerTools && (
|
|
|
|
|
<SequenceCard
|
|
|
|
|
className={SequenceCardStyle}
|
|
|
|
|
variant="SurfaceVariant"
|
|
|
|
|
direction="Column"
|
|
|
|
|
gap="400"
|
|
|
|
|
>
|
|
|
|
|
<SettingTile
|
|
|
|
|
title="Access Token"
|
|
|
|
|
description="Copy access token to clipboard."
|
|
|
|
|
after={
|
|
|
|
|
<Button
|
|
|
|
|
onClick={() =>
|
|
|
|
|
copyToClipboard(mx.getAccessToken() ?? '<NO_ACCESS_TOKEN_FOUND>')
|
|
|
|
|
}
|
|
|
|
|
variant="Secondary"
|
|
|
|
|
fill="Soft"
|
|
|
|
|
size="300"
|
|
|
|
|
radii="300"
|
|
|
|
|
outlined
|
|
|
|
|
>
|
|
|
|
|
<Text size="B300">Copy</Text>
|
|
|
|
|
</Button>
|
|
|
|
|
}
|
|
|
|
|
/>
|
|
|
|
|
</SequenceCard>
|
|
|
|
|
)}
|
|
|
|
|
</Box>
|
2025-02-27 19:34:55 +11:00
|
|
|
{developerTools && (
|
|
|
|
|
<AccountData
|
|
|
|
|
expand={expand}
|
|
|
|
|
onExpandToggle={setExpend}
|
|
|
|
|
onSelect={setAccountDataType}
|
|
|
|
|
/>
|
|
|
|
|
)}
|
2025-02-10 16:49:47 +11:00
|
|
|
</Box>
|
|
|
|
|
</PageContent>
|
|
|
|
|
</Scroll>
|
|
|
|
|
</Box>
|
|
|
|
|
</Page>
|
|
|
|
|
);
|
|
|
|
|
}
|