Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
130 changes: 116 additions & 14 deletions src/lib/components/panel/PanelHeader.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,29 @@

<script lang="ts">
import { onMount, type Snippet } from 'svelte';
import { VariableTabs } from 'm3-svelte';
import { Divider, Icon, Menu, MenuItem, VariableTabs } from 'm3-svelte';
import iconMenu from '@ktibow/iconset-material-symbols/menu';
import iconCheck from '@ktibow/iconset-material-symbols/check';
import OpenInTabButton from './OpenInTabButton.svelte';

let {
title,
mode,
modes,
tab,
tabs,
utilities,
view,
prepareHref,
tabActions,
children
}: {
title: string;
mode: string;
modes: PanelNavigationItem[];
tab: string;
tabs: PanelNavigationItem[];
utilities: PanelNavigationItem[];
view?: string;
prepareHref?: () => Promise<string>;
tabActions?: Snippet;
Expand All @@ -36,31 +44,125 @@
onMount(() => {
ready = true;
});

const menuId = $props.id();
let menuButton: HTMLButtonElement;
let menu: HTMLElement;
let menuTop = $state(0);
let menuLeft = $state(0);
let menuOpen = $state(false);
const utilityActive = $derived(utilities.some((item) => item.value === tab));

function positionMenu() {
const bounds = menuButton.getBoundingClientRect();
menuTop = Math.max(8, bounds.bottom + 8);
menuLeft = Math.max(
8,
Math.min(bounds.left, window.innerWidth - menu.getBoundingClientRect().width - 8)
);
}

function select(item: PanelNavigationItem) {
menu.hidePopover();
item.onselect();
}
</script>

<svelte:window
onresize={() => menuOpen && positionMenu()}
onscroll={() => menuOpen && positionMenu()}
/>

{#snippet navigationItem(item: PanelNavigationItem, current: 'true' | 'page' | undefined)}
<div class="navigation-item" aria-current={current}>
<MenuItem icon={item.icon ?? 'space'} onclick={() => select(item)}>
<span class="flex-1">{item.name}</span>
{#if current}<Icon icon={iconCheck} />{/if}
</MenuItem>
</div>
{/snippet}

<section
class="rounded-2xl bg-surface-container w-full shrink-0 overflow-hidden shadow-[0_0.2rem_0.75rem_rgb(var(--m3-scheme-shadow)/0.12)]"
>
<header
class="gap-3 bg-secondary-container px-4 py-4 text-on-secondary-container flex items-center justify-between"
>
<h1 class="leading-tight text-[clamp(1.35rem,5cqi,1.8rem)] font-[750] tracking-[-0.025em]">
<button
bind:this={menuButton}
type="button"
class="h-10 w-10 text-on-secondary-container hover:bg-on-secondary-container/10 focus-visible:outline-primary flex shrink-0 items-center justify-center rounded-full focus-visible:outline-2 focus-visible:outline-offset-2"
aria-label="Open navigation"
aria-expanded={menuOpen}
popovertarget={menuId}
>
<Icon icon={iconMenu} size={20} />
</button>
<h1
class="min-w-0 leading-tight flex-1 text-[clamp(1.35rem,5cqi,1.8rem)] font-[750] tracking-[-0.025em]"
>
{title}
</h1>
<OpenInTabButton {view} {prepareHref} />
</header>
<div class="bg-surface flex items-center">
<div class="preview-tabs min-w-0 flex-1">
<VariableTabs
secondary
disabled={!ready}
{tab}
items={tabs}
onchange={(event) =>
tabs.find((item) => item.value === event.currentTarget.value)?.onselect()}
/>
<nav
id={menuId}
bind:this={menu}
popover="auto"
aria-label="Application navigation"
class="m-0 w-70 p-0 max-w-[calc(100vw-1rem)] overflow-y-auto border-0 bg-transparent"
style:top={`${menuTop}px`}
style:left={`${menuLeft}px`}
style:max-height={`calc(100dvh - ${menuTop}px - 0.5rem)`}
ontoggle={(event) => {
menuOpen = event.newState === 'open';
if (menuOpen) positionMenu();
}}
>
<Menu>
<p class="px-5 py-2 text-sm font-medium text-on-surface-variant">WIT-Calendar</p>
{#each modes as item (item.value)}
{@render navigationItem(item, item.value === mode && !utilityActive ? 'true' : undefined)}
{/each}
<div class="my-2"><Divider inset /></div>
{#each utilities as item (item.value)}
{@render navigationItem(item, item.value === tab ? 'page' : undefined)}
{/each}
</Menu>
</nav>
{#if tabs.some((item) => item.value === tab)}
<div class="bg-surface flex items-center">
<div class="preview-tabs min-w-0 flex-1">
<VariableTabs
secondary
disabled={!ready}
{tab}
items={tabs}
onchange={(event) =>
tabs.find((item) => item.value === event.currentTarget.value)?.onselect()}
/>
</div>
{#if tabActions}<div class="px-1 shrink-0">{@render tabActions()}</div>{/if}
</div>
{#if tabActions}<div class="px-1 shrink-0">{@render tabActions()}</div>{/if}
</div>
{/if}
{@render children?.()}
</section>

<style>
.navigation-item {
margin-inline: 0.5rem;
border-radius: var(--m3-util-rounding-extra-small);
}
.navigation-item :global(button) {
width: 100%;
border-radius: inherit;
text-align: left;
}
.navigation-item[aria-current] {
background-color: rgb(var(--m3-scheme-secondary-container));
}
.navigation-item[aria-current] :global(button),
.navigation-item[aria-current] :global(svg) {
color: rgb(var(--m3-scheme-on-secondary-container));
}
</style>
21 changes: 15 additions & 6 deletions src/lib/components/panel/PanelShell.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,13 @@
import { resolve } from '$app/paths';
import type { Snippet } from 'svelte';
import PanelHeader, { type PanelNavigationItem } from './PanelHeader.svelte';
import iconCalendar from '@ktibow/iconset-material-symbols/calendar-month';
import iconSettings from '@ktibow/iconset-material-symbols/settings-outline';
import iconHelp from '@ktibow/iconset-material-symbols/help-outline';

let {
title,
mode,
tab,
tabs,
view,
Expand All @@ -16,6 +20,7 @@
class: className = ''
}: {
title: string;
mode: string;
tab: string;
tabs: PanelNavigationItem[];
view?: string;
Expand All @@ -26,25 +31,29 @@
class?: string;
} = $props();

const workspaceTabs = [
{ name: 'Calendar', value: 'calendar', onselect: () => void goto(resolve('/calendar')) },
{ name: 'Friends', value: 'friends', onselect: () => void goto(resolve('/friends')) }
const modes = [
{
name: 'Calendar',
value: 'calendar',
icon: iconCalendar,
onselect: () => void goto(resolve('/calendar'))
}
];
const utilities = [
{
name: 'Settings',
value: 'settings',
icon: iconSettings,
onselect: () => void goto(resolve('/settings'))
},
{ name: 'Help', value: 'help', onselect: () => void goto(resolve('/help')) }
{ name: 'Help', value: 'help', icon: iconHelp, onselect: () => void goto(resolve('/help')) }
];
const navigationTabs = $derived([...(tabs.length ? tabs : workspaceTabs), ...utilities]);
</script>

<div
class="{className} min-w-0 gap-3 p-3 text-on-surface @max-[20rem]:p-2 [&_h2]:text-lg [&_h2]:font-semibold [&_h3]:font-semibold [&_h4]:font-semibold @container flex w-full flex-col"
>
<PanelHeader {title} {tab} tabs={navigationTabs} {view} {prepareHref} {tabActions}>
<PanelHeader {title} {mode} {modes} {tab} {tabs} {utilities} {view} {prepareHref} {tabActions}>
{@render headerContent?.()}
</PanelHeader>
{@render children()}
Expand Down
1 change: 1 addition & 0 deletions src/routes/(panel)/(calendar)/+layout.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@
{#if !restoring}
<PanelShell
title={activeTab === 'friends' ? 'Friends' : 'Your Calendar'}
mode="calendar"
tab={activeTab}
{tabs}
class="friends-preview"
Expand Down
9 changes: 7 additions & 2 deletions src/routes/(panel)/(utilities)/+layout.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,16 @@
});
</script>

<PanelShell title={settings ? 'Settings' : 'Help'} tab={settings ? 'settings' : 'help'} tabs={[]}>
<PanelShell
title={settings ? 'Settings' : 'Help'}
mode=""
tab={settings ? 'settings' : 'help'}
tabs={[]}
>
{#snippet headerContent()}
<div class="border-outline-variant bg-surface-container-high px-4 py-3 border-t">
<h2 class="m-0 text-sm font-bold text-on-surface">
{settings ? 'Calendar preferences' : 'Information'}
{settings ? 'Preferences' : 'Information'}
</h2>
<p class="m-0 mt-0.5 text-xs text-on-surface-variant">
{settings
Expand Down
8 changes: 6 additions & 2 deletions tests/ui/academic-profile.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { test, expect } from './extension.fixture';
import { lookupAcademicProfile, STUDENT_PROFILE_URL } from '../../src/lib/calendar/academicProfile';
import { STUDENT_GRADES_URL } from '../../src/lib/calendar/courseOutcomes';
import { chooseRadio, fitsViewport } from './helpers';
import { fitsViewport } from './helpers';
import { origin } from './backend';

test('backfill flags load once across panel navigation and reload for a changed session', async ({
Expand All @@ -12,7 +12,11 @@ test('backfill flags load once across panel navigation and reload for a changed
await expect
.poll(() => network.filter((row) => row.path === '/api/user/backfills').length)
.toBe(1);
await chooseRadio(page, 'Settings');
await page.getByRole('button', { name: 'Open navigation', exact: true }).click();
await page
.getByRole('navigation', { name: 'Application navigation' })
.getByRole('button', { name: 'Settings', exact: true })
.click();
await expect(page.getByText(/primary@example.invalid/)).toBeVisible();
expect(network.filter((row) => row.path === '/api/user/backfills')).toHaveLength(1);
await worker.evaluate(async () => {
Expand Down
12 changes: 10 additions & 2 deletions tests/ui/calendar.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,11 @@ test('a queued current term is polled without opening LeopardWeb', async ({ exte
await expect
.poll(() => extension.network.filter((row) => row.totalMs === undefined))
.toHaveLength(0);
await chooseRadio(page, 'Settings');
await page.getByRole('button', { name: 'Open navigation', exact: true }).click();
await page
.getByRole('navigation', { name: 'Application navigation' })
.getByRole('button', { name: 'Settings', exact: true })
.click();
await expect(page.getByText(/primary@example.invalid/)).toBeVisible();
const response = page.waitForResponse(endpoint);
release();
Expand All @@ -44,7 +48,11 @@ test('a queued current term is polled without opening LeopardWeb', async ({ exte
false
);
ready = true;
await chooseRadio(page, 'Calendar');
await page.getByRole('button', { name: 'Open navigation', exact: true }).click();
await page
.getByRole('navigation', { name: 'Application navigation' })
.getByRole('button', { name: 'Calendar', exact: true })
.click();
await expect(page.getByRole('button', { name: /Algorithms Test/ }).first()).toBeVisible();
await expect(page.getByRole('status').filter({ hasText: 'Loading your calendar…' })).toHaveCount(
0
Expand Down
6 changes: 5 additions & 1 deletion tests/ui/live.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,11 @@ test('isolated staging session loads Calendar, Friends and Settings', async ({ e
const picker = page.getByRole('dialog', { name: 'Select people' });
await expect.poll(() => picker.getByRole('checkbox').count()).toBeGreaterThanOrEqual(4);
await picker.getByRole('button', { name: 'Close', exact: true }).click();
await chooseRadio(page, 'Settings');
await page.getByRole('button', { name: 'Open navigation', exact: true }).click();
await page
.getByRole('navigation', { name: 'Application navigation' })
.getByRole('button', { name: 'Settings', exact: true })
.click();
await expect(page.getByRole('heading', { name: 'Connected Google accounts' })).toBeVisible();
await expect(
page.getByText(`Signed in as ${process.env.WIT_LIVE_EXPECTED_EMAIL}`, { exact: true })
Expand Down
55 changes: 44 additions & 11 deletions tests/ui/settings-management.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,20 +96,49 @@ test('legacy routes and navigation reach Settings without changing values', asyn
return transition;
};
});
await chooseRadio(page, 'Calendar');
await expect(page.getByRole('button', { name: 'Open navigation', exact: true })).toHaveCount(0);
for (const width of [320, 1280]) {
await page.getByRole('button', { name: 'Open navigation', exact: true }).click();
await page
.getByRole('navigation', { name: 'Application navigation' })
.getByRole('button', { name: 'Calendar', exact: true })
.click();
const navigation = page.getByRole('navigation', { name: 'Application navigation' });
const openNavigation = page.getByRole('button', { name: 'Open navigation', exact: true });
await expect(page.getByRole('radio', { name: 'Settings', exact: true })).toHaveCount(0);
await expect(page.getByRole('radio', { name: 'Help', exact: true })).toHaveCount(0);
for (const width of [320, 480, 1280]) {
await page.setViewportSize({ width, height: 900 });
for (const name of ['Calendar', 'Friends', 'Settings', 'Help']) {
await expect(page.getByRole('radio', { name, exact: true })).toHaveCount(1);
}
await fitsViewport(page);
await openNavigation.click();
await fitsViewport(page, navigation);
await expect(navigation.getByRole('button')).toHaveText(['Calendar', 'Settings', 'Help']);
await expect(navigation.locator('[aria-current="true"]')).toHaveText('Calendar');
await page.keyboard.press('Escape');
await expect(navigation).toBeHidden();
await expect(openNavigation).toBeFocused();
}
await openNavigation.click();
await navigation.getByRole('button', { name: 'Help', exact: true }).click();
await expect(page.getByRole('heading', { name: 'Help', exact: true })).toBeVisible();
await expect(page).toHaveURL(/\/help(?:\.html)?$/);
await expect(navigation).toBeHidden();
await openNavigation.click();
await expect(navigation.locator('[aria-current="page"]')).toHaveText('Help');
await navigation.getByRole('button', { name: 'Calendar', exact: true }).click();
await chooseRadio(page, 'Friends');
await expect(page.getByRole('heading', { name: 'Friends', exact: true })).toBeVisible();
await chooseRadio(page, 'Settings');
await openNavigation.click();
await expect(navigation.locator('[aria-current="true"]')).toHaveText('Calendar');
await page.setViewportSize({ width: 320, height: 900 });
await fitsViewport(page, navigation);
await navigation.getByRole('button', { name: 'Calendar', exact: true }).click();
await expect(page.getByRole('heading', { name: 'Your Calendar', exact: true })).toBeVisible();
await expect(page.getByRole('radio', { name: 'Calendar', exact: true })).toBeChecked();
await chooseRadio(page, 'Friends');
await openNavigation.click();
await navigation.getByRole('button', { name: 'Settings', exact: true }).click();
await expect(page).toHaveURL(/\/settings(?:\.html)?$/);
await expect(page.getByRole('radio', { name: 'Settings', exact: true })).toBeChecked();
await expect(navigation).toBeHidden();
await openNavigation.click();
await expect(navigation.locator('[aria-current="page"]')).toHaveText('Settings');
await page.keyboard.press('Escape');
await expect(page.getByText(/primary@example.invalid/)).toBeVisible();
await expect
.poll(() => network.some((row) => row.path === '/api/calendar_preferences'))
Expand All @@ -128,7 +157,11 @@ test('legacy routes and navigation reach Settings without changing values', asyn
await fitsViewport(page);
await expect.poll(values).toEqual(before);
}
await chooseRadio(page, 'Calendar');
await page.getByRole('button', { name: 'Open navigation', exact: true }).click();
await page
.getByRole('navigation', { name: 'Application navigation' })
.getByRole('button', { name: 'Calendar', exact: true })
.click();
await expect(page.getByRole('heading', { name: 'Your Calendar', exact: true })).toBeVisible();
await chooseRadio(page, 'Friends');
await expect(page.getByRole('heading', { name: 'Friends', exact: true })).toBeVisible();
Expand Down
Loading