refactor: new snjs support (#967)
This commit is contained in:
@@ -1,12 +1,6 @@
|
||||
import { action, makeAutoObservable, observable } from 'mobx';
|
||||
import { ExtensionsLatestVersions } from '@/components/Preferences/panes/extensions-segments';
|
||||
import {
|
||||
ComponentArea,
|
||||
ContentType,
|
||||
FeatureIdentifier,
|
||||
SNComponent,
|
||||
IconType,
|
||||
} from '@standardnotes/snjs';
|
||||
import { FeatureIdentifier, IconType } from '@standardnotes/snjs';
|
||||
import { WebApplication } from '@/ui_models/application';
|
||||
|
||||
const PREFERENCE_IDS = [
|
||||
@@ -61,7 +55,6 @@ const READY_PREFERENCES_MENU_ITEMS: PreferencesMenuItem[] = [
|
||||
|
||||
export class PreferencesMenu {
|
||||
private _selectedPane: PreferenceId | FeatureIdentifier = 'account';
|
||||
private _extensionPanes: SNComponent[] = [];
|
||||
private _menu: PreferencesMenuItem[];
|
||||
private _extensionLatestVersions: ExtensionsLatestVersions =
|
||||
new ExtensionsLatestVersions(new Map());
|
||||
@@ -74,7 +67,6 @@ export class PreferencesMenu {
|
||||
? PREFERENCES_MENU_ITEMS
|
||||
: READY_PREFERENCES_MENU_ITEMS;
|
||||
|
||||
this.loadExtensionsPanes();
|
||||
this.loadLatestVersions();
|
||||
|
||||
makeAutoObservable<
|
||||
@@ -105,64 +97,24 @@ export class PreferencesMenu {
|
||||
return this._extensionLatestVersions;
|
||||
}
|
||||
|
||||
loadExtensionsPanes(): void {
|
||||
const excludedComponents = [
|
||||
FeatureIdentifier.TwoFactorAuthManager,
|
||||
'org.standardnotes.batch-manager',
|
||||
'org.standardnotes.extensions-manager',
|
||||
FeatureIdentifier.CloudLink,
|
||||
];
|
||||
this._extensionPanes = (
|
||||
this.application.items.getItems([
|
||||
ContentType.ActionsExtension,
|
||||
ContentType.Component,
|
||||
ContentType.Theme,
|
||||
]) as SNComponent[]
|
||||
).filter(
|
||||
(extension) =>
|
||||
extension.area === ComponentArea.Modal &&
|
||||
!excludedComponents.includes(extension.package_info.identifier)
|
||||
);
|
||||
}
|
||||
|
||||
get menuItems(): SelectableMenuItem[] {
|
||||
const menuItems = this._menu.map((preference) => ({
|
||||
...preference,
|
||||
selected: preference.id === this._selectedPane,
|
||||
}));
|
||||
const extensionsMenuItems: SelectableMenuItem[] = this._extensionPanes.map(
|
||||
(extension) => {
|
||||
return {
|
||||
icon: 'window',
|
||||
id: extension.package_info.identifier,
|
||||
label: extension.name,
|
||||
selected: extension.package_info.identifier === this._selectedPane,
|
||||
};
|
||||
}
|
||||
);
|
||||
|
||||
return menuItems.concat(extensionsMenuItems);
|
||||
return menuItems;
|
||||
}
|
||||
|
||||
get selectedMenuItem(): PreferencesMenuItem | undefined {
|
||||
return this._menu.find((item) => item.id === this._selectedPane);
|
||||
}
|
||||
|
||||
get selectedExtension(): SNComponent | undefined {
|
||||
return this._extensionPanes.find(
|
||||
(extension) => extension.package_info.identifier === this._selectedPane
|
||||
);
|
||||
}
|
||||
|
||||
get selectedPaneId(): PreferenceId | FeatureIdentifier {
|
||||
if (this.selectedMenuItem != undefined) {
|
||||
return this.selectedMenuItem.id;
|
||||
}
|
||||
|
||||
if (this.selectedExtension != undefined) {
|
||||
return this.selectedExtension.package_info.identifier;
|
||||
}
|
||||
|
||||
return 'account';
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
import { RoundIconButton } from '@/components/RoundIconButton';
|
||||
import { TitleBar, Title } from '@/components/TitleBar';
|
||||
import { FunctionComponent } from 'preact';
|
||||
import { observer } from 'mobx-react-lite';
|
||||
|
||||
import {
|
||||
AccountPreferences,
|
||||
HelpAndFeedback,
|
||||
@@ -8,15 +10,12 @@ import {
|
||||
General,
|
||||
Security,
|
||||
} from './panes';
|
||||
import { observer } from 'mobx-react-lite';
|
||||
|
||||
import { PreferencesMenu } from './PreferencesMenu';
|
||||
import { PreferencesMenuView } from './PreferencesMenuView';
|
||||
import { WebApplication } from '@/ui_models/application';
|
||||
import { MfaProps } from './panes/two-factor-auth/MfaProps';
|
||||
import { AppState } from '@/ui_models/app_state';
|
||||
import { useEffect, useMemo } from 'preact/hooks';
|
||||
import { ExtensionPane } from './panes/ExtensionPane';
|
||||
import { Backups } from '@/components/Preferences/panes/Backups';
|
||||
import { Appearance } from './panes/Appearance';
|
||||
|
||||
@@ -66,24 +65,13 @@ const PaneSelector: FunctionComponent<
|
||||
case 'help-feedback':
|
||||
return <HelpAndFeedback />;
|
||||
default:
|
||||
if (menu.selectedExtension != undefined) {
|
||||
return (
|
||||
<ExtensionPane
|
||||
application={application}
|
||||
appState={appState}
|
||||
extension={menu.selectedExtension}
|
||||
preferencesMenu={menu}
|
||||
/>
|
||||
);
|
||||
} else {
|
||||
return (
|
||||
<General
|
||||
appState={appState}
|
||||
application={application}
|
||||
extensionsLatestVersions={menu.extensionsLatestVersions}
|
||||
/>
|
||||
);
|
||||
}
|
||||
return (
|
||||
<General
|
||||
appState={appState}
|
||||
application={application}
|
||||
extensionsLatestVersions={menu.extensionsLatestVersions}
|
||||
/>
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
@@ -4,12 +4,12 @@ import { sortThemes } from '@/components/QuickSettingsMenu/QuickSettingsMenu';
|
||||
import { HorizontalSeparator } from '@/components/Shared/HorizontalSeparator';
|
||||
import { Switch } from '@/components/Switch';
|
||||
import { WebApplication } from '@/ui_models/application';
|
||||
import { GetFeatures } from '@standardnotes/features';
|
||||
import {
|
||||
ContentType,
|
||||
FeatureIdentifier,
|
||||
FeatureStatus,
|
||||
PrefKey,
|
||||
GetFeatures,
|
||||
SNTheme,
|
||||
} from '@standardnotes/snjs';
|
||||
import { observer } from 'mobx-react-lite';
|
||||
@@ -61,9 +61,8 @@ export const Appearance: FunctionComponent<Props> = observer(
|
||||
);
|
||||
|
||||
useEffect(() => {
|
||||
const themesAsItems: DropdownItem[] = (
|
||||
application.items.getDisplayableItems(ContentType.Theme) as SNTheme[]
|
||||
)
|
||||
const themesAsItems: DropdownItem[] = application.items
|
||||
.getDisplayableItems<SNTheme>(ContentType.Theme)
|
||||
.filter((theme) => !theme.isLayerable())
|
||||
.sort(sortThemes)
|
||||
.map((theme) => {
|
||||
|
||||
@@ -1,79 +0,0 @@
|
||||
import {
|
||||
PreferencesGroup,
|
||||
PreferencesSegment,
|
||||
} from '@/components/Preferences/components';
|
||||
import { WebApplication } from '@/ui_models/application';
|
||||
import { ComponentViewer, SNComponent } from '@standardnotes/snjs';
|
||||
import { FeatureIdentifier } from '@standardnotes/features';
|
||||
import { observer } from 'mobx-react-lite';
|
||||
import { FunctionComponent } from 'preact';
|
||||
import { ExtensionItem } from './extensions-segments';
|
||||
import { ComponentView } from '@/components/ComponentView';
|
||||
import { AppState } from '@/ui_models/app_state';
|
||||
import { PreferencesMenu } from '@/components/Preferences/PreferencesMenu';
|
||||
import { useEffect, useState } from 'preact/hooks';
|
||||
|
||||
interface IProps {
|
||||
application: WebApplication;
|
||||
appState: AppState;
|
||||
extension: SNComponent;
|
||||
preferencesMenu: PreferencesMenu;
|
||||
}
|
||||
|
||||
const urlOverrideForExtension = (extension: SNComponent) => {
|
||||
if (extension.identifier === FeatureIdentifier.CloudLink) {
|
||||
return 'https://extensions.standardnotes.org/components/cloudlink';
|
||||
} else {
|
||||
return undefined;
|
||||
}
|
||||
};
|
||||
|
||||
export const ExtensionPane: FunctionComponent<IProps> = observer(
|
||||
({ extension, application, appState, preferencesMenu }) => {
|
||||
const [componentViewer] = useState<ComponentViewer>(
|
||||
application.componentManager.createComponentViewer(
|
||||
extension,
|
||||
undefined,
|
||||
undefined,
|
||||
urlOverrideForExtension(extension)
|
||||
)
|
||||
);
|
||||
const latestVersion =
|
||||
preferencesMenu.extensionsLatestVersions.getVersion(extension);
|
||||
|
||||
useEffect(() => {
|
||||
return () => {
|
||||
application.componentManager.destroyComponentViewer(componentViewer);
|
||||
};
|
||||
}, [application, componentViewer]);
|
||||
|
||||
return (
|
||||
<div className="preferences-extension-pane color-foreground flex-grow flex flex-row overflow-y-auto min-h-0">
|
||||
<div className="flex-grow flex flex-col py-6 items-center">
|
||||
<div className="w-200 max-w-200 flex flex-col">
|
||||
<PreferencesGroup>
|
||||
<ExtensionItem
|
||||
application={application}
|
||||
extension={extension}
|
||||
first={false}
|
||||
uninstall={() =>
|
||||
application.mutator
|
||||
.deleteItem(extension)
|
||||
.then(() => preferencesMenu.loadExtensionsPanes())
|
||||
}
|
||||
latestVersion={latestVersion}
|
||||
/>
|
||||
<PreferencesSegment>
|
||||
<ComponentView
|
||||
application={application}
|
||||
appState={appState}
|
||||
componentViewer={componentViewer}
|
||||
/>
|
||||
</PreferencesSegment>
|
||||
</PreferencesGroup>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
);
|
||||
@@ -13,10 +13,11 @@ import { useEffect, useRef, useState } from 'preact/hooks';
|
||||
import { observer } from 'mobx-react-lite';
|
||||
|
||||
const loadExtensions = (application: WebApplication) =>
|
||||
application.items.getItems(
|
||||
[ContentType.ActionsExtension, ContentType.Component, ContentType.Theme],
|
||||
true
|
||||
) as SNComponent[];
|
||||
application.items.getItems([
|
||||
ContentType.ActionsExtension,
|
||||
ContentType.Component,
|
||||
ContentType.Theme,
|
||||
]) as SNComponent[];
|
||||
|
||||
export const Extensions: FunctionComponent<{
|
||||
application: WebApplication;
|
||||
|
||||
@@ -13,16 +13,16 @@ import {
|
||||
Text,
|
||||
Title,
|
||||
} from '../../components';
|
||||
import {
|
||||
EmailBackupFrequency,
|
||||
MuteFailedBackupsEmailsOption,
|
||||
SettingName,
|
||||
} from '@standardnotes/settings';
|
||||
import { Dropdown, DropdownItem } from '@/components/Dropdown';
|
||||
import { Switch } from '@/components/Switch';
|
||||
import { HorizontalSeparator } from '@/components/Shared/HorizontalSeparator';
|
||||
import { FeatureIdentifier } from '@standardnotes/features';
|
||||
import { FeatureStatus } from '@standardnotes/snjs';
|
||||
import {
|
||||
FeatureStatus,
|
||||
FeatureIdentifier,
|
||||
EmailBackupFrequency,
|
||||
MuteFailedBackupsEmailsOption,
|
||||
SettingName,
|
||||
} from '@standardnotes/snjs';
|
||||
|
||||
type Props = {
|
||||
application: WebApplication;
|
||||
|
||||
@@ -1,11 +1,12 @@
|
||||
import { useCallback, useEffect, useState } from 'preact/hooks';
|
||||
import { ButtonType, SettingName } from '@standardnotes/snjs';
|
||||
import {
|
||||
ButtonType,
|
||||
SettingName,
|
||||
CloudProvider,
|
||||
DropboxBackupFrequency,
|
||||
GoogleDriveBackupFrequency,
|
||||
OneDriveBackupFrequency,
|
||||
} from '@standardnotes/settings';
|
||||
} from '@standardnotes/snjs';
|
||||
import { WebApplication } from '@/ui_models/application';
|
||||
import { Button } from '@/components/Button';
|
||||
import { isDev, openInNewTab } from '@/utils';
|
||||
|
||||
@@ -9,14 +9,15 @@ import {
|
||||
Title,
|
||||
} from '@/components/Preferences/components';
|
||||
import { HorizontalSeparator } from '@/components/Shared/HorizontalSeparator';
|
||||
import { FeatureIdentifier } from '@standardnotes/features';
|
||||
import { FeatureStatus } from '@standardnotes/snjs';
|
||||
import { FunctionComponent } from 'preact';
|
||||
import {
|
||||
FeatureStatus,
|
||||
FeatureIdentifier,
|
||||
CloudProvider,
|
||||
MuteFailedCloudBackupsEmailsOption,
|
||||
SettingName,
|
||||
} from '@standardnotes/settings';
|
||||
} from '@standardnotes/snjs';
|
||||
import { FunctionComponent } from 'preact';
|
||||
|
||||
import { Switch } from '@/components/Switch';
|
||||
import { convertStringifiedBooleanToBoolean } from '@/utils';
|
||||
import { STRING_FAILED_TO_UPDATE_USER_SETTING } from '@/strings';
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { displayStringForContentType, SNComponent } from '@standardnotes/snjs';
|
||||
import { DisplayStringForContentType, SNComponent } from '@standardnotes/snjs';
|
||||
import { Button } from '@/components/Button';
|
||||
import { FunctionComponent } from 'preact';
|
||||
import { Title, Text, Subtitle, PreferencesSegment } from '../../components';
|
||||
@@ -30,7 +30,7 @@ export const ConfirmCustomExtension: FunctionComponent<{
|
||||
},
|
||||
{
|
||||
label: 'Extension Type',
|
||||
value: displayStringForContentType(component.content_type),
|
||||
value: DisplayStringForContentType(component.content_type),
|
||||
},
|
||||
];
|
||||
|
||||
|
||||
@@ -47,7 +47,7 @@ export const ExtensionItem: FunctionComponent<ExtensionItemProps> = ({
|
||||
const newOfflineOnly = !offlineOnly;
|
||||
setOfflineOnly(newOfflineOnly);
|
||||
application.mutator
|
||||
.changeAndSaveItem(extension.uuid, (m: any) => {
|
||||
.changeAndSaveItem(extension, (m: any) => {
|
||||
if (m.content == undefined) m.content = {};
|
||||
m.content.offlineOnly = newOfflineOnly;
|
||||
})
|
||||
@@ -63,7 +63,7 @@ export const ExtensionItem: FunctionComponent<ExtensionItemProps> = ({
|
||||
const changeExtensionName = (newName: string) => {
|
||||
setExtensionName(newName);
|
||||
application.mutator
|
||||
.changeAndSaveItem(extension.uuid, (m: any) => {
|
||||
.changeAndSaveItem(extension, (m: any) => {
|
||||
if (m.content == undefined) m.content = {};
|
||||
m.content.name = newName;
|
||||
})
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
import { WebApplication } from '@/ui_models/application';
|
||||
import { FeatureDescription } from '@standardnotes/features';
|
||||
import { SNComponent, ClientDisplayableError } from '@standardnotes/snjs';
|
||||
import {
|
||||
SNComponent,
|
||||
ClientDisplayableError,
|
||||
FeatureDescription,
|
||||
} from '@standardnotes/snjs';
|
||||
import { makeAutoObservable, observable } from 'mobx';
|
||||
|
||||
export class ExtensionsLatestVersions {
|
||||
|
||||
@@ -34,7 +34,7 @@ const makeEditorDefault = (
|
||||
if (currentDefault) {
|
||||
removeEditorDefault(application, currentDefault);
|
||||
}
|
||||
application.mutator.changeAndSaveItem(component.uuid, (m) => {
|
||||
application.mutator.changeAndSaveItem(component, (m) => {
|
||||
const mutator = m as ComponentMutator;
|
||||
mutator.defaultEditor = true;
|
||||
});
|
||||
@@ -44,7 +44,7 @@ const removeEditorDefault = (
|
||||
application: WebApplication,
|
||||
component: SNComponent
|
||||
) => {
|
||||
application.mutator.changeAndSaveItem(component.uuid, (m) => {
|
||||
application.mutator.changeAndSaveItem(component, (m) => {
|
||||
const mutator = m as ComponentMutator;
|
||||
mutator.defaultEditor = false;
|
||||
});
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
import { FindNativeFeature } from '@standardnotes/features';
|
||||
import { Switch } from '@/components/Switch';
|
||||
import {
|
||||
PreferencesGroup,
|
||||
@@ -8,7 +7,11 @@ import {
|
||||
Title,
|
||||
} from '@/components/Preferences/components';
|
||||
import { WebApplication } from '@/ui_models/application';
|
||||
import { FeatureIdentifier, FeatureStatus } from '@standardnotes/snjs';
|
||||
import {
|
||||
FeatureIdentifier,
|
||||
FeatureStatus,
|
||||
FindNativeFeature,
|
||||
} from '@standardnotes/snjs';
|
||||
import { FunctionComponent } from 'preact';
|
||||
import { useCallback, useEffect, useState } from 'preact/hooks';
|
||||
import { usePremiumModal } from '@/components/Premium';
|
||||
|
||||
@@ -12,7 +12,7 @@ import {
|
||||
MuteSignInEmailsOption,
|
||||
LogSessionUserAgentOption,
|
||||
SettingName,
|
||||
} from '@standardnotes/settings';
|
||||
} from '@standardnotes/snjs';
|
||||
import { observer } from 'mobx-react-lite';
|
||||
import { FunctionalComponent } from 'preact';
|
||||
import { useCallback, useEffect, useState } from 'preact/hooks';
|
||||
|
||||
Reference in New Issue
Block a user