diff --git a/packages/web/src/javascripts/Components/NoteView/NoteStatusIndicator.tsx b/packages/web/src/javascripts/Components/NoteView/NoteStatusIndicator.tsx new file mode 100644 index 000000000..44cef026f --- /dev/null +++ b/packages/web/src/javascripts/Components/NoteView/NoteStatusIndicator.tsx @@ -0,0 +1,67 @@ +import { ElementIds } from '@/Constants/ElementIDs' +import { classNames } from '@/Utils/ConcatenateClassNames' +import { useState } from 'react' +import Icon from '../Icon/Icon' + +export type NoteStatus = { + type: 'saving' | 'saved' | 'error' + message: string + desc?: string +} + +type Props = { + status: NoteStatus | undefined + syncTakingTooLong: boolean +} + +const NoteStatusIndicator = ({ status, syncTakingTooLong }: Props) => { + const [shouldShowTooltip, setShouldShowTooltip] = useState(false) + + if (!status) { + return null + } + + return ( +
+ +
+
+ {status.message} +
+ {status.desc &&
{status.desc}
} +
+
+ ) +} + +export default NoteStatusIndicator diff --git a/packages/web/src/javascripts/Components/NoteView/NoteView.tsx b/packages/web/src/javascripts/Components/NoteView/NoteView.tsx index db82907a7..3b8104cba 100644 --- a/packages/web/src/javascripts/Components/NoteView/NoteView.tsx +++ b/packages/web/src/javascripts/Components/NoteView/NoteView.tsx @@ -41,6 +41,7 @@ import AutoresizingNoteViewTextarea from './AutoresizingTextarea' import MobileItemsListButton from '../NoteGroupView/MobileItemsListButton' import NoteTagsPanel from '../NoteTags/NoteTagsPanel' import NoteTagsContainer from '../NoteTags/NoteTagsContainer' +import NoteStatusIndicator, { NoteStatus } from './NoteStatusIndicator' import { PrefDefaults } from '@/Constants/PrefDefaults' const MinimumStatusDuration = 400 @@ -48,11 +49,6 @@ const TextareaDebounce = 100 const NoteEditingDisabledText = 'Note editing disabled.' const StickyHeaderScrollThresholdInPx = 20 -type NoteStatus = { - message?: string - desc?: string -} - function sortAlphabetically(array: SNComponent[]): SNComponent[] { return array.sort((a, b) => (a.name.toLowerCase() < b.name.toLowerCase() ? -1 : 1)) } @@ -346,6 +342,7 @@ class NoteView extends PureComponent { break case ApplicationEvent.LocalDatabaseWriteError: this.showErrorStatus({ + type: 'error', message: 'Offline Saving Issue', desc: 'Changes not saved', }) @@ -503,7 +500,7 @@ class NoteView extends PureComponent { } showSavingStatus() { - this.setStatus({ message: 'Saving…' }, false) + this.setStatus({ type: 'saving', message: 'Saving…' }, false) } showAllChangesSavedStatus() { @@ -512,6 +509,7 @@ class NoteView extends PureComponent { syncTakingTooLong: false, }) this.setStatus({ + type: 'saved', message: 'All changes saved' + (this.application.noAccount() ? ' offline' : ''), }) } @@ -519,6 +517,7 @@ class NoteView extends PureComponent { showErrorStatus(error?: NoteStatus) { if (!error) { error = { + type: 'error', message: 'Sync Unreachable', desc: 'Changes saved offline', } @@ -948,7 +947,7 @@ class NoteView extends PureComponent { : '', )} > -
+
@@ -966,60 +965,41 @@ class NoteView extends PureComponent { autoComplete="off" />
+
{!this.state.shouldStickyHeader && ( -
- {this.state.noteStatus?.message?.length && ( -
-
-
- {this.state.noteStatus?.message} -
- {this.state.noteStatus?.desc && ( -
{this.state.noteStatus.desc}
- )} -
-
- )} -
- - - - - -
+
+ + + + +
)}
diff --git a/packages/web/src/javascripts/Constants/ElementIDs.ts b/packages/web/src/javascripts/Constants/ElementIDs.ts index 98fbe1e85..1b169c290 100644 --- a/packages/web/src/javascripts/Constants/ElementIDs.ts +++ b/packages/web/src/javascripts/Constants/ElementIDs.ts @@ -9,4 +9,5 @@ export const ElementIds = { NoteTextEditor: 'note-text-editor', NoteTitleEditor: 'note-title-editor', RootId: 'app-group-root', + NoteStatusTooltip: 'note-status-tooltip', } as const