Skip to content

Commit 7a44ed1

Browse files
committed
use better typescript
1 parent 8c52389 commit 7a44ed1

5 files changed

Lines changed: 23 additions & 32 deletions

File tree

packages/client/src/components/app/ChatApp.svelte

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,7 @@
55
import Channel from "../channels/Channel.svelte";
66
import ChannelList from "../channels/ChannelList.svelte";
77
import Personalization from "../chat/Personalization.svelte";
8-
9-
type Selection =
10-
| { type: "chat"; selectedChannelId: Id<"channels"> | undefined }
11-
| { type: "personalization"; selectedChannelId: undefined };
8+
import type { Selection } from "../chat/types.ts";
129
1310
interface Props {
1411
organizationId: Id<"organizations">;
Lines changed: 14 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,9 @@
11
<script lang="ts">
22
import { api, type Id } from "@packages/convex";
33
import { useQuery } from "convex-svelte";
4+
import type { Selection } from "$components/chat/types";
45
import CreateChannelButton from "./CreateChannelButton.svelte";
56
6-
type Selection =
7-
| { type: "chat"; selectedChannelId: Id<"channels"> | undefined }
8-
| { type: "personalization"; selectedChannelId: undefined };
9-
107
interface Props {
118
organizationId: Id<"organizations">;
129
screenMode: Selection;
@@ -28,25 +25,21 @@
2825
<div class="flex-1 overflow-y-auto">
2926
{#if channels.data}
3027
{#each channels.data as channel (channel._id)}
31-
<button
28+
{@const active =
29+
screenMode.type === "chat" &&
30+
screenMode.selectedChannelId === channel._id}
31+
<a
3232
class={[
33-
"border-base-300 w-full border-b p-3 text-left",
34-
screenMode.selectedChannelId === channel._id
35-
? "bg-primary text-primary-content"
36-
: "hover:bg-base-300",
37-
].join(" ")}
38-
onclick={() => {
39-
screenMode = {
40-
type: "chat",
41-
selectedChannelId: channel._id as Id<"channels">,
42-
};
43-
}}
33+
"border-base-300 block w-full border-b p-3 text-left",
34+
active ? "bg-primary text-primary-content" : "hover:bg-base-300",
35+
]}
36+
href={`/orgs/${organizationId}/chat/${channel._id}`}
4437
>
45-
<div class="font-medium"># {channel.name}</div>
38+
<span class="font-medium"># {channel.name}</span>
4639
{#if channel.description}
47-
<div class="text-sm opacity-70">{channel.description}</div>
40+
<span class="text-sm opacity-70">{channel.description}</span>
4841
{/if}
49-
</button>
42+
</a>
5043
{/each}
5144
{:else}
5245
<div class="text-base-content/60 p-4 text-center">
@@ -60,10 +53,8 @@
6053
</div>
6154
{/if}
6255
</div>
63-
<button
56+
<a
6457
class="btn btn-primary mt-auto mb-2 w-full"
65-
onclick={() => {
66-
screenMode = { type: "personalization", selectedChannelId: undefined };
67-
}}>個人用設定</button
58+
href={`/orgs/${organizationId}/personalization`}>個人用設定</a
6859
>
6960
</div>
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import type { Id } from "@packages/convex";
2+
3+
export type Selection =
4+
| { type: "top" }
5+
| { type: "chat"; selectedChannelId: Id<"channels"> }
6+
| { type: "personalization" };

packages/client/src/routes/orgs/[orgId]/+page.svelte

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,4 @@
66
const orgId = $derived(page.params.orgId as Id<"organizations">);
77
</script>
88

9-
<ChatApp
10-
organizationId={orgId}
11-
screenMode={{ type: "chat", selectedChannelId: undefined }}
12-
/>
9+
<ChatApp organizationId={orgId} screenMode={{ type: "top" }} />

packages/client/src/routes/orgs/[orgId]/personalization/+page.svelte

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,5 @@
88

99
<ChatApp
1010
organizationId={orgId as Id<"organizations">}
11-
screenMode={{ type: "personalization", selectedChannelId: undefined }}
11+
screenMode={{ type: "personalization" }}
1212
/>

0 commit comments

Comments
 (0)