refactor: reviewer's comment
- use Preact's `FunctionalComponent` instead of React's `FC` to keep the app more lightweight - remove `@node_modules/` from imports
This commit is contained in:
@@ -5,14 +5,14 @@ import {
|
|||||||
STRING_GENERATING_REGISTER_KEYS,
|
STRING_GENERATING_REGISTER_KEYS,
|
||||||
STRING_NON_MATCHING_PASSWORDS
|
STRING_NON_MATCHING_PASSWORDS
|
||||||
} from '@/strings';
|
} from '@/strings';
|
||||||
import { JSXInternal } from '@node_modules/preact/src/jsx';
|
import { JSXInternal } from 'preact/src/jsx';
|
||||||
import TargetedEvent = JSXInternal.TargetedEvent;
|
import TargetedEvent = JSXInternal.TargetedEvent;
|
||||||
import TargetedKeyboardEvent = JSXInternal.TargetedKeyboardEvent;
|
import TargetedKeyboardEvent = JSXInternal.TargetedKeyboardEvent;
|
||||||
import { WebApplication } from '@/ui_models/application';
|
import { WebApplication } from '@/ui_models/application';
|
||||||
import { StateUpdater, useEffect, useRef, useState } from 'preact/hooks';
|
import { StateUpdater, useEffect, useRef, useState } from 'preact/hooks';
|
||||||
import TargetedMouseEvent = JSXInternal.TargetedMouseEvent;
|
import TargetedMouseEvent = JSXInternal.TargetedMouseEvent;
|
||||||
import { User } from '@node_modules/@standardnotes/snjs/dist/@types/services/api/responses';
|
import { FunctionalComponent } from 'preact';
|
||||||
import { FC } from 'react';
|
import { User } from '@standardnotes/snjs/dist/@types/services/api/responses';
|
||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
application: WebApplication;
|
application: WebApplication;
|
||||||
@@ -27,18 +27,18 @@ type Props = {
|
|||||||
user: User | undefined;
|
user: User | undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
const Authentication: FC<Props> = ({
|
const Authentication: FunctionalComponent<Props> = ({
|
||||||
application,
|
application,
|
||||||
server,
|
server,
|
||||||
setServer,
|
setServer,
|
||||||
closeAccountMenu,
|
closeAccountMenu,
|
||||||
notesAndTagsCount,
|
notesAndTagsCount,
|
||||||
showLogin,
|
showLogin,
|
||||||
setShowLogin,
|
setShowLogin,
|
||||||
showRegister,
|
showRegister,
|
||||||
setShowRegister,
|
setShowRegister,
|
||||||
user
|
user
|
||||||
}: Props) => {
|
}: Props) => {
|
||||||
|
|
||||||
const [showAdvanced, setShowAdvanced] = useState(false);
|
const [showAdvanced, setShowAdvanced] = useState(false);
|
||||||
const [isAuthenticating, setIsAuthenticating] = useState(false);
|
const [isAuthenticating, setIsAuthenticating] = useState(false);
|
||||||
@@ -69,7 +69,6 @@ const Authentication: FC<Props> = ({
|
|||||||
|
|
||||||
const handleHostInputChange = (event: TargetedEvent<HTMLInputElement>) => {
|
const handleHostInputChange = (event: TargetedEvent<HTMLInputElement>) => {
|
||||||
const { value } = event.target as HTMLInputElement;
|
const { value } = event.target as HTMLInputElement;
|
||||||
// setUrl(value);
|
|
||||||
setServer(value);
|
setServer(value);
|
||||||
application.setHost(value);
|
application.setHost(value);
|
||||||
};
|
};
|
||||||
@@ -243,42 +242,48 @@ const Authentication: FC<Props> = ({
|
|||||||
</div>
|
</div>
|
||||||
<form className="sk-panel-form" onSubmit={handleAuthFormSubmit} noValidate>
|
<form className="sk-panel-form" onSubmit={handleAuthFormSubmit} noValidate>
|
||||||
<div className="sk-panel-section">
|
<div className="sk-panel-section">
|
||||||
<input className="sk-input contrast"
|
<input
|
||||||
name="email"
|
className="sk-input contrast"
|
||||||
type="email"
|
name="email"
|
||||||
value={email}
|
type="email"
|
||||||
onChange={handleEmailChange}
|
value={email}
|
||||||
placeholder="Email"
|
onChange={handleEmailChange}
|
||||||
required
|
placeholder="Email"
|
||||||
spellcheck={false}
|
required
|
||||||
ref={emailInputRef}
|
spellcheck={false}
|
||||||
|
ref={emailInputRef}
|
||||||
/>
|
/>
|
||||||
<input className="sk-input contrast"
|
<input
|
||||||
name="password"
|
className="sk-input contrast"
|
||||||
type="password"
|
name="password"
|
||||||
value={password}
|
type="password"
|
||||||
onChange={handlePasswordChange}
|
value={password}
|
||||||
placeholder="Password"
|
onChange={handlePasswordChange}
|
||||||
required
|
placeholder="Password"
|
||||||
onKeyPress={handleKeyPressKeyDown}
|
required
|
||||||
onKeyDown={handleKeyPressKeyDown}
|
onKeyPress={handleKeyPressKeyDown}
|
||||||
ref={passwordInputRef}
|
onKeyDown={handleKeyPressKeyDown}
|
||||||
|
ref={passwordInputRef}
|
||||||
/>
|
/>
|
||||||
{showRegister &&
|
{showRegister &&
|
||||||
<input className="sk-input contrast"
|
<input
|
||||||
name="password_conf"
|
className="sk-input contrast"
|
||||||
type="password"
|
name="password_conf"
|
||||||
placeholder="Confirm Password" required
|
type="password"
|
||||||
onKeyPress={handleKeyPressKeyDown}
|
placeholder="Confirm Password"
|
||||||
onKeyDown={handleKeyPressKeyDown}
|
required
|
||||||
value={passwordConfirmation}
|
onKeyPress={handleKeyPressKeyDown}
|
||||||
onChange={handlePasswordConfirmationChange}
|
onKeyDown={handleKeyPressKeyDown}
|
||||||
ref={passwordConfirmationInputRef}
|
value={passwordConfirmation}
|
||||||
|
onChange={handlePasswordConfirmationChange}
|
||||||
|
ref={passwordConfirmationInputRef}
|
||||||
/>}
|
/>}
|
||||||
<div className="sk-panel-row" />
|
<div className="sk-panel-row" />
|
||||||
<button className="sn-button small info" onClick={() => {
|
<button
|
||||||
setShowAdvanced(!showAdvanced);
|
className="sn-button small info"
|
||||||
}}>
|
onClick={() => {
|
||||||
|
setShowAdvanced(!showAdvanced);
|
||||||
|
}}>
|
||||||
Advanced Options
|
Advanced Options
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
@@ -290,12 +295,13 @@ const Authentication: FC<Props> = ({
|
|||||||
</div>
|
</div>
|
||||||
<div className="bordered-row padded-row">
|
<div className="bordered-row padded-row">
|
||||||
<label className="sk-label">Sync Server Domain</label>
|
<label className="sk-label">Sync Server Domain</label>
|
||||||
<input className="sk-input sk-base"
|
<input
|
||||||
name="server"
|
className="sk-input sk-base"
|
||||||
placeholder="Server URL"
|
name="server"
|
||||||
onChange={handleHostInputChange}
|
placeholder="Server URL"
|
||||||
value={server}
|
onChange={handleHostInputChange}
|
||||||
required
|
value={server}
|
||||||
|
required
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
{showLogin && (
|
{showLogin && (
|
||||||
|
|||||||
@@ -6,13 +6,13 @@ import {
|
|||||||
STRING_UNSUPPORTED_BACKUP_FILE_VERSION,
|
STRING_UNSUPPORTED_BACKUP_FILE_VERSION,
|
||||||
StringImportError
|
StringImportError
|
||||||
} from '@/strings';
|
} from '@/strings';
|
||||||
import { BackupFile } from '@node_modules/@standardnotes/snjs';
|
import { BackupFile } from '@standardnotes/snjs';
|
||||||
import { useState } from '@node_modules/preact/hooks';
|
import { useState } from 'preact/hooks';
|
||||||
import { WebApplication } from '@/ui_models/application';
|
import { WebApplication } from '@/ui_models/application';
|
||||||
import { JSXInternal } from '@node_modules/preact/src/jsx';
|
import { JSXInternal } from 'preact/src/jsx';
|
||||||
import TargetedEvent = JSXInternal.TargetedEvent;
|
import TargetedEvent = JSXInternal.TargetedEvent;
|
||||||
import { StateUpdater } from 'preact/hooks';
|
import { StateUpdater } from 'preact/hooks';
|
||||||
import { FC } from 'react';
|
import { FunctionalComponent } from 'preact';
|
||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
application: WebApplication;
|
application: WebApplication;
|
||||||
@@ -21,12 +21,12 @@ type Props = {
|
|||||||
setIsBackupEncrypted: StateUpdater<boolean>;
|
setIsBackupEncrypted: StateUpdater<boolean>;
|
||||||
}
|
}
|
||||||
|
|
||||||
const DataBackup: FC<Props> = ({
|
const DataBackup: FunctionalComponent<Props> = ({
|
||||||
application,
|
application,
|
||||||
isBackupEncrypted,
|
isBackupEncrypted,
|
||||||
isEncryptionEnabled,
|
isEncryptionEnabled,
|
||||||
setIsBackupEncrypted
|
setIsBackupEncrypted
|
||||||
}) => {
|
}) => {
|
||||||
|
|
||||||
const [isImportDataLoading, setIsImportDataLoading] = useState(false);
|
const [isImportDataLoading, setIsImportDataLoading] = useState(false);
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { FC } from 'react';
|
import { FunctionalComponent } from 'preact';
|
||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
isEncryptionEnabled: boolean;
|
isEncryptionEnabled: boolean;
|
||||||
@@ -6,11 +6,11 @@ type Props = {
|
|||||||
encryptionStatusString: string | undefined;
|
encryptionStatusString: string | undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
const Encryption: FC<Props> = ({
|
const Encryption: FunctionalComponent<Props> = ({
|
||||||
isEncryptionEnabled,
|
isEncryptionEnabled,
|
||||||
notesAndTagsCount,
|
notesAndTagsCount,
|
||||||
encryptionStatusString,
|
encryptionStatusString
|
||||||
}) => {
|
}) => {
|
||||||
const getEncryptionStatusForNotes = () => {
|
const getEncryptionStatusForNotes = () => {
|
||||||
const length = notesAndTagsCount;
|
const length = notesAndTagsCount;
|
||||||
return `${length}/${length} notes and tags encrypted`;
|
return `${length}/${length} notes and tags encrypted`;
|
||||||
@@ -31,6 +31,6 @@ const Encryption: FC<Props> = ({
|
|||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
};
|
||||||
|
|
||||||
export default Encryption;
|
export default Encryption;
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { useState } from '@node_modules/preact/hooks';
|
import { useState } from 'preact/hooks';
|
||||||
import { storage, StorageKey } from '@Services/localStorage';
|
import { storage, StorageKey } from '@Services/localStorage';
|
||||||
import { disableErrorReporting, enableErrorReporting, errorReportingId } from '@Services/errorReporting';
|
import { disableErrorReporting, enableErrorReporting, errorReportingId } from '@Services/errorReporting';
|
||||||
import { alertDialog } from '@Services/alertService';
|
import { alertDialog } from '@Services/alertService';
|
||||||
|
|||||||
@@ -1,9 +1,8 @@
|
|||||||
import { FunctionalComponent } from 'preact';
|
|
||||||
import { AppState } from '@/ui_models/app_state';
|
import { AppState } from '@/ui_models/app_state';
|
||||||
import { StateUpdater, useState } from '@node_modules/preact/hooks';
|
import { StateUpdater, useState } from 'preact/hooks';
|
||||||
import { WebApplication } from '@/ui_models/application';
|
import { WebApplication } from '@/ui_models/application';
|
||||||
import { User } from '@node_modules/@standardnotes/snjs/dist/@types/services/api/responses';
|
import { User } from '@standardnotes/snjs/dist/@types/services/api/responses';
|
||||||
import { observer } from '@node_modules/mobx-react-lite';
|
import { observer } from 'mobx-react-lite';
|
||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
appState: AppState;
|
appState: AppState;
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
import { FC } from 'react';
|
|
||||||
import {
|
import {
|
||||||
STRING_CONFIRM_APP_QUIT_DURING_PASSCODE_CHANGE,
|
STRING_CONFIRM_APP_QUIT_DURING_PASSCODE_CHANGE,
|
||||||
STRING_CONFIRM_APP_QUIT_DURING_PASSCODE_REMOVAL, STRING_E2E_ENABLED, STRING_ENC_NOT_ENABLED, STRING_LOCAL_ENC_ENABLED,
|
STRING_CONFIRM_APP_QUIT_DURING_PASSCODE_REMOVAL, STRING_E2E_ENABLED, STRING_ENC_NOT_ENABLED, STRING_LOCAL_ENC_ENABLED,
|
||||||
@@ -7,13 +6,14 @@ import {
|
|||||||
} from '@/strings';
|
} from '@/strings';
|
||||||
import { WebApplication } from '@/ui_models/application';
|
import { WebApplication } from '@/ui_models/application';
|
||||||
import { preventRefreshing } from '@/utils';
|
import { preventRefreshing } from '@/utils';
|
||||||
import { JSXInternal } from '@node_modules/preact/src/jsx';
|
import { JSXInternal } from 'preact/src/jsx';
|
||||||
import TargetedEvent = JSXInternal.TargetedEvent;
|
import TargetedEvent = JSXInternal.TargetedEvent;
|
||||||
import { alertDialog } from '@Services/alertService';
|
import { alertDialog } from '@Services/alertService';
|
||||||
import { useCallback, useEffect, useRef, useState } from '@node_modules/preact/hooks';
|
import { useCallback, useEffect, useRef, useState } from 'preact/hooks';
|
||||||
import { ApplicationEvent } from '@node_modules/@standardnotes/snjs';
|
import { ApplicationEvent } from '@standardnotes/snjs';
|
||||||
import TargetedMouseEvent = JSXInternal.TargetedMouseEvent;
|
import TargetedMouseEvent = JSXInternal.TargetedMouseEvent;
|
||||||
import { StateUpdater } from 'preact/hooks';
|
import { StateUpdater } from 'preact/hooks';
|
||||||
|
import { FunctionalComponent } from 'preact';
|
||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
application: WebApplication;
|
application: WebApplication;
|
||||||
@@ -22,7 +22,7 @@ type Props = {
|
|||||||
setIsBackupEncrypted: StateUpdater<boolean>;
|
setIsBackupEncrypted: StateUpdater<boolean>;
|
||||||
};
|
};
|
||||||
|
|
||||||
const PasscodeLock: FC<Props> = ({
|
const PasscodeLock: FunctionalComponent<Props> = ({
|
||||||
application,
|
application,
|
||||||
setEncryptionStatusString,
|
setEncryptionStatusString,
|
||||||
setIsEncryptionEnabled,
|
setIsEncryptionEnabled,
|
||||||
|
|||||||
@@ -1,15 +1,15 @@
|
|||||||
import { WebApplication } from '@/ui_models/application';
|
import { WebApplication } from '@/ui_models/application';
|
||||||
import { FC } from 'react';
|
import { FunctionalComponent } from 'preact';
|
||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
application: WebApplication;
|
application: WebApplication;
|
||||||
protectionsDisabledUntil: string | null;
|
protectionsDisabledUntil: string | null;
|
||||||
};
|
};
|
||||||
|
|
||||||
const Protections: FC<Props> = ({
|
const Protections: FunctionalComponent<Props> = ({
|
||||||
application,
|
application,
|
||||||
protectionsDisabledUntil
|
protectionsDisabledUntil
|
||||||
}) => {
|
}) => {
|
||||||
const enableProtections = () => {
|
const enableProtections = () => {
|
||||||
application.clearProtectionSession();
|
application.clearProtectionSession();
|
||||||
};
|
};
|
||||||
@@ -41,6 +41,6 @@ const Protections: FC<Props> = ({
|
|||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
};
|
||||||
|
|
||||||
export default Protections;
|
export default Protections;
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ import { AppState } from '@/ui_models/app_state';
|
|||||||
import { WebApplication } from '@/ui_models/application';
|
import { WebApplication } from '@/ui_models/application';
|
||||||
import { useEffect, useState } from 'preact/hooks';
|
import { useEffect, useState } from 'preact/hooks';
|
||||||
import { isSameDay } from '@/utils';
|
import { isSameDay } from '@/utils';
|
||||||
import { ApplicationEvent } from '@node_modules/@standardnotes/snjs';
|
import { ApplicationEvent } from '@standardnotes/snjs';
|
||||||
import { ConfirmSignoutContainer } from '@/components/ConfirmSignoutModal';
|
import { ConfirmSignoutContainer } from '@/components/ConfirmSignoutModal';
|
||||||
import Authentication from '@/components/AccountMenu/Authentication';
|
import Authentication from '@/components/AccountMenu/Authentication';
|
||||||
import Footer from '@/components/AccountMenu/Footer';
|
import Footer from '@/components/AccountMenu/Footer';
|
||||||
@@ -14,7 +14,7 @@ import Protections from '@/components/AccountMenu/Protections';
|
|||||||
import PasscodeLock from '@/components/AccountMenu/PasscodeLock';
|
import PasscodeLock from '@/components/AccountMenu/PasscodeLock';
|
||||||
import DataBackup from '@/components/AccountMenu/DataBackup';
|
import DataBackup from '@/components/AccountMenu/DataBackup';
|
||||||
import ErrorReporting from '@/components/AccountMenu/ErrorReporting';
|
import ErrorReporting from '@/components/AccountMenu/ErrorReporting';
|
||||||
import { useCallback } from '@node_modules/preact/hooks';
|
import { useCallback } from 'preact/hooks';
|
||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
appState: AppState;
|
appState: AppState;
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ import TrashSweepIcon from '../../icons/ic-trash-sweep.svg';
|
|||||||
import MoreIcon from '../../icons/ic-more.svg';
|
import MoreIcon from '../../icons/ic-more.svg';
|
||||||
import TuneIcon from '../../icons/ic-tune.svg';
|
import TuneIcon from '../../icons/ic-tune.svg';
|
||||||
import { toDirective } from './utils';
|
import { toDirective } from './utils';
|
||||||
|
import { FunctionalComponent } from 'preact';
|
||||||
|
|
||||||
const ICONS = {
|
const ICONS = {
|
||||||
'pencil-off': PencilOffIcon,
|
'pencil-off': PencilOffIcon,
|
||||||
@@ -38,7 +39,7 @@ type Props = {
|
|||||||
className: string;
|
className: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export const Icon: React.FC<Props> = ({ type, className }) => {
|
export const Icon: FunctionalComponent<Props> = ({ type, className }) => {
|
||||||
const IconComponent = ICONS[type];
|
const IconComponent = ICONS[type];
|
||||||
return <IconComponent className={`sn-icon ${className}`} />;
|
return <IconComponent className={`sn-icon ${className}`} />;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import { action, computed, makeObservable, observable, runInAction } from 'mobx';
|
import { action, computed, makeObservable, observable, runInAction } from 'mobx';
|
||||||
import { ContentType } from '@node_modules/@standardnotes/snjs';
|
import { ContentType } from '@standardnotes/snjs';
|
||||||
import { WebApplication } from '@/ui_models/application';
|
import { WebApplication } from '@/ui_models/application';
|
||||||
import { SNItem } from '@node_modules/@standardnotes/snjs/dist/@types/models/core/item';
|
import { SNItem } from '@standardnotes/snjs/dist/@types/models/core/item';
|
||||||
|
|
||||||
export class AccountMenuState {
|
export class AccountMenuState {
|
||||||
show = false;
|
show = false;
|
||||||
|
|||||||
Reference in New Issue
Block a user