staging-tester / ocean-landing-serve / src/ routes/ help/ +page.svelte

<script lang="ts">
	import ArrowRightIcon from 'phosphor-svelte/lib/ArrowRightIcon';
	import CreditCardIcon from 'phosphor-svelte/lib/CreditCardIcon';
	import FolderSimpleIcon from 'phosphor-svelte/lib/FolderSimpleIcon';
	import KeyIcon from 'phosphor-svelte/lib/KeyIcon';
	import MagnifyingGlassIcon from 'phosphor-svelte/lib/MagnifyingGlassIcon';
	import ShieldIcon from 'phosphor-svelte/lib/ShieldIcon';
	import BoatIcon from 'phosphor-svelte/lib/BoatIcon';
	import TerminalIcon from 'phosphor-svelte/lib/TerminalIcon';
	import XIcon from 'phosphor-svelte/lib/XIcon';
	import { afterNavigate } from '$app/navigation';
	import { page } from '$app/state';
	import Footer from '#lib/components/site/Footer.svelte';
	import Navbar from '#lib/components/site/Navbar.svelte';
	import OceanStrip from '#lib/components/site/OceanStrip.svelte';
	import * as Accordion from '#lib/components/ui/accordion/index.js';
	import { Button } from '#lib/components/ui/button/index.js';
	import { articles, topics, type HelpTopic } from '#lib/help.js';

	const icons = { account: KeyIcon, git: TerminalIcon, caissons: FolderSimpleIcon, moving: BoatIcon, billing: CreditCardIcon, privacy: ShieldIcon };

	// The site search links answers here as ?q=<question>; open that answer.
	const answer = (q: string) => (articles.some((a) => a.q === q) ? q : '');
	const asked = page.url.searchParams.get('q') ?? '';
	let query = $state(asked);
	let open = $state(answer(asked));

	afterNavigate(() => {
		const q = page.url.searchParams.get('q');
		if (q === null) return;
		query = q;
		open = answer(q);
	});

	const words = $derived(query.trim().toLowerCase().split(/\s+/).filter(Boolean));
	const hits = $derived(articles.filter((a) => words.every((w) => `${a.q} ${a.a}`.toLowerCase().includes(w))));
	const grouped = $derived(topics.map((t) => ({ topic: t, items: hits.filter((a) => a.topic === t.id) })).filter((g) => g.items.length > 0));
	const count = (id: HelpTopic['id']) => articles.filter((a) => a.topic === id).length;
	const ask = $derived(`/contact?message=${encodeURIComponent(query.trim() ? `I need help with: ${query.trim()}. ` : 'I need help with ')}`);
</script>

<svelte:head>
	<title>Help · Sailfork</title>
	<meta name="description" content="Answers about signing in, SSH keys, moving to Sailfork, billing and your data." />
</svelte:head>

<Navbar />

<main>
	<header class="pt-10 sm:pt-16">
		<div class="mx-auto grid max-w-7xl gap-8 px-4 sm:px-6 lg:grid-cols-12 lg:items-end lg:px-8">
			<h1 class="type-display lg:col-span-7">How can we help?</h1>
			<div class="min-w-0 lg:col-span-5">
				<label for="help-search" class="sr-only">Search help</label>
				<div class="flex h-11 items-center gap-2 rounded-md border border-input bg-background px-3 transition-[box-shadow,border-color] focus-within:border-ring focus-within:ring-3 focus-within:ring-ring/50">
					<MagnifyingGlassIcon aria-hidden="true" class="size-4 shrink-0 text-muted-foreground" />
					<input
						id="help-search"
						type="search"
						bind:value={query}
						autocomplete="off"
						placeholder="Try “reset password” or “ssh key”"
						class="type-ui h-full min-w-0 flex-1 bg-transparent outline-none placeholder:text-muted-foreground [&::-webkit-search-cancel-button]:hidden"
					/>
					{#if query}
						<button type="button" onclick={() => (query = '')} aria-label="Clear search" class="cursor-pointer rounded-sm text-muted-foreground transition-colors hover:text-foreground focus-visible:ring-3 focus-visible:ring-ring/50 focus-visible:outline-none">
							<XIcon class="size-4" aria-hidden="true" />
						</button>
					{/if}
				</div>
				<p class="type-small mt-2 text-muted-foreground" aria-live="polite">
					{words.length === 0 ? `${articles.length} answers across ${topics.length} topics.` : `${hits.length} ${hits.length === 1 ? 'answer matches' : 'answers match'}.`}
				</p>
			</div>
		</div>
		<div class="mt-12"><OceanStrip /></div>
	</header>

	{#if words.length === 0}
		<nav aria-label="Help topics" class="border-t border-border">
			<ul class="mx-auto grid max-w-7xl px-4 sm:grid-cols-2 sm:px-6 lg:grid-cols-5 lg:px-8">
				{#each topics as t (t.id)}
					{@const Icon = icons[t.id]}
					<li class="border-b border-border sm:border-r sm:last:border-r-0 lg:border-b-0">
						<a href="#{t.id}" class="group grid h-full gap-3 px-1 py-6 transition-colors hover:bg-muted/60 focus-visible:ring-3 focus-visible:ring-ring/50 focus-visible:outline-none sm:px-5">
							<Icon aria-hidden="true" class="size-5 text-primary" />
							<span>
								<span class="type-heading block">{t.title}</span>
								<span class="type-small mt-1 block text-muted-foreground">{t.blurb}</span>
							</span>
							<span class="type-small text-muted-foreground tabular-nums">{count(t.id)} answers</span>
						</a>
					</li>
				{/each}
			</ul>
		</nav>
	{/if}

	{#if grouped.length === 0}
		<section class="border-t border-border py-20">
			<div class="mx-auto grid max-w-7xl gap-6 px-4 sm:px-6 lg:grid-cols-12 lg:px-8">
				<div class="lg:col-span-6 lg:col-start-5">
					<h2 class="type-title">Nothing matches “{query.trim()}”</h2>
					<p class="type-body mt-3 max-w-[48ch] text-muted-foreground">Try fewer words, or ask us. We answer every message ourselves.</p>
					<div class="mt-6 flex flex-wrap gap-3">
						<Button href={ask}>Ask us<ArrowRightIcon aria-hidden="true" /></Button>
						<Button variant="outline" onclick={() => (query = '')}>Clear search</Button>
					</div>
				</div>
			</div>
		</section>
	{:else}
		{#each grouped as g (g.topic.id)}
			{@const Icon = icons[g.topic.id]}
			<section id={g.topic.id} aria-labelledby="{g.topic.id}-title" class="scroll-mt-8 border-t border-border py-16">
				<div class="mx-auto grid max-w-7xl gap-10 px-4 sm:px-6 lg:grid-cols-12 lg:px-8">
					<div class="lg:col-span-4">
						<Icon aria-hidden="true" class="size-5 text-primary" />
						<h2 id="{g.topic.id}-title" class="type-title mt-3">{g.topic.title}</h2>
						<p class="type-body mt-2 max-w-[36ch] text-muted-foreground">{g.topic.blurb}</p>
					</div>
					<Accordion.Root type="single" bind:value={open} class="border-b border-border lg:col-span-8">
						{#each g.items as item (item.q)}
							<Accordion.Item value={item.q} class="border-t border-border">
								<Accordion.Trigger class="type-heading gap-4 py-5">{item.q}</Accordion.Trigger>
								<Accordion.Content class="pb-5">
									<div class="animate-in fade-in-0 slide-in-from-top-1 duration-200 ease-snappy motion-reduce:animate-none">
										<p class="type-body max-w-[62ch] text-muted-foreground">{item.a}</p>
										{#if item.link}
											<a href={item.link.href} class="type-ui mt-3 inline-flex items-center gap-1 text-primary underline underline-offset-4">
												{item.link.label}<ArrowRightIcon class="size-3.5" aria-hidden="true" />
											</a>
										{/if}
									</div>
								</Accordion.Content>
							</Accordion.Item>
						{/each}
					</Accordion.Root>
				</div>
			</section>
		{/each}
	{/if}

	<section aria-labelledby="still-title" class="border-t border-border py-20">
		<div class="mx-auto grid max-w-7xl gap-10 px-4 sm:px-6 lg:grid-cols-12 lg:px-8">
			<h2 id="still-title" class="type-title lg:col-span-4">Still stuck?</h2>
			<dl class="grid gap-x-10 sm:grid-cols-2 lg:col-span-8">
				<div class="border-t border-border py-5">
					<dt class="type-heading">Write to us</dt>
					<dd class="type-body mt-1 max-w-[42ch] text-muted-foreground">Say what you tried and what happened. Include the repository and the command if it is about git. <a href={ask} class="inline-flex items-center gap-1 text-primary underline underline-offset-4">
							Contact us<ArrowRightIcon class="size-3.5" aria-hidden="true" />
						</a></dd>
				</div>
				<div class="border-t border-border py-5">
					<dt class="type-heading">Locked out?</dt>
					<dd class="type-body mt-1 max-w-[42ch] text-muted-foreground">Write from the email on your account, so we can tell it is you. We never ask for your password.</dd>
				</div>
			</dl>
		</div>
	</section>
</main>

<Footer />