-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #16 from hinagiku-dev/Frontend-update
Frontend update
- Loading branch information
Showing
5 changed files
with
139 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,6 +23,6 @@ | |
} | ||
main.sidebar-open { | ||
margin-left: 12.5rem; /* 側邊欄的寬度 */ | ||
margin-left: 12.5rem; | ||
} | ||
</style> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
src/routes/session/[id]/discussion/[userId]/+page.server.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; |
102 changes: 102 additions & 0 deletions
102
src/routes/session/[id]/discussion/[userId]/+page.svelte
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
<script> | ||
let messages = [{ sender: 'Support', text: 'Hello! How can I assist you today?' }]; | ||
let inputText = ''; | ||
//import { User } from 'lucide-svelte' | ||
function sendMessage() { | ||
if (messages[messages.length - 1].sender === 'me') return; | ||
if (inputText.trim() !== '') { | ||
messages = [...messages, { sender: 'me', text: inputText }]; | ||
inputText = ''; | ||
} | ||
} | ||
</script> | ||
|
||
<main class="mt-20"> | ||
<div class="chat-container"> | ||
<div class="messages"> | ||
{#each messages as message} | ||
<div class="message" class:me={message.sender === 'me'}> | ||
<!--<User class="inline-block"/>--> | ||
{#if message.sender !== 'me'} | ||
<img src={message.avatar} alt="Avatar" class="avatar left" /> | ||
{/if} | ||
<p class="font-bold">{message.sender === 'me' ? 'You' : message.sender}:</p> | ||
{message.text} | ||
{#if message.sender === 'me'} | ||
<img src={message.avatar} alt="Avatar" class="avatar right" /> | ||
{/if} | ||
</div> | ||
{/each} | ||
</div> | ||
<div class="input-area"> | ||
<input | ||
class="inline-block" | ||
type="text" | ||
bind:value={inputText} | ||
placeholder="Type your message..." | ||
on:keyup={(e) => e.key === 'Enter' && sendMessage()} | ||
/> | ||
<button disabled={messages[messages.length - 1].sender === 'me'} on:click={sendMessage} | ||
>Send</button | ||
> | ||
<div class="w-full"></div> | ||
{#if messages[messages.length - 1].sender === 'me'} | ||
<div>Please wait for a response...</div> | ||
{/if} | ||
</div> | ||
</div> | ||
</main> | ||
|
||
<style> | ||
.chat-container { | ||
max-width: 80%; | ||
margin: 0 auto; | ||
} | ||
.messages { | ||
height: 400px; | ||
overflow-y: auto; | ||
border: 1px solid #ccc; | ||
padding: 10px; | ||
} | ||
.message { | ||
margin: 10px 0; | ||
text-align: left; | ||
} | ||
.message.me { | ||
text-align: right; | ||
} | ||
.input-area { | ||
margin-top: 10px; | ||
display: flex; | ||
flex-wrap: wrap; | ||
} | ||
.input-area input { | ||
flex: 1; | ||
padding: 10px; | ||
} | ||
.input-area button { | ||
padding: 10px; | ||
} | ||
.input-area button:hover { | ||
background-color: #f0f0f0; | ||
} | ||
.input-area button:active { | ||
background-color: #e0e0e0; | ||
} | ||
.input-area button:disabled { | ||
pointer-events: none; | ||
} | ||
.avatar { | ||
width: 40px; | ||
height: 40px; | ||
border-radius: 50%; | ||
margin: 0 10px; | ||
} | ||
.avatar.left { | ||
order: -1; | ||
} | ||
.avatar.right { | ||
order: 1; | ||
} | ||
</style> |