Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add quick settings menu with theme switcher and other changes #673

Merged
merged 34 commits into from
Oct 19, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
e79848f
feat: Animate account menu on correctly on toggle
amanharwara Oct 10, 2021
a0672d1
feat: Add quick settings menu with theme switcher
amanharwara Oct 10, 2021
d14e306
feat: Add styles to quick setting menu
amanharwara Oct 10, 2021
da87e9d
feat: Remove theme shortcuts from footer
amanharwara Oct 10, 2021
d9c87a3
refactor: Use action for changing values
amanharwara Oct 10, 2021
cfb33ea
refactor: Use action for changing value
amanharwara Oct 10, 2021
8a649c8
fix: Fix actions
amanharwara Oct 10, 2021
47badcf
fix: Color and spacing
amanharwara Oct 10, 2021
43e0d4c
feat: Remove "Recently used themes"
amanharwara Oct 10, 2021
154ad77
Update app/assets/javascripts/ui_models/app_state/quick_settings_stat…
amanharwara Oct 11, 2021
853c3a1
feat: Add keyboard navigation to theme switcher
amanharwara Oct 11, 2021
a462f99
feat: Add menu border
amanharwara Oct 11, 2021
148791a
feat: Use radio button design
amanharwara Oct 11, 2021
8d97f5b
Merge branch 'develop' into feat/theme-switcher
amanharwara Oct 11, 2021
bf19220
fix: Fix classnames
amanharwara Oct 12, 2021
4dc29a3
feat: Add & use info-backdrop for button focus bg
amanharwara Oct 12, 2021
fb85844
feat: Use info-backdrop color for quick settings menu items
amanharwara Oct 12, 2021
3e66533
feat: Add arrow key navigation for quick settings menu
amanharwara Oct 12, 2021
55e3497
refactor: Remove unnecessary conditional
amanharwara Oct 12, 2021
0834dc1
feat: Focus "Account Settings" button when account menu is opened
amanharwara Oct 12, 2021
93a8953
feat: Add arrow key navigation to account menu
amanharwara Oct 12, 2021
35d35ac
Merge branch 'develop' into feat/theme-switcher
amanharwara Oct 13, 2021
5478535
Merge branch 'develop' into feat/theme-switcher
amanharwara Oct 13, 2021
2a96e24
Update app/assets/javascripts/ui_models/app_state/quick_settings_stat…
amanharwara Oct 13, 2021
e93bcb1
Update app/assets/javascripts/components/QuickSettingsMenu.tsx
amanharwara Oct 13, 2021
0c6b3fc
refactor: Use ref on Default theme btn to focus it
amanharwara Oct 13, 2021
cccc83f
Merge branch 'feat/theme-switcher' of github.com:amanharwara/web into…
amanharwara Oct 13, 2021
abb2358
Merge branch 'develop' into feat/theme-switcher
amanharwara Oct 13, 2021
62ae7f7
Merge branch 'develop' into feat/theme-switcher
amanharwara Oct 14, 2021
0d1e289
feat: Focus preferences button by default in quick settings
amanharwara Oct 14, 2021
5219013
feat: Use array of refs for focusing buttons
amanharwara Oct 14, 2021
221e1be
Merge branch 'develop' into feat/theme-switcher
amanharwara Oct 14, 2021
2491fd1
Merge branch 'develop' into feat/theme-switcher
amanharwara Oct 17, 2021
ba36b34
Merge branch 'develop' into feat/theme-switcher
amanharwara Oct 18, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/assets/icons/ic-themes.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions app/assets/javascripts/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ import { IconDirective } from './components/Icon';
import { NoteTagsContainerDirective } from './components/NoteTagsContainer';
import { PreferencesDirective } from './preferences';
import { AppVersion, IsWebPlatform } from '@/version';
import { QuickSettingsMenuDirective } from './components/QuickSettingsMenu';

function reloadHiddenFirefoxTab(): boolean {
/**
Expand Down Expand Up @@ -154,6 +155,7 @@ const startApplication: StartApplication = async function startApplication(
.directive('syncResolutionMenu', () => new SyncResolutionMenu())
.directive('sessionsModal', SessionsModalDirective)
.directive('accountMenu', AccountMenuDirective)
.directive('quickSettingsMenu', QuickSettingsMenuDirective)
.directive('noAccountWarning', NoAccountWarningDirective)
.directive('protectedNotePanel', NoProtectionsdNoteWarningDirective)
.directive('searchOptions', SearchOptionsDirective)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export const AdvancedOptions: FunctionComponent<Props> = observer(
return (
<>
<button
className="sn-dropdown-item font-bold"
className="sn-dropdown-item focus:bg-info-backdrop focus:shadow-none font-bold"
onClick={toggleShowAdvanced}
>
<div className="flex items-center">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { WebApplication } from '@/ui_models/application';
import { AppState } from '@/ui_models/app_state';
import { observer } from 'mobx-react-lite';
import { FunctionComponent } from 'preact';
import { StateUpdater, useRef, useState } from 'preact/hooks';
import { StateUpdater, useEffect, useRef, useState } from 'preact/hooks';
import { AccountMenuPane } from '.';
import { Button } from '../Button';
import { Checkbox } from '../Checkbox';
Expand Down Expand Up @@ -31,6 +31,10 @@ export const ConfirmPassword: FunctionComponent<Props> = observer(

const passwordInputRef = useRef<HTMLInputElement>();

useEffect(() => {
passwordInputRef?.current?.focus();
}, []);

const handlePasswordChange = (e: Event) => {
if (e.target instanceof HTMLInputElement) {
setConfirmPassword(e.target.value);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@ 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 { useEffect, useRef, useState } from 'preact/hooks';
import { AccountMenuPane } from '.';
import { FunctionComponent } from 'preact';
import { JSXInternal } from 'preact/src/jsx';
import { AppVersion } from '@/version';

type Props = {
Expand All @@ -25,6 +26,9 @@ export const GeneralAccountMenu: FunctionComponent<Props> = observer(
const [lastSyncDate, setLastSyncDate] = useState(
formatLastSyncDate(application.getLastSyncDate() as Date)
);
const [currentFocusedIndex, setCurrentFocusedIndex] = useState(0);

const buttonRefs = useRef<(HTMLButtonElement | null)[]>([]);

const doSynchronization = async () => {
setIsSyncingInProgress(true);
Expand Down Expand Up @@ -53,9 +57,49 @@ export const GeneralAccountMenu: FunctionComponent<Props> = observer(

const user = application.getUser();

const accountMenuRef = useRef<HTMLDivElement>();

const handleKeyDown: JSXInternal.KeyboardEventHandler<HTMLDivElement> = (
event
) => {
switch (event.key) {
case 'ArrowDown':
setCurrentFocusedIndex((index) => {
console.log(index, buttonRefs.current.length);
if (index + 1 < buttonRefs.current.length) {
return index + 1;
} else {
return 0;
}
});
break;
case 'ArrowUp':
setCurrentFocusedIndex((index) => {
if (index - 1 > -1) {
return index - 1;
} else {
return buttonRefs.current.length - 1;
}
});
break;
}
};

useEffect(() => {
if (buttonRefs.current[currentFocusedIndex]) {
buttonRefs.current[currentFocusedIndex]?.focus();
}
}, [currentFocusedIndex]);

const pushRefToArray = (ref: HTMLButtonElement | null) => {
if (ref && !buttonRefs.current.includes(ref)) {
buttonRefs.current.push(ref);
}
};

return (
<>
<div className="flex items-center justify-between px-3 mt-1 mb-2">
<div ref={accountMenuRef} onKeyDown={handleKeyDown}>
<div className="flex items-center justify-between px-3 mt-1 mb-3">
<div className="sn-account-menu-headline">Account</div>
<div className="flex cursor-pointer" onClick={closeMenu}>
<Icon type="close" className="color-grey-1" />
Expand Down Expand Up @@ -105,7 +149,8 @@ export const GeneralAccountMenu: FunctionComponent<Props> = observer(
<div className="h-1px my-2 bg-border"></div>
{user ? (
<button
className="sn-dropdown-item"
className="sn-dropdown-item focus:bg-info-backdrop focus:shadow-none"
ref={pushRefToArray}
onClick={() => {
appState.accountMenu.closeAccountMenu();
appState.preferences.setCurrentPane('account');
Expand All @@ -118,7 +163,8 @@ export const GeneralAccountMenu: FunctionComponent<Props> = observer(
) : (
<>
<button
className="sn-dropdown-item"
className="sn-dropdown-item focus:bg-info-backdrop focus:shadow-none"
ref={pushRefToArray}
onClick={() => {
setMenuPane(AccountMenuPane.Register);
}}
Expand All @@ -127,7 +173,8 @@ export const GeneralAccountMenu: FunctionComponent<Props> = observer(
Create free account
</button>
<button
className="sn-dropdown-item"
className="sn-dropdown-item focus:bg-info-backdrop focus:shadow-none"
ref={pushRefToArray}
onClick={() => {
setMenuPane(AccountMenuPane.SignIn);
}}
Expand All @@ -138,7 +185,8 @@ export const GeneralAccountMenu: FunctionComponent<Props> = observer(
</>
)}
<button
className="sn-dropdown-item justify-between"
className="sn-dropdown-item focus:bg-info-backdrop focus:shadow-none"
ref={pushRefToArray}
onClick={() => {
appState.accountMenu.closeAccountMenu();
appState.preferences.setCurrentPane('help-feedback');
Expand All @@ -155,7 +203,8 @@ export const GeneralAccountMenu: FunctionComponent<Props> = observer(
<>
<div className="h-1px my-2 bg-border"></div>
<button
className="sn-dropdown-item"
className="sn-dropdown-item focus:bg-info-backdrop focus:shadow-none"
ref={pushRefToArray}
onClick={() => {
appState.accountMenu.setSigningOut(true);
}}
Expand All @@ -165,7 +214,7 @@ export const GeneralAccountMenu: FunctionComponent<Props> = observer(
</button>
</>
) : null}
</>
</div>
);
}
);
20 changes: 19 additions & 1 deletion app/assets/javascripts/components/AccountMenu/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { SignInPane } from './SignIn';
import { CreateAccount } from './CreateAccount';
import { ConfirmSignoutContainer } from '../ConfirmSignoutModal';
import { ConfirmPassword } from './ConfirmPassword';
import { JSXInternal } from 'preact/src/jsx';

export enum AccountMenuPane {
GeneralMenu,
Expand Down Expand Up @@ -87,14 +88,31 @@ const AccountMenu: FunctionComponent<Props> = observer(
closeAccountMenu,
} = appState.accountMenu;

const handleKeyDown: JSXInternal.KeyboardEventHandler<HTMLDivElement> = (
event
) => {
switch (event.key) {
case 'Escape':
if (currentPane === AccountMenuPane.GeneralMenu) {
closeAccountMenu();
} else if (currentPane === AccountMenuPane.ConfirmPassword) {
setCurrentPane(AccountMenuPane.Register);
} else {
setCurrentPane(AccountMenuPane.GeneralMenu);
}
break;
}
};

return (
<div className="sn-component">
<div
className={`sn-account-menu sn-dropdown ${
className={`sn-menu-border sn-account-menu sn-dropdown ${
shouldAnimateCloseMenu
? 'slide-up-animation'
: 'sn-dropdown--animated'
} min-w-80 max-h-120 max-w-xs flex flex-col py-2 overflow-y-auto absolute`}
onKeyDown={handleKeyDown}
>
<MenuPaneSelector
appState={appState}
Expand Down
Loading