Skip to content

Commit

Permalink
feat: get editor icons and their colors from snjs (#828)
Browse files Browse the repository at this point in the history
* feat: get editor icons and their colors from snjs

* feat: get icons and their tints from snjs

* fix: use IconType from snjs
  • Loading branch information
vardan-arm authored Jan 31, 2022
1 parent e890e22 commit bf382ce
Show file tree
Hide file tree
Showing 21 changed files with 126 additions and 104 deletions.
3 changes: 2 additions & 1 deletion app/assets/javascripts/components/Dropdown.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ import {
} from '@reach/listbox';
import VisuallyHidden from '@reach/visually-hidden';
import { FunctionComponent } from 'preact';
import { IconType, Icon } from './Icon';
import { Icon } from './Icon';
import { IconType } from '@standardnotes/snjs';

export type DropdownItem = {
icon?: IconType;
Expand Down
3 changes: 1 addition & 2 deletions app/assets/javascripts/components/Icon.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ import MenuArrowDownAlt from '../../icons/ic-menu-arrow-down-alt.svg';
import MenuArrowRight from '../../icons/ic-menu-arrow-right.svg';

import { FunctionalComponent } from 'preact';
import { IconType } from '@standardnotes/snjs';

const ICONS = {
editor: EditorIcon,
Expand Down Expand Up @@ -137,8 +138,6 @@ const ICONS = {
'premium-feature': PremiumFeatureIcon,
};

export type IconType = keyof typeof ICONS;

type Props = {
type: IconType;
className?: string;
Expand Down
3 changes: 2 additions & 1 deletion app/assets/javascripts/components/IconButton.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { FunctionComponent } from 'preact';
import { Icon, IconType } from './Icon';
import { Icon } from './Icon';
import { IconType } from '@standardnotes/snjs';

interface Props {
/**
Expand Down
3 changes: 2 additions & 1 deletion app/assets/javascripts/components/InputWithIcon.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { FunctionComponent, Ref } from 'preact';
import { JSXInternal } from 'preact/src/jsx';
import { forwardRef } from 'preact/compat';
import { Icon, IconType } from './Icon';
import { Icon } from './Icon';
import { IconButton } from './IconButton';
import { IconType } from '@standardnotes/snjs';

type ToggleProps = {
toggleOnIcon: IconType;
Expand Down
5 changes: 3 additions & 2 deletions app/assets/javascripts/components/NotesListItem.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { getIconAndTintForEditor } from '@/preferences/panes/general-segments';
import { WebApplication } from '@/ui_models/application';
import {
CollectionSort,
Expand Down Expand Up @@ -74,7 +73,9 @@ export const NotesListItem: FunctionComponent<Props> = ({
const showModifiedDate = sortedBy === CollectionSort.UpdatedAt;
const editorForNote = application.componentManager.editorForNote(note);
const editorName = editorForNote?.name ?? 'Plain editor';
const [icon, tint] = getIconAndTintForEditor(editorForNote?.identifier);
const [icon, tint] = application.iconsController.getIconAndTintForEditor(
editorForNote?.identifier
);

return (
<div
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import {
} from '@reach/disclosure';
import {
ComponentArea,
IconType,
ItemMutator,
NoteMutator,
PrefKey,
Expand All @@ -27,7 +28,7 @@ import {
} from '@standardnotes/snjs';
import { FunctionComponent } from 'preact';
import { useEffect, useRef, useState } from 'preact/hooks';
import { Icon, IconType } from '../Icon';
import { Icon } from '../Icon';
import { PremiumModalProvider } from '../Premium';
import { createEditorMenuGroups } from './changeEditor/createEditorMenuGroups';
import { EditorAccordionMenu } from './changeEditor/EditorAccordionMenu';
Expand Down
3 changes: 2 additions & 1 deletion app/assets/javascripts/components/RoundIconButton.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { FunctionComponent } from 'preact';
import { Icon, IconType } from './Icon';
import { Icon } from './Icon';
import { IconType } from '@standardnotes/snjs';

type ButtonType = 'normal' | 'primary';

Expand Down
9 changes: 6 additions & 3 deletions app/assets/javascripts/components/Switch.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ export const Switch: FunctionalComponent<SwitchProps> = (

return (
<label
className={`sn-component flex justify-between items-center cursor-pointer px-3 ${className} ${isDisabled ? 'faded' : ''}`}
className={`sn-component flex justify-between items-center cursor-pointer px-3 ${className} ${
isDisabled ? 'faded' : ''
}`}
{...(props.role ? { role: props.role } : {})}
>
{props.children}
Expand All @@ -51,8 +53,9 @@ export const Switch: FunctionalComponent<SwitchProps> = (
/>
<span
aria-hidden
className={`sn-switch-handle ${checked ? 'sn-switch-handle--right' : ''
}`}
className={`sn-switch-handle ${
checked ? 'sn-switch-handle--right' : ''
}`}
/>
</CustomCheckboxContainer>
</label>
Expand Down
4 changes: 2 additions & 2 deletions app/assets/javascripts/components/Tags/SmartTagsListItem.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { Icon, IconType } from '@/components/Icon';
import { Icon } from '@/components/Icon';
import { FeaturesState } from '@/ui_models/app_state/features_state';
import { TagsState } from '@/ui_models/app_state/tags_state';
import '@reach/tooltip/styles.css';
import { SNSmartTag } from '@standardnotes/snjs';
import { SNSmartTag, IconType } from '@standardnotes/snjs';
import { observer } from 'mobx-react-lite';
import { FunctionComponent } from 'preact';
import { useCallback, useEffect, useRef, useState } from 'preact/hooks';
Expand Down
3 changes: 2 additions & 1 deletion app/assets/javascripts/components/menu/MenuItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@ import {
} from 'preact';
import { forwardRef, Ref } from 'preact/compat';
import { JSXInternal } from 'preact/src/jsx';
import { Icon, IconType } from '../Icon';
import { Icon } from '../Icon';
import { Switch, SwitchProps } from '../Switch';
import { IconType } from '@standardnotes/snjs';

export enum MenuItemType {
IconButton,
Expand Down
2 changes: 1 addition & 1 deletion app/assets/javascripts/preferences/PreferencesMenu.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { IconType } from '@/components/Icon';
import { action, makeAutoObservable, observable } from 'mobx';
import { ExtensionsLatestVersions } from '@/preferences/panes/extensions-segments';
import {
ComponentArea,
ContentType,
FeatureIdentifier,
SNComponent,
IconType,
} from '@standardnotes/snjs';
import { WebApplication } from '@/ui_models/application';

Expand Down
3 changes: 2 additions & 1 deletion app/assets/javascripts/preferences/components/MenuItem.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Icon, IconType } from '@/components/Icon';
import { Icon } from '@/components/Icon';
import { FunctionComponent } from 'preact';
import { IconType } from '@standardnotes/snjs';

interface Props {
iconType: IconType;
Expand Down
3 changes: 2 additions & 1 deletion app/assets/javascripts/preferences/panes/Appearance.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,8 @@ const AppearancePane: FunctionComponent<Props> = observer(({ application }) => {
<div className="flex flex-col">
<Subtitle>Use system color scheme</Subtitle>
<Text>
Automatically change active theme based on your system settings.
Automatically change active theme based on your system
settings.
</Text>
</div>
<Switch
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import { convertStringifiedBooleanToBoolean, isDesktopApplication } from '@/utils';
import {
convertStringifiedBooleanToBoolean,
isDesktopApplication,
} from '@/utils';
import { STRING_FAILED_TO_UPDATE_USER_SETTING } from '@/strings';
import { useCallback, useEffect, useState } from 'preact/hooks';
import { WebApplication } from '@/ui_models/application';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
CloudProvider,
DropboxBackupFrequency,
GoogleDriveBackupFrequency,
OneDriveBackupFrequency
OneDriveBackupFrequency,
} from '@standardnotes/settings';
import { WebApplication } from '@/ui_models/application';
import { Button } from '@/components/Button';
Expand All @@ -20,9 +20,9 @@ type Props = {
};

export const CloudBackupProvider: FunctionComponent<Props> = ({
application,
providerName
}) => {
application,
providerName,
}) => {
const [authBegan, setAuthBegan] = useState(false);
const [successfullyInstalled, setSuccessfullyInstalled] = useState(false);
const [backupFrequency, setBackupFrequency] = useState<string | null>(null);
Expand All @@ -32,14 +32,13 @@ export const CloudBackupProvider: FunctionComponent<Props> = ({
event.stopPropagation();

try {
const shouldDisable = await application.alertService
.confirm(
'Are you sure you want to disable this integration?',
'Disable?',
'Disable',
ButtonType.Danger,
'Cancel'
);
const shouldDisable = await application.alertService.confirm(
'Are you sure you want to disable this integration?',
'Disable?',
'Disable',
ButtonType.Danger,
'Cancel'
);
if (shouldDisable) {
await application.deleteSetting(backupFrequencySettingName);
await application.deleteSetting(backupTokenSettingName);
Expand All @@ -54,15 +53,21 @@ export const CloudBackupProvider: FunctionComponent<Props> = ({
const installIntegration = (event: Event) => {
event.stopPropagation();

const authUrl = application.getCloudProviderIntegrationUrl(providerName, isDev);
const authUrl = application.getCloudProviderIntegrationUrl(
providerName,
isDev
);
openInNewTab(authUrl);
setAuthBegan(true);
};

const performBackupNow = async () => {
// A backup is performed anytime the setting is updated with the integration token, so just update it here
try {
await application.updateSetting(backupFrequencySettingName, backupFrequency as string);
await application.updateSetting(
backupFrequencySettingName,
backupFrequency as string
);
application.alertService.alert(
'A backup has been triggered for this provider. Please allow a couple minutes for your backup to be processed.'
);
Expand All @@ -77,20 +82,24 @@ export const CloudBackupProvider: FunctionComponent<Props> = ({
[CloudProvider.Dropbox]: {
backupTokenSettingName: SettingName.DropboxBackupToken,
backupFrequencySettingName: SettingName.DropboxBackupFrequency,
defaultBackupFrequency: DropboxBackupFrequency.Daily
defaultBackupFrequency: DropboxBackupFrequency.Daily,
},
[CloudProvider.Google]: {
backupTokenSettingName: SettingName.GoogleDriveBackupToken,
backupFrequencySettingName: SettingName.GoogleDriveBackupFrequency,
defaultBackupFrequency: GoogleDriveBackupFrequency.Daily
defaultBackupFrequency: GoogleDriveBackupFrequency.Daily,
},
[CloudProvider.OneDrive]: {
backupTokenSettingName: SettingName.OneDriveBackupToken,
backupFrequencySettingName: SettingName.OneDriveBackupFrequency,
defaultBackupFrequency: OneDriveBackupFrequency.Daily
}
defaultBackupFrequency: OneDriveBackupFrequency.Daily,
},
};
const { backupTokenSettingName, backupFrequencySettingName, defaultBackupFrequency } = backupSettingsData[providerName];
const {
backupTokenSettingName,
backupFrequencySettingName,
defaultBackupFrequency,
} = backupSettingsData[providerName];

const getCloudProviderIntegrationTokenFromUrl = (url: URL) => {
const urlSearchParams = new URLSearchParams(url.search);
Expand Down Expand Up @@ -123,8 +132,14 @@ export const CloudBackupProvider: FunctionComponent<Props> = ({
if (!cloudProviderToken) {
throw new Error();
}
await application.updateSetting(backupTokenSettingName, cloudProviderToken);
await application.updateSetting(backupFrequencySettingName, defaultBackupFrequency);
await application.updateSetting(
backupTokenSettingName,
cloudProviderToken
);
await application.updateSetting(
backupFrequencySettingName,
defaultBackupFrequency
);

setBackupFrequency(defaultBackupFrequency);

Expand Down Expand Up @@ -174,15 +189,15 @@ export const CloudBackupProvider: FunctionComponent<Props> = ({
</div>
{authBegan && (
<div>
<p className='sk-panel-row'>
<p className="sk-panel-row">
Complete authentication from the newly opened window. Upon
completion, a confirmation code will be displayed. Enter this code
below:
</p>
<div className={`mt-1`}>
<input
className='sk-input sk-base center-text'
placeholder='Enter confirmation code'
className="sk-input sk-base center-text"
placeholder="Enter confirmation code"
value={confirmation}
onKeyPress={handleKeyPress}
onChange={handleChange}
Expand All @@ -193,8 +208,8 @@ export const CloudBackupProvider: FunctionComponent<Props> = ({
{shouldShowEnableButton && (
<div>
<Button
type='normal'
label='Enable'
type="normal"
label="Enable"
className={'px-1 text-xs min-w-40'}
onClick={installIntegration}
/>
Expand All @@ -204,15 +219,15 @@ export const CloudBackupProvider: FunctionComponent<Props> = ({
{backupFrequency && (
<div className={'flex flex-col items-end'}>
<Button
className='min-w-40 mb-2'
type='normal'
label='Perform Backup'
className="min-w-40 mb-2"
type="normal"
label="Perform Backup"
onClick={performBackupNow}
/>
<Button
className='min-w-40'
type='normal'
label='Disable'
className="min-w-40"
type="normal"
label="Disable"
onClick={disable}
/>
</div>
Expand Down
Loading

0 comments on commit bf382ce

Please sign in to comment.