From c466f45de16837987a6dee2719f7c4a4ef1a6ca3 Mon Sep 17 00:00:00 2001 From: Hao Wu Date: Sat, 21 Sep 2024 12:01:00 +0800 Subject: [PATCH] Todo nav (#50) * move nav to home * Refactor DiaryEditor and Home components: - Add loading icon to DiaryEditor. - Remove unnecessary interval and styles from DiaryEditor. - Update navigation links in NavBar and Home. - Improve date navigation in Home. - Scope styles to components. --- api/Notepad.fsproj | 3 +- api/Program.fs | 1 + api/Word.fs | 13 +++++ web/src/components/DiaryEditor.vue | 58 +++---------------- web/src/components/NavBar.vue | 2 +- web/src/router.js | 2 +- web/src/util.js | 2 +- web/src/views/Home.vue | 93 ++++++++++++++++++++++++++++-- 8 files changed, 115 insertions(+), 59 deletions(-) create mode 100644 api/Word.fs diff --git a/api/Notepad.fsproj b/api/Notepad.fsproj index 3c9b38c..2bbf20a 100644 --- a/api/Notepad.fsproj +++ b/api/Notepad.fsproj @@ -1,4 +1,4 @@ - + Exe net8.0 @@ -16,6 +16,7 @@ + diff --git a/api/Program.fs b/api/Program.fs index 9a5a5ad..45e7a08 100644 --- a/api/Program.fs +++ b/api/Program.fs @@ -153,6 +153,7 @@ webHost [||] { get "/api/diary/{id}" Note.noteByIdPartDebug put "/api/diary/{id}" Note.addNotePart get "/api/todo" Note.todoListsHandler + get "/api/random-word" Word.getRandomWord ] use_middleware serveVueFiles diff --git a/api/Word.fs b/api/Word.fs new file mode 100644 index 0000000..e840eaa --- /dev/null +++ b/api/Word.fs @@ -0,0 +1,13 @@ +module Word + +open System + +let randomWords = + [ ] // Add more words as needed + +let getRandomWord = + fun ctx -> + let random = Random() + let word = randomWords.[random.Next(randomWords.Length)] + // refresh note summary + Falco.Request.mapRoute (ignore) (fun _ -> {| word = word |} |> Json.Response.ofJson) ctx diff --git a/web/src/components/DiaryEditor.vue b/web/src/components/DiaryEditor.vue index 47d53db..e55618c 100644 --- a/web/src/components/DiaryEditor.vue +++ b/web/src/components/DiaryEditor.vue @@ -1,18 +1,9 @@ @@ -42,29 +33,12 @@ const props = defineProps({ }); -const now = ref(moment()); const loading = ref(true); -const timeFormat = 'h:mm:ss a'; const last_note_json = ref(null); const content = ref(null); -const icons = { - tableOfContents, -}; const extensions = createExtensions(); const json = ref(null); -onMounted(() => { - // eslint-disable-next-line no-unused-vars - const interval = setInterval(() => now.value = moment(), 1000); -}); - -const today = computed(() => { - return now.value.format('YYYYMMDD'); -}); - -const time = computed(() => { - return now.value.format(timeFormat); -}); const mutation = useMutation({ mutationFn: async () => { @@ -122,6 +96,11 @@ const onInit = async ({ editor }) => { editor.setContent(lastNoteJson); } } catch (error) { + if (error.response && error.response.status === 401) { + // Use the correct router method in the Vue 3 setup + router.push({ name: 'login' }); + } + console.error('Error updating diary:', error); console.error('Error fetching diary content:', error); } finally { loading.value = false; @@ -129,31 +108,10 @@ const onInit = async ({ editor }) => { }; - diff --git a/web/src/components/NavBar.vue b/web/src/components/NavBar.vue index 2fb420e..57cf9db 100644 --- a/web/src/components/NavBar.vue +++ b/web/src/components/NavBar.vue @@ -1,6 +1,6 @@