From bf74f0e2594dbad96caa1635f9c426b32e3c2323 Mon Sep 17 00:00:00 2001 From: 180079995 <101566121+180079995@users.noreply.github.com> Date: Wed, 27 Nov 2024 00:07:57 +0800 Subject: [PATCH 1/3] discussion --- src/routes/+layout.svelte | 2 +- src/routes/join/+page.svelte | 19 +--- src/routes/session/[id]/+page.svelte | 33 ++++++- .../[id]/discussion/[userId]/+page.server.ts | 30 ++++++ .../[id]/discussion/[userId]/+page.svelte | 91 +++++++++++++++++++ 5 files changed, 154 insertions(+), 21 deletions(-) create mode 100644 src/routes/session/[id]/discussion/[userId]/+page.server.ts create mode 100644 src/routes/session/[id]/discussion/[userId]/+page.svelte diff --git a/src/routes/+layout.svelte b/src/routes/+layout.svelte index 888fa88..b5aeebd 100644 --- a/src/routes/+layout.svelte +++ b/src/routes/+layout.svelte @@ -19,6 +19,6 @@ } main.sidebar-open { - margin-left: 12.5rem; /* 側邊欄的寬度 */ + margin-left: 12.5rem; } diff --git a/src/routes/join/+page.svelte b/src/routes/join/+page.svelte index 9250b24..0a3979c 100644 --- a/src/routes/join/+page.svelte +++ b/src/routes/join/+page.svelte @@ -40,22 +40,9 @@ bind:value={tempIdInput} required pattern="\d\{6}" - class="w-full rounded-lg border p-2" + class="w-full rounded-lg border p-2 font-bold" placeholder="Enter 6-digit code" /> - - - - {#if form?.idInvalid}

Please enter a valid 6-digit code

{/if} @@ -73,10 +60,10 @@ required pattern="^(?:[1-9]|[1-4][0-9]|50)$" class="w-full rounded-lg border p-2" - placeholder="輸入組別" + placeholder="Please enter your group number" /> {#if form?.groupNumberInvalid} -

請輸入有效的組別

+

Please enter a valid group number

{/if} diff --git a/src/routes/session/[id]/+page.svelte b/src/routes/session/[id]/+page.svelte index f5c59aa..e895d94 100644 --- a/src/routes/session/[id]/+page.svelte +++ b/src/routes/session/[id]/+page.svelte @@ -27,6 +27,11 @@ resources = resources.filter((_, i) => i !== index); } + function generateNewTask() { + // Generate new task + console.log('New task generated'); + } + removeResource(0); function applyChanges(newtitle: string, resources: Array<{ type: string; content: string }>) { @@ -87,19 +92,19 @@
{#if editingTitle}
+ -
{:else} -

{session.title}

{#if isHost} {/if} +

{session.title}


{/if}

Hosted by {session.hostName}

@@ -253,7 +258,7 @@ {:else}
{#each Object.entries(session.participants) as [userId, participant]} -
+
{#if !(userId === session.hostId) && isHost} @@ -285,9 +290,29 @@ {:else if session.status === 'ended'} This session has ended. {:else} - Discussion in progress... + Now discussing... {/if}

+ {#if session.status === 'active'} +

Topic

+

session.topic

+
+ +
+ + {/if}
diff --git a/src/routes/session/[id]/discussion/[userId]/+page.server.ts b/src/routes/session/[id]/discussion/[userId]/+page.server.ts new file mode 100644 index 0000000..05957fc --- /dev/null +++ b/src/routes/session/[id]/discussion/[userId]/+page.server.ts @@ -0,0 +1,30 @@ +import { adminDb } from '$lib/server/firebase'; +import { redirect } from '@sveltejs/kit'; +import type { Actions, PageServerLoad } from '../$types'; + +export const load: PageServerLoad = async ({ params, locals }) => { + if (!locals.user) { + throw redirect(303, '/login'); + } + + const sessionRef = adminDb.collection('discussion').doc(params.id); + console.log(sessionRef); + //const sessionDoc = await sessionRef.get(); + + /* + if (!sessionDoc.exists) { + throw error(404, 'User is not in the session'); + } + */ + + return {}; +}; + +export const actions = { + default: async ({ locals }) => { + if (!locals.user) { + throw redirect(303, '/login'); + } + //send message to the server + } +} satisfies Actions; diff --git a/src/routes/session/[id]/discussion/[userId]/+page.svelte b/src/routes/session/[id]/discussion/[userId]/+page.svelte new file mode 100644 index 0000000..c636d83 --- /dev/null +++ b/src/routes/session/[id]/discussion/[userId]/+page.svelte @@ -0,0 +1,91 @@ + + +
+
+
+ {#each messages as message} +
+ {message.sender === 'me' ? 'You' : 'Support'}: + {message.text} +
+ {/each} +
+
+ {#if messages[messages.length - 1].sender === 'me'} + + {:else} + e.key === 'Enter' && sendMessage()} + /> + {/if} + + + {#if messages[messages.length - 1].sender === 'me'} +
Please wait for a response...
+ {/if} +
+
+
+ + From a8208cad53b888bc996f2050373d17376157a9a1 Mon Sep 17 00:00:00 2001 From: 180079995 <101566121+180079995@users.noreply.github.com> Date: Wed, 27 Nov 2024 00:30:30 +0800 Subject: [PATCH 2/3] Update +page.svelte --- .../[id]/discussion/[userId]/+page.svelte | 37 ++++++++----------- 1 file changed, 15 insertions(+), 22 deletions(-) diff --git a/src/routes/session/[id]/discussion/[userId]/+page.svelte b/src/routes/session/[id]/discussion/[userId]/+page.svelte index c636d83..9c9afd6 100644 --- a/src/routes/session/[id]/discussion/[userId]/+page.svelte +++ b/src/routes/session/[id]/discussion/[userId]/+page.svelte @@ -3,6 +3,7 @@ let inputText = ''; function sendMessage() { + if (messages[messages.length - 1].sender === 'me') return; if (inputText.trim() !== '') { messages = [...messages, { sender: 'me', text: inputText }]; inputText = ''; @@ -10,7 +11,7 @@ } -
+
{#each messages as message} @@ -21,24 +22,19 @@ {/each}
- {#if messages[messages.length - 1].sender === 'me'} - - {:else} - e.key === 'Enter' && sendMessage()} - /> - {/if} - - e.key === 'Enter' && sendMessage()} + /> + +
{#if messages[messages.length - 1].sender === 'me'} -
Please wait for a response...
+
Please wait for a response...
{/if}
@@ -65,11 +61,9 @@ text-align: left; } .input-area { - display: flex; margin-top: 10px; - } - .input-area div { - display: block; + display: flex; + flex-wrap: wrap; } .input-area input { flex: 1; @@ -77,7 +71,6 @@ } .input-area button { padding: 10px; - display: block; } .input-area button:hover { background-color: #f0f0f0; From d504394fe8742cd800cd239ee86dd9c8bb7648fc Mon Sep 17 00:00:00 2001 From: 180079995 <101566121+180079995@users.noreply.github.com> Date: Wed, 27 Nov 2024 22:32:35 +0800 Subject: [PATCH 3/3] Update +page.svelte --- .../[id]/discussion/[userId]/+page.svelte | 30 +++++++++++++++---- 1 file changed, 24 insertions(+), 6 deletions(-) diff --git a/src/routes/session/[id]/discussion/[userId]/+page.svelte b/src/routes/session/[id]/discussion/[userId]/+page.svelte index 9c9afd6..fbebc62 100644 --- a/src/routes/session/[id]/discussion/[userId]/+page.svelte +++ b/src/routes/session/[id]/discussion/[userId]/+page.svelte @@ -1,6 +1,7 @@