design: use commonlist in sidebars
This commit is contained in:
9 files changed
+211
-64
No files matched your search
@@ -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,
|
onedit,
|
||||||
onhide,
|
onhide,
|
||||||
}: Props = $props()
|
}: Props = $props()
|
||||||
let buttonHeight = $derived(view == 'compact' ? 'h-7' : 'h-8')
|
let buttonHeight = $derived(view == 'compact' ? 'h-7.5' : 'h-8')
|
||||||
let buttonSquare = $derived(view == 'compact' ? 'w-7 h-7' : 'w-8 h-8')
|
let buttonSquare = $derived(view == 'compact' ? 'w-7.5 h-7.5' : 'w-8 h-8')
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
{#if editing}
|
{#if editing}
|
||||||
|
|||||||
@@ -39,23 +39,6 @@
|
|||||||
let { post, onhide, editing = $bindable() }: Props = $props()
|
let { post, onhide, editing = $bindable() }: Props = $props()
|
||||||
</script>
|
</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>
|
<MenuDivider>
|
||||||
{$t('post.actions.more.actions')}
|
{$t('post.actions.more.actions')}
|
||||||
</MenuDivider>
|
</MenuDivider>
|
||||||
|
|||||||
@@ -34,15 +34,15 @@
|
|||||||
{@render title?.(open)}
|
{@render title?.(open)}
|
||||||
</div>
|
</div>
|
||||||
{#if icon}
|
{#if icon}
|
||||||
<Icon
|
<div
|
||||||
src={open ? Minus : Plus}
|
|
||||||
size="16"
|
|
||||||
micro
|
|
||||||
class={[
|
class={[
|
||||||
|
'ml-auto ',
|
||||||
!open && 'rotate-90',
|
!open && 'rotate-90',
|
||||||
'transition-transform duration-300 ease-out',
|
'transition-transform duration-300 ease-out',
|
||||||
]}
|
]}
|
||||||
/>
|
>
|
||||||
|
<Icon src={open ? Minus : Plus} size="16" micro class={[]} />
|
||||||
|
</div>
|
||||||
{/if}
|
{/if}
|
||||||
<div
|
<div
|
||||||
class="inset-0 -z-10 opacity-0 absolute bg-slate-200 dark:bg-zinc-900 rounded-full
|
class="inset-0 -z-10 opacity-0 absolute bg-slate-200 dark:bg-zinc-900 rounded-full
|
||||||
|
|||||||
@@ -1,10 +1,12 @@
|
|||||||
<script lang="ts" generics="T">
|
<script lang="ts" generics="T">
|
||||||
import type { Snippet } from 'svelte'
|
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,
|
lg: 120,
|
||||||
md: 80,
|
md: 80,
|
||||||
sm: 40,
|
sm: 40,
|
||||||
|
xs: 0,
|
||||||
}
|
}
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
@@ -12,7 +14,9 @@
|
|||||||
item?: Snippet<[T, number]>
|
item?: Snippet<[T, number]>
|
||||||
children?: Snippet
|
children?: Snippet
|
||||||
animate?: boolean
|
animate?: boolean
|
||||||
size?: 'lg' | 'md' | 'sm'
|
size?: 'lg' | 'md' | 'sm' | 'xs'
|
||||||
|
class?: ClassValue
|
||||||
|
selected?: (item: T) => boolean
|
||||||
}
|
}
|
||||||
|
|
||||||
let {
|
let {
|
||||||
@@ -21,6 +25,8 @@
|
|||||||
children,
|
children,
|
||||||
animate = true,
|
animate = true,
|
||||||
size = 'sm',
|
size = 'sm',
|
||||||
|
class: clazz,
|
||||||
|
selected,
|
||||||
}: Props = $props()
|
}: Props = $props()
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
@@ -28,7 +34,13 @@
|
|||||||
{#if items}
|
{#if items}
|
||||||
{#each items as item, index (item)}
|
{#each items as item, index (item)}
|
||||||
<li
|
<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;"
|
style="--i: {index < 10 ? index * sizeDelay[size] : 0}ms;"
|
||||||
>
|
>
|
||||||
{@render itemSnippet?.(item, index)}
|
{@render itemSnippet?.(item, index)}
|
||||||
@@ -40,8 +52,6 @@
|
|||||||
|
|
||||||
<style>
|
<style>
|
||||||
ul > :global(li) {
|
ul > :global(li) {
|
||||||
padding-block: calc(var(--spacing) * 3);
|
|
||||||
padding-inline: calc(var(--spacing) * 3.5);
|
|
||||||
transition: background-color 0.1s;
|
transition: background-color 0.1s;
|
||||||
background-color: var(--color-white);
|
background-color: var(--color-white);
|
||||||
container-type: inline-size;
|
container-type: inline-size;
|
||||||
@@ -60,15 +70,41 @@
|
|||||||
&:hover {
|
&:hover {
|
||||||
background-color: var(--color-slate-25);
|
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) {
|
@media screen and (min-width: 40rem) {
|
||||||
ul > :global(li) {
|
&:not(.xs) {
|
||||||
padding-block: calc(var(--spacing) * 3);
|
padding-block: calc(var(--spacing) * 3);
|
||||||
padding-inline: calc(var(--spacing) * 4);
|
padding-inline: calc(var(--spacing) * 4);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.xs {
|
||||||
|
padding-block: calc(var(--spacing) * 0.5);
|
||||||
|
padding-block: calc(var(--spacing) * 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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) {
|
:global(.dark) ul > :global(li) {
|
||||||
background-color: color-mix(
|
background-color: color-mix(
|
||||||
in oklab,
|
in oklab,
|
||||||
|
|||||||
@@ -54,7 +54,7 @@
|
|||||||
{#snippet prefix()}
|
{#snippet prefix()}
|
||||||
<div class={(icon || customIcon) && adaptive ? 'lg:hidden' : ''}>
|
<div class={(icon || customIcon) && adaptive ? 'lg:hidden' : ''}>
|
||||||
{#if icon}
|
{#if icon}
|
||||||
<Icon src={icon} size="20" />
|
<Icon src={icon} size="20" mini />
|
||||||
{:else}
|
{:else}
|
||||||
{@render customIcon?.({ size: 16, isSelected })}
|
{@render customIcon?.({ size: 16, isSelected })}
|
||||||
{/if}
|
{/if}
|
||||||
|
|||||||
@@ -18,6 +18,9 @@
|
|||||||
} from 'svelte-hero-icons'
|
} from 'svelte-hero-icons'
|
||||||
import EndPlaceholder from '../EndPlaceholder.svelte'
|
import EndPlaceholder from '../EndPlaceholder.svelte'
|
||||||
import type { ClassValue } from 'svelte/elements'
|
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 {
|
interface Props {
|
||||||
style?: string
|
style?: string
|
||||||
@@ -104,40 +107,24 @@
|
|||||||
</EndPlaceholder>
|
</EndPlaceholder>
|
||||||
</span>
|
</span>
|
||||||
{/snippet}
|
{/snippet}
|
||||||
<div class="w-full flex gap-px flex-col">
|
<CommonList
|
||||||
{#each [...profile.meta.profiles] as prof, index}
|
size="xs"
|
||||||
<div class="w-full">
|
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} />
|
<ProfileButton {index} {prof} />
|
||||||
</div>
|
{/snippet}
|
||||||
{/each}
|
</CommonList>
|
||||||
</div>
|
<div class="my-2"></div>
|
||||||
<SidebarButton href="/accounts" icon={UserGroup}>
|
<SidebarButton href="/accounts" icon={UserGroup}>
|
||||||
{$t('account.accounts')}
|
{$t('account.accounts')}
|
||||||
</SidebarButton>
|
</SidebarButton>
|
||||||
</Expandable>
|
</Expandable>
|
||||||
{/if}
|
{/if}
|
||||||
<hr class="border-slate-200 dark:border-zinc-900 my-1" />
|
<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}
|
||||||
{#if profile.current?.user.moderates.length > 0}
|
{#if profile.current?.user.moderates.length > 0}
|
||||||
<Expandable
|
<Expandable
|
||||||
@@ -179,9 +166,37 @@
|
|||||||
</EndPlaceholder>
|
</EndPlaceholder>
|
||||||
</span>
|
</span>
|
||||||
{/snippet}
|
{/snippet}
|
||||||
<CommunityList
|
<CommonList
|
||||||
items={profile.current.user.follows.map(i => i.community)}
|
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>
|
</Expandable>
|
||||||
{/if}
|
{/if}
|
||||||
</nav>
|
</nav>
|
||||||
@@ -46,7 +46,7 @@
|
|||||||
{#if customIcon}
|
{#if customIcon}
|
||||||
{@render customIcon({ selected })}
|
{@render customIcon({ selected })}
|
||||||
{:else if icon}
|
{:else if icon}
|
||||||
<Icon src={icon} solid={selected} size="20" />
|
<Icon src={icon} solid size="20" />
|
||||||
{/if}
|
{/if}
|
||||||
{/snippet}
|
{/snippet}
|
||||||
{@render children?.()}
|
{@render children?.()}
|
||||||
|
|||||||
@@ -125,12 +125,12 @@
|
|||||||
{...rest}
|
{...rest}
|
||||||
tabindex={disabled ? -1 : undefined}
|
tabindex={disabled ? -1 : undefined}
|
||||||
class={[
|
class={[
|
||||||
loading ? buttonColor.secondary : buttonColor[color],
|
|
||||||
buttonSize[size],
|
buttonSize[size],
|
||||||
buttonRounding[rounding],
|
buttonRounding[rounding],
|
||||||
buttonShadow[shadow],
|
buttonShadow[shadow],
|
||||||
|
buttonColor[color],
|
||||||
'text-sm transition-all font-medium cursor-pointer duration-75 disabled:opacity-50 disabled:pointer-events-none disabled:shadow-none',
|
'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'
|
alignment == 'center'
|
||||||
? 'origin-center'
|
? 'origin-center'
|
||||||
: alignment == 'left'
|
: alignment == 'left'
|
||||||
|
|||||||
Reference in new issue
Block a user