-
-
Notifications
You must be signed in to change notification settings - Fork 423
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: display warning banner when using the app with no account
- Loading branch information
Showing
26 changed files
with
697 additions
and
185 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
declare module '*.svg' { | ||
export default function SvgComponent(props: React.SVGProps<SVGSVGElement>): JSX.Element; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import { WebApplication } from '@/ui_models/application'; | ||
import { toDirective, useAutorunValue } from './utils'; | ||
import Close from '../../icons/ic_close.svg'; | ||
import { AppState } from '@/ui_models/app_state'; | ||
|
||
function NoAccountWarning({ | ||
application, | ||
appState, | ||
}: { | ||
application: WebApplication; | ||
appState: AppState; | ||
}) { | ||
const canShow = useAutorunValue(() => appState.noAccountWarning.show); | ||
if (!canShow || application.hasAccount()) { | ||
return null; | ||
} | ||
return ( | ||
<div className="mt-5 p-5 rounded-md shadow-sm grid grid-template-cols-1fr"> | ||
<h1 className="sk-h3 m-0 font-semibold">Data not backed up</h1> | ||
<p className="m-0 mt-1 col-start-1 col-end-3"> | ||
Sign in or register to back up your notes | ||
</p> | ||
<button | ||
className="sn-btn mt-3 col-start-1 col-end-3 justify-self-start" | ||
onClick={(event) => { | ||
event.stopPropagation(); | ||
appState.accountMenu.setShow(true); | ||
}} | ||
> | ||
Open Account menu | ||
</button> | ||
<button | ||
onClick={() => { | ||
appState.noAccountWarning.hide(); | ||
}} | ||
title="Ignore" | ||
label="Ignore" | ||
className="border-0 p-0 bg-transparent cursor-pointer rounded-md col-start-2 row-start-1" | ||
> | ||
<Close className="fill-neutral hover:fill-info" /> | ||
</button> | ||
</div> | ||
); | ||
} | ||
|
||
export const NoAccountWarningDirective = toDirective(NoAccountWarning); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import { WebApplication } from '@/ui_models/application'; | ||
import { AppState } from '@/ui_models/app_state'; | ||
import { autorun, IAutorunOptions, IReactionPublic } from 'mobx'; | ||
import { FunctionComponent, h, render } from 'preact'; | ||
import { useEffect } from 'preact/hooks'; | ||
import { useState } from 'react'; | ||
|
||
export function useAutorunValue<T>(query: () => T): T { | ||
const [value, setValue] = useState(query); | ||
useAutorun(() => { | ||
setValue(query()); | ||
}); | ||
return value; | ||
} | ||
|
||
export function useAutorun( | ||
view: (r: IReactionPublic) => unknown, | ||
opts?: IAutorunOptions | ||
): void { | ||
useEffect(() => autorun(view, opts), [view, opts]); | ||
} | ||
|
||
export function toDirective( | ||
component: FunctionComponent<{ | ||
application: WebApplication; | ||
appState: AppState; | ||
}> | ||
) { | ||
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types | ||
return function () { | ||
return { | ||
controller: [ | ||
'$element', | ||
'$scope', | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
($element: JQLite, $scope: any) => { | ||
return { | ||
$onChanges() { | ||
render( | ||
h(component, { | ||
application: $scope.application, | ||
appState: $scope.appState, | ||
}), | ||
$element[0] | ||
); | ||
}, | ||
}; | ||
}, | ||
], | ||
scope: { | ||
application: '=', | ||
appState: '=', | ||
}, | ||
}; | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.