~james/core

core/web/src/lib/components/profile/ProfileTabs.svelte -rw-r--r-- 2.2 KiB
452f17b7 — james chore(import): snapshot james.dad.town/core at f70c71c7696a 16 hours ago
                                                                                
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
<script lang="ts">
	import { dev } from "$app/env";
	import { page } from "$app/state";
	import SquareChartGantt from "$icon/square-chart-gantt";
	import BookMarked from "$icon/book-marked";
	import Star from "$icon/star";
	import LineSquiggle from "$icon/line-squiggle";
	import Shield from "$icon/shield";
	import Settings from "$icon/settings";
	import Tabs, { type TabDef } from "#lib/components/ui/Tabs.svelte";
	import type { ProfileCounts } from "#lib/components/profile/types.ts";

	interface Props {
		actor: string;
		active: string;
		counts: ProfileCounts;
		organization?: boolean;
		settings?: boolean;
		layered?: boolean;
	}

	let {
		actor,
		active,
		counts,
		organization = false,
		settings = false,
		layered = false
	}: Props = $props();

	const hrefFor = (id: string) => {
		const query = new URLSearchParams([
			...(id === "overview" ? [] : [["tab", id]]),
			...(dev && page.url.searchParams.get("preview") === "organization"
				? [["preview", "organization"]]
				: [])
		]).toString();
		return `/${actor}${query ? `?${query}` : ""}`;
	};

	const tabs = $derived<TabDef[]>(
		organization
			? [
					{
						id: "overview",
						label: "Overview",
						icon: SquareChartGantt,
						href: hrefFor("overview")
					},
					{
						id: "repos",
						label: "Repositories",
						icon: BookMarked,
						count: counts.repos,
						href: hrefFor("repos")
					},
					...(settings
						? [
								{
									id: "settings",
									label: "Settings",
									icon: Settings,
									href: hrefFor("settings")
								}
							]
						: [])
				]
			: [
					{
						id: "overview",
						label: "Overview",
						icon: SquareChartGantt,
						href: hrefFor("overview")
					},
					{
						id: "repos",
						label: "Repositories",
						icon: BookMarked,
						count: counts.repos,
						href: hrefFor("repos")
					},
					{
						id: "starred",
						label: "Starred",
						icon: Star,
						count: counts.stars,
						href: hrefFor("starred")
					},
					{
						id: "strings",
						label: "Strings",
						icon: LineSquiggle,
						count: counts.strings,
						href: hrefFor("strings")
					},
					{ id: "vouches", label: "Vouches", icon: Shield, href: hrefFor("vouches") }
				]
	);
</script>

<Tabs {tabs} {active} {layered} label="profile sections" />