import { WebApplication } from '@/ui_models/application'; import { AppState } from '@/ui_models/app_state'; import { observer } from 'mobx-react-lite'; import { Icon } from '../Icon'; import { formatLastSyncDate } from '@/preferences/panes/account/Sync'; import { SyncQueueStrategy } from '@standardnotes/snjs'; import { STRING_GENERIC_SYNC_ERROR } from '@/strings'; import { useState } from 'preact/hooks'; import { AccountMenuPane } from '.'; import { FunctionComponent } from 'preact'; import { Menu } from '../menu/Menu'; import { MenuItem, MenuItemSeparator, MenuItemType } from '../menu/MenuItem'; type Props = { appState: AppState; application: WebApplication; setMenuPane: (pane: AccountMenuPane) => void; closeMenu: () => void; }; const iconClassName = 'color-neutral mr-2'; export const GeneralAccountMenu: FunctionComponent = observer( ({ application, appState, setMenuPane, closeMenu }) => { const [isSyncingInProgress, setIsSyncingInProgress] = useState(false); const [lastSyncDate, setLastSyncDate] = useState( formatLastSyncDate(application.getLastSyncDate() as Date) ); const doSynchronization = async () => { setIsSyncingInProgress(true); application .sync({ queueStrategy: SyncQueueStrategy.ForceSpawnNew, checkIntegrity: true, }) .then((res) => { if (res && res.error) { throw new Error(); } else { setLastSyncDate( formatLastSyncDate(application.getLastSyncDate() as Date) ); } }) .catch(() => { application.alertService.alert(STRING_GENERIC_SYNC_ERROR); }) .finally(() => { setIsSyncingInProgress(false); }); }; const user = application.getUser(); return ( <>
Account
{user ? ( <>
You're signed in as:
{user.email}
{application.getHost()}
{isSyncingInProgress ? (
Syncing...
) : (
Last synced:
{lastSyncDate}
)}
) : ( <>
You’re offline. Sign in to sync your notes and preferences across all your devices and enable end-to-end encryption.
Offline
)}
{user ? ( { appState.accountMenu.closeAccountMenu(); appState.preferences.setCurrentPane('account'); appState.preferences.openPreferences(); }} > Account settings ) : ( <> { setMenuPane(AccountMenuPane.Register); }} > Create free account { setMenuPane(AccountMenuPane.SignIn); }} > Sign in )} { appState.accountMenu.closeAccountMenu(); appState.preferences.setCurrentPane('help-feedback'); appState.preferences.openPreferences(); }} >
Help & feedback
v{appState.version}
{user ? ( <> { appState.accountMenu.setSigningOut(true); }} > Sign out and clear local data ) : null}
); } );