From 08b58ee72953e746d268f76419cdf575f88f0f39 Mon Sep 17 00:00:00 2001 From: donavon04 Date: Wed, 11 Dec 2024 14:57:00 -0700 Subject: [PATCH] added full CRUD capabilities --- backend/app.js | 5 +- frontend/env.txt | 6 - frontend/src/lib/components/Tiptap.svelte | 12 +- frontend/src/routes/+layout.svelte | 55 +++++- frontend/src/routes/+page.svelte | 27 --- frontend/src/routes/add/+page.svelte | 68 +++++-- frontend/src/routes/document/+page.svelte | 214 ++++++++++++++++------ frontend/src/routes/edit/+page.svelte | 189 +++++++++++++++++++ frontend/src/routes/home/+page.svelte | 9 + frontend/src/routes/login/+page.svelte | 19 -- 10 files changed, 473 insertions(+), 131 deletions(-) delete mode 100644 frontend/env.txt create mode 100644 frontend/src/routes/edit/+page.svelte diff --git a/backend/app.js b/backend/app.js index aceef8f..0e91df3 100644 --- a/backend/app.js +++ b/backend/app.js @@ -42,7 +42,7 @@ app.use((err, req, res, next) => { // Create a new document app.post('/documents', async (req, res) => { - const { title, body, tags } = req.body; + const { title, body, tags, created_by } = req.body; // Validate input if (!title || !body) { @@ -53,12 +53,15 @@ app.post('/documents', async (req, res) => { return res.status(400).json({ error: 'Tags must be an array' }); } + console.log(created_by); + try { // Insert the document into the database const result = await db.collection('documents').insertOne({ title, body, tags, + created_by, created_at: new Date() }); diff --git a/frontend/env.txt b/frontend/env.txt deleted file mode 100644 index cbd9674..0000000 --- a/frontend/env.txt +++ /dev/null @@ -1,6 +0,0 @@ -AUTH_SECRET="txvHsSGbEuQ6j3I3YZEyXkVJnPTP/s5vdK4+OJ8sxQo=" # Added by `npx auth`. Read more: https://cli.authjs.dev - -AUTH_MICROSOFT_ENTRA_ID_ID='3cdfac60-e7fb-4648-89d3-67966c497d35' -AUTH_MICROSOFT_ENTRA_ID_SECRET='5Gi8Q~_pmDtvN3.Jwqt85kiI.uiyAAC7Z.4iFayY' -AUTH_MICROSOFT_ENTRA_ID_ISSUER='538b9b1c-23fa-4102-b36e-a4d83fc9c4c1' -POTATO='77863dd1-f8ab-4f6e-b94a-0f7a0340b320' \ No newline at end of file diff --git a/frontend/src/lib/components/Tiptap.svelte b/frontend/src/lib/components/Tiptap.svelte index 860015f..53a5796 100644 --- a/frontend/src/lib/components/Tiptap.svelte +++ b/frontend/src/lib/components/Tiptap.svelte @@ -13,6 +13,11 @@ let element; let editor; + let initialHTML; + + export function setHTML(html){ + editor.commands.insertContent(html); + } export function getHTML(){ const html = editor.getHTML(); // Get the editor content as HTML @@ -25,6 +30,7 @@ extensions: [ StarterKit, Underline, + Image.configure({ block: true }), Dropcursor, CodeBlock.configure({ exitOnTripleEnter: true, @@ -34,7 +40,6 @@ class: 'bg-gray-900 border-2 border-gray-500 rounded-xl p-2 text-white', }, }), - Image, TextAlign.configure({ types: ['heading', 'paragraph'], }), @@ -79,7 +84,11 @@ }, }), ], + // place the cursor in the editor after initialization + autofocus: true, + // make the text editable (but that’s the default anyway) editable: true, + // disable the loading of the default CSS (which is not much anyway) injectCSS: false, onTransaction: () => { // force re-render so `editor.isActive` works as expected @@ -90,6 +99,7 @@ class: 'prose-base m-3 focus:outline-none', }, }, + content: initialHTML, }); }); diff --git a/frontend/src/routes/+layout.svelte b/frontend/src/routes/+layout.svelte index 9852654..a980d5e 100644 --- a/frontend/src/routes/+layout.svelte +++ b/frontend/src/routes/+layout.svelte @@ -1,12 +1,59 @@ +
+ + MPE Logo + -
- MPE Logo - Add +
- diff --git a/frontend/src/routes/+page.svelte b/frontend/src/routes/+page.svelte index 9de8e97..e69de29 100644 --- a/frontend/src/routes/+page.svelte +++ b/frontend/src/routes/+page.svelte @@ -1,27 +0,0 @@ - - -

SvelteKit Auth Example

-
- {#if $page.data.session} - {#if $page.data.session.user?.image} - User Avatar - {/if} - - Signed in as
- {$page.data.session.user?.name ?? "User"} - -
- {:else} - You are not signed in -
- -
- {/if} -
\ No newline at end of file diff --git a/frontend/src/routes/add/+page.svelte b/frontend/src/routes/add/+page.svelte index 0327276..b7570c8 100644 --- a/frontend/src/routes/add/+page.svelte +++ b/frontend/src/routes/add/+page.svelte @@ -3,6 +3,7 @@ -
-
- +
+
+
+ + +
+ + + + {#if dropMenu} +
+ + +
+ {/if} +
+
- +
{#each tags as tag, i} - @@ -104,8 +135,11 @@
- +
-
+
\ No newline at end of file diff --git a/frontend/src/routes/document/+page.svelte b/frontend/src/routes/document/+page.svelte index ad9410c..64b10ef 100644 --- a/frontend/src/routes/document/+page.svelte +++ b/frontend/src/routes/document/+page.svelte @@ -1,60 +1,162 @@ - - - {#if error} -

{error}

- {:else if document} -
-
-
-

{document.title}

-
- {#each document.tags as tag} -
-

{tag}

-
- {/each} -
- {#if document.author} -

By: {document.author}

- {/if} - {#if document.created_at} -

{new Date(document.created_at).toLocaleString()}

- {/if} -
-
- - {@html document.body} -
+ + const result = await response.json(); + console.log(result.message); + + // Redirect after successful deletion + window.location.href = "/home"; + } catch (error) { + console.error('Error deleting document:', error); + alert('An unexpected error occurred while deleting the document.'); + } + } + + // Reset popup and decision + alertPopup = false; + agreeToDelete = false; +} + + + +{#if alertPopup} + +
+ + +
+

Do you agree to delete this document forever?

+
+ +
- {:else} -

Loading...

- {/if} +
+{/if} + +{#if error} +

{error}

+{:else if document} +
+
+
+
+

{document.title}

+ {#if $page.data.session} +
+ + +
+ {/if} +
+
+
+ {#each document.tags as tag} +
+

{tag}

+
+ {/each} +
+
+
+ {#if document.created_by} +

By: {document.created_by}

+ {/if} +
+
+ {#if document.created_at} +

{new Date(document.created_at).toLocaleString()}

+ {/if} +
+
+
+
+
+ + {@html document.body} +
+
+{:else} + +{/if} \ No newline at end of file diff --git a/frontend/src/routes/edit/+page.svelte b/frontend/src/routes/edit/+page.svelte new file mode 100644 index 0000000..b054c55 --- /dev/null +++ b/frontend/src/routes/edit/+page.svelte @@ -0,0 +1,189 @@ + + Add + + + + +
+
+
+ + +
+ + + + {#if dropMenu} +
+ + +
+ {/if} +
+
+ +
+ +
+
+ + +
+
+ {#each tags as tag, i} + + {/each} +
+
+
+ +
+
+ +
\ No newline at end of file diff --git a/frontend/src/routes/home/+page.svelte b/frontend/src/routes/home/+page.svelte index 7935a7c..ae3476d 100644 --- a/frontend/src/routes/home/+page.svelte +++ b/frontend/src/routes/home/+page.svelte @@ -1,5 +1,6 @@
+ {#if $page.data.session} +
+ + + +
+ {/if}

{@html document.title}

{@html truncateBody(document.body)}

+
{/each} diff --git a/frontend/src/routes/login/+page.svelte b/frontend/src/routes/login/+page.svelte index dfebf9d..d57564d 100644 --- a/frontend/src/routes/login/+page.svelte +++ b/frontend/src/routes/login/+page.svelte @@ -32,25 +32,6 @@
- {#if $page.data.session} - {#if $page.data.session.user?.image} - User Avatar - {/if} - - Signed in as
- {$page.data.session.user?.name ?? "User"} - -
- {:else} - You are not signed in -
- -
- {/if}

Not a member?