design: use commonlist in sidebars

This commit is contained in:
James Xylight committed 2025-08-20 20:48:50 -07:00
1 parent bf0d4cf238
commit 9e9fc326b8
9 files changed
+216 -69

No files matched your search

+113
View File
@@ -0,0 +1,113 @@
# CLAUDE.md
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
## Project Overview
Photon is a Svelte-based Lemmy client built with SvelteKit 2 and Svelte 5. It's a modern frontend for Lemmy instances with extensive customization options and multi-platform support.
### Key Technologies
- **Frontend**: SvelteKit 2 + Svelte 5 with TypeScript
- **Styling**: TailwindCSS v4 + PostCSS
- **Desktop App**: Tauri (optional, in src-tauri/)
- **Package Manager**: Bun (primary) or npm
- **Build Adapters**: Supports Bun, Node, and static builds
## Development Commands
### Development
```bash
# Start development server
bun run dev
# or
npm run dev
```
### Building
```bash
# Build for Bun runtime (fastest)
ADAPTER=bun bun run build
# Build for Node runtime (better compatibility)
ADAPTER=node npm run build
# Build static files
ADAPTER=static npm run build
```
### Code Quality
```bash
# Type checking
bun run check
# or watch mode
bun run check:watch
# Linting
bun run lint
# Formatting
bun run format
# or specific files
bun run format:specific <file>
```
### Running Built Application
```bash
# Start Bun server
bun run bunstart
# Start Node server
bun run start
```
### Testing
The project uses Vitest as configured in package.json, but no test files currently exist:
```bash
bun run test
```
## Architecture
### Core Structure
- **Routes**: SvelteKit file-based routing in `src/routes/`
- **Components**: Organized by domain in `src/lib/components/`
- `lemmy/`: Lemmy-specific components (posts, comments, communities)
- `ui/`: Generic UI components
- `mono/`: Design system components (imported as 'mono-svelte')
- **State Management**: Svelte 5 runes with custom stores for global state
- **Internationalization**: Custom i18n system in `src/lib/i18n/`
### Key Global State
- **Authentication**: `src/lib/auth.svelte.ts` - Profile and user management
- **Settings**: `src/lib/settings.svelte.ts` - User preferences and configuration
- **Lemmy Client**: `src/lib/lemmy.svelte.ts` - API client and site data
- **Instance**: `src/lib/instance.svelte.ts` - Instance URL management
### Component Organization
- **Lemmy Domain**: Components for posts, comments, communities, moderation
- **UI Components**: Reusable interface elements with design system
- **Layout**: Shell, navbar, sidebar structure
- **Form Components**: Input controls with consistent styling
### Environment Configuration
Photon uses PUBLIC_ prefixed environment variables for client-side configuration. Default values are defined in `src/lib/settings.svelte.ts`. Key configuration includes:
- `PUBLIC_INSTANCE_URL`: Default Lemmy instance
- `PUBLIC_SSR_ENABLED`: Server-side rendering toggle
- `PUBLIC_LOCK_TO_INSTANCE`: Whether to allow instance switching
### Multi-Platform Support
- **Web**: Primary SvelteKit application
- **Desktop**: Optional Tauri wrapper in `src-tauri/` for native desktop app
- **Mobile**: PWA capabilities with responsive design
### Build System
- **Vite**: Primary build tool with SvelteKit integration
- **Adapters**: Dynamic adapter selection via ADAPTER environment variable
- **Aliases**: 'mono-svelte' points to internal design system at `src/lib/mono`
### State Patterns
The codebase uses Svelte 5 runes extensively:
- `$state()` for reactive state
- `$derived()` for computed values
- `$effect()` for side effects
- Custom classes with reactive properties for complex state management
@@ -44,8 +44,8 @@
onedit,
onhide,
}: Props = $props()
let buttonHeight = $derived(view == 'compact' ? 'h-7' : 'h-8')
let buttonSquare = $derived(view == 'compact' ? 'w-7 h-7' : 'w-8 h-8')
let buttonHeight = $derived(view == 'compact' ? 'h-7.5' : 'h-8')
let buttonSquare = $derived(view == 'compact' ? 'w-7.5 h-7.5' : 'w-8 h-8')
</script>
{#if editing}
@@ -39,23 +39,6 @@
let { post, onhide, editing = $bindable() }: Props = $props()
</script>
<MenuDivider>{$t('post.actions.more.creator')}</MenuDivider>
<MenuButton link href={userLink(post.creator)}>
{#snippet prefix()}
<Icon src={UserCircle} size="16" micro class="shrink-0" />
{/snippet}
<TextProps wrap="no-wrap">
{post.creator.name}
</TextProps>
</MenuButton>
<MenuButton link href={communityLink(post.community)}>
{#snippet prefix()}
<Icon src={Newspaper} size="16" micro class="shrink-0" />
{/snippet}
<TextProps wrap="no-wrap">
{post.community.title}
</TextProps>
</MenuButton>
<MenuDivider>
{$t('post.actions.more.actions')}
</MenuDivider>
+5 -5
View File
@@ -34,15 +34,15 @@
{@render title?.(open)}
</div>
{#if icon}
<Icon
src={open ? Minus : Plus}
size="16"
micro
<div
class={[
'ml-auto ',
!open && 'rotate-90',
'transition-transform duration-300 ease-out',
]}
/>
>
<Icon src={open ? Minus : Plus} size="16" micro class={[]} />
</div>
{/if}
<div
class="inset-0 -z-10 opacity-0 absolute bg-slate-200 dark:bg-zinc-900 rounded-full
+46 -10
View File
@@ -1,10 +1,12 @@
<script lang="ts" generics="T">
import type { Snippet } from 'svelte'
import type { ClassValue } from 'svelte/elements'
const sizeDelay: Record<'lg' | 'md' | 'sm', number> = {
const sizeDelay: Record<'lg' | 'md' | 'sm' | 'xs', number> = {
lg: 120,
md: 80,
sm: 40,
xs: 0,
}
interface Props {
@@ -12,7 +14,9 @@
item?: Snippet<[T, number]>
children?: Snippet
animate?: boolean
size?: 'lg' | 'md' | 'sm'
size?: 'lg' | 'md' | 'sm' | 'xs'
class?: ClassValue
selected?: (item: T) => boolean
}
let {
@@ -21,6 +25,8 @@
children,
animate = true,
size = 'sm',
class: clazz,
selected,
}: Props = $props()
</script>
@@ -28,7 +34,13 @@
{#if items}
{#each items as item, index (item)}
<li
class={['group/li', animate && 'animate']}
class={[
'group/li',
animate && 'animate',
size == 'xs' && 'xs',
selected?.(item) && 'selected',
clazz,
]}
style="--i: {index < 10 ? index * sizeDelay[size] : 0}ms;"
>
{@render itemSnippet?.(item, index)}
@@ -40,8 +52,6 @@
<style>
ul > :global(li) {
padding-block: calc(var(--spacing) * 3);
padding-inline: calc(var(--spacing) * 3.5);
transition: background-color 0.1s;
background-color: var(--color-white);
container-type: inline-size;
@@ -60,13 +70,39 @@
&:hover {
background-color: var(--color-slate-25);
}
&:not(.xs) {
padding-block: calc(var(--spacing) * 3);
padding-inline: calc(var(--spacing) * 3.5);
}
@media screen and (min-width: 40rem) {
&:not(.xs) {
padding-block: calc(var(--spacing) * 3);
padding-inline: calc(var(--spacing) * 4);
}
}
.xs {
padding-block: calc(var(--spacing) * 0.5);
padding-block: calc(var(--spacing) * 1);
}
}
@media screen and (min-width: 40rem) {
ul > :global(li) {
padding-block: calc(var(--spacing) * 3);
padding-inline: calc(var(--spacing) * 4);
}
ul > :global(li).selected {
background-color: color-mix(
in oklab,
var(--color-white),
var(--color-slate-100)
);
}
:global(.dark) ul > :global(li).selected {
background-color: color-mix(
in oklab,
var(--color-zinc-925),
var(--color-zinc-800)
);
}
:global(.dark) ul > :global(li) {
@@ -54,7 +54,7 @@
{#snippet prefix()}
<div class={(icon || customIcon) && adaptive ? 'lg:hidden' : ''}>
{#if icon}
<Icon src={icon} size="20" />
<Icon src={icon} size="20" mini />
{:else}
{@render customIcon?.({ size: 16, isSelected })}
{/if}
+46 -31
View File
@@ -18,6 +18,9 @@
} from 'svelte-hero-icons'
import EndPlaceholder from '../EndPlaceholder.svelte'
import type { ClassValue } from 'svelte/elements'
import CommonList from '../layout/CommonList.svelte'
import { communityLink } from '$lib/lemmy/generic'
import Avatar from '../Avatar.svelte'
interface Props {
style?: string
@@ -104,40 +107,24 @@
</EndPlaceholder>
</span>
{/snippet}
<div class="w-full flex gap-px flex-col">
{#each [...profile.meta.profiles] as prof, index}
<div class="w-full">
<ProfileButton {index} {prof} />
</div>
{/each}
</div>
<CommonList
size="xs"
animate={false}
items={profile.meta.profiles}
class="px-1 py-0.5"
selected={prof => prof.id == profile.meta.profile}
>
{#snippet item(prof, index)}
<ProfileButton {index} {prof} />
{/snippet}
</CommonList>
<div class="my-2"></div>
<SidebarButton href="/accounts" icon={UserGroup}>
{$t('account.accounts')}
</SidebarButton>
</Expandable>
{/if}
<hr class="border-slate-200 dark:border-zinc-900 my-1" />
{#if profile.current?.favorites && profile.current?.favorites.length > 0}
<Expandable
class="max-w-full min-w-0 w-full"
bind:open={settings.expand.favorites}
>
{#snippet title()}
<span class="px-2 py-1 w-full">
<EndPlaceholder>
{$t('routes.profile.favorites')}
{#snippet action()}
<span class="dark:text-white text-black">
{profile.current.favorites?.length}
</span>
{/snippet}
</EndPlaceholder>
</span>
{/snippet}
<CommunityList isFavorites items={profile.current.favorites} />
</Expandable>
<hr class="border-slate-200 dark:border-zinc-900 my-1" />
{/if}
{#if profile.current?.user}
{#if profile.current?.user.moderates.length > 0}
<Expandable
@@ -179,9 +166,37 @@
</EndPlaceholder>
</span>
{/snippet}
<CommunityList
items={profile.current.user.follows.map(i => i.community)}
/>
<CommonList
animate={false}
size="xs"
items={profile.current.user.follows}
class="px-1 py-0.5"
>
{#snippet item(follow)}
<SidebarButton
class="font-normal w-full h-max"
color="none"
alignment="left"
href={communityLink(follow.community)}
>
{#snippet customIcon()}
<Avatar
url={follow.community.icon}
alt={follow.community.name}
title={follow.community.title}
width={28}
/>{/snippet}
{#snippet label()}
<div class="flex flex-col max-w-full break-words">
<span>{follow.community.title}</span>
<span class="text-xs text-slate-600 dark:text-zinc-400">
{new URL(follow.community.actor_id).hostname}
</span>
</div>
{/snippet}
</SidebarButton>
{/snippet}
</CommonList>
</Expandable>
{/if}
</nav>
@@ -46,7 +46,7 @@
{#if customIcon}
{@render customIcon({ selected })}
{:else if icon}
<Icon src={icon} solid={selected} size="20" />
<Icon src={icon} solid size="20" />
{/if}
{/snippet}
{@render children?.()}
+2 -2
View File
@@ -125,12 +125,12 @@
{...rest}
tabindex={disabled ? -1 : undefined}
class={[
loading ? buttonColor.secondary : buttonColor[color],
buttonSize[size],
buttonRounding[rounding],
buttonShadow[shadow],
buttonColor[color],
'text-sm transition-all font-medium cursor-pointer duration-75 disabled:opacity-50 disabled:pointer-events-none disabled:shadow-none',
disabled && 'pointer-events-none opacity-50 shadow-none',
(disabled || loading) && 'pointer-events-none opacity-50 shadow-none',
alignment == 'center'
? 'origin-center'
: alignment == 'left'