From 13259169319a05ee05a92881dfd34bcdea7a59ba Mon Sep 17 00:00:00 2001 From: andrewlalis Date: Thu, 16 Nov 2023 16:17:10 -0500 Subject: [PATCH] Improved auth redirection, and added PrintableListView.vue --- litelist-app/src/router/index.ts | 5 ++ litelist-app/src/stores/auth.ts | 2 +- litelist-app/src/views/LoginView.vue | 2 + litelist-app/src/views/PrintableListView.vue | 56 ++++++++++++++++++++ litelist-app/src/views/SingleListView.vue | 35 ++---------- 5 files changed, 68 insertions(+), 32 deletions(-) create mode 100644 litelist-app/src/views/PrintableListView.vue diff --git a/litelist-app/src/router/index.ts b/litelist-app/src/router/index.ts index 9959f63..d6a9c9d 100644 --- a/litelist-app/src/router/index.ts +++ b/litelist-app/src/router/index.ts @@ -4,6 +4,7 @@ import ListsView from "@/views/ListsView.vue"; import {useAuthStore} from "@/stores/auth"; import SingleListView from "@/views/SingleListView.vue"; import AdminView from "@/views/AdminView.vue"; +import PrintableListView from "@/views/PrintableListView.vue"; const router = createRouter({ history: createWebHistory(import.meta.env.BASE_URL), @@ -33,6 +34,10 @@ const router = createRouter({ path: "/lists/:id", component: SingleListView }, + { + path: "/lists/:id/print", + component: PrintableListView + }, { path: "/admin", component: AdminView diff --git a/litelist-app/src/stores/auth.ts b/litelist-app/src/stores/auth.ts index b6a607e..27c322c 100644 --- a/litelist-app/src/stores/auth.ts +++ b/litelist-app/src/stores/auth.ts @@ -21,7 +21,7 @@ export const useAuthStore = defineStore("auth", () => { token.value = newToken localStorage.setItem(LOCAL_STORAGE_KEY, token.value) tokenRefreshInterval.value = setInterval(tryRefreshToken, 60000) - await router.push("/lists") + // await router.push("/lists") } async function logOut() { diff --git a/litelist-app/src/views/LoginView.vue b/litelist-app/src/views/LoginView.vue index c882c72..1534a0c 100644 --- a/litelist-app/src/views/LoginView.vue +++ b/litelist-app/src/views/LoginView.vue @@ -29,6 +29,7 @@ async function doLogin() { try { const info = await login(loginModel.value.username, loginModel.value.password) await authStore.logIn(info.token, info.user) + await router.push("/lists") } catch (error: any) { console.error(error.message) } @@ -45,6 +46,7 @@ async function doRegister() { await register(registerModel.value.username, registerModel.value.email, registerModel.value.password) const info = await login(registerModel.value.username, registerModel.value.password) await authStore.logIn(info.token, info.user) + await router.push("/lists") } catch (error: any) { console.error(error) } diff --git a/litelist-app/src/views/PrintableListView.vue b/litelist-app/src/views/PrintableListView.vue new file mode 100644 index 0000000..59075a8 --- /dev/null +++ b/litelist-app/src/views/PrintableListView.vue @@ -0,0 +1,56 @@ + + + + + + \ No newline at end of file diff --git a/litelist-app/src/views/SingleListView.vue b/litelist-app/src/views/SingleListView.vue index edc0ed5..7b012d7 100644 --- a/litelist-app/src/views/SingleListView.vue +++ b/litelist-app/src/views/SingleListView.vue @@ -66,13 +66,14 @@ function toggleCreatingNewNote() { async function clearList() { if (!list.value) return + const l: NoteList = list.value const dialog = document.getElementById("list-clear-notes-dialog") as HTMLDialogElement dialog.showModal() const confirmButton = document.getElementById("clear-notes-confirm-button") as HTMLButtonElement confirmButton.onclick = async () => { dialog.close() - await deleteAllNotes(authStore.token, list.value.id) - list.value.notes = [] + await deleteAllNotes(authStore.token, l.id) + l.notes = [] } const cancelButton = document.getElementById("clear-notes-cancel-button") as HTMLButtonElement cancelButton.onclick = async () => { @@ -87,32 +88,6 @@ async function createNoteAndRefresh() { newNoteText.value = "" list.value = await getNoteList(authStore.token, list.value.id) } - -function printList() { - if (!list.value) return - const l: NoteList = list.value - const header = `

${l.name}

` - const description = `

${l.description}

` - let checkboxList = `
` - for (let i = 0; i < l.notes.length; i++) { - const note = l.notes[i] - checkboxList += `
` - } - checkboxList += `
` - const w = window.open() - const html = ` - - - -${header} -${description} -${checkboxList} - - -` - w.document.write(html) - w.window.print() -}