-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathChannelItem.svelte
More file actions
77 lines (71 loc) · 2.04 KB
/
ChannelItem.svelte
File metadata and controls
77 lines (71 loc) · 2.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
<script lang="ts">
import Hash from "@lucide/svelte/icons/hash";
import type { Channel, ChannelGroup } from "@packages/api-client";
import ChannelContextMenu from "./ChannelContextMenu.svelte";
interface Props {
channel: Channel;
organizationId: string;
active: boolean;
unreadCount: number;
indent?: string;
groups?: ChannelGroup[];
onEdit?: (channel: Channel) => void;
onDelete?: (channelId: string) => void;
onLeave?: (channelId: string) => void;
onMoveToGroup?: (channelId: string, groupId: string | null) => void;
}
let {
channel,
organizationId,
active,
unreadCount,
indent,
groups = [],
onEdit,
onDelete,
onLeave,
onMoveToGroup,
}: Props = $props();
let contextMenu = $state<{ x: number; y: number } | null>(null);
function handleContextMenu(e: MouseEvent) {
e.preventDefault();
contextMenu = { x: e.clientX, y: e.clientY };
}
</script>
{#if contextMenu}
<ChannelContextMenu
x={contextMenu.x}
y={contextMenu.y}
channelType={channel.type}
currentGroupId={channel.groupId ?? null}
{groups}
onEdit={() => onEdit?.(channel)}
onDelete={() => onDelete?.(channel.id)}
onLeave={() => onLeave?.(channel.id)}
onMoveToGroup={(groupId) => onMoveToGroup?.(channel.id, groupId)}
onClose={() => (contextMenu = null)}
/>
{/if}
<a
href={`/orgs/${organizationId}/chat/${channel.id}`}
class={[
"group flex items-center gap-2 rounded px-2 py-2 text-sm transition-colors",
active
? "bg-primary/15 text-primary"
: "text-base-content/80 hover:bg-base-300 hover:text-base-content",
]}
style:padding-left={indent}
oncontextmenu={handleContextMenu}
>
<Hash
class={["size-4 flex-shrink-0", active ? "text-primary" : "text-muted"]}
/>
<span class={["flex-1 truncate", unreadCount > 0 && "font-medium"]}>
{channel.name}
</span>
{#if unreadCount > 0}
<span class="badge-unread flex items-center justify-center rounded-full">
{unreadCount > 99 ? "99+" : unreadCount}
</span>
{/if}
</a>