Merge pull request #364 from Xyphyn/command-palette
feat: add a command palette
This commit is contained in:
14 files changed
+837
-6
No files matched your search
@@ -17,6 +17,7 @@
|
||||
color="tertiary"
|
||||
{...$$restProps}
|
||||
on:click
|
||||
on:contextmenu
|
||||
class="rounded-full w-10 h-10 flex-shrink-0 {isSelected
|
||||
? 'bg-slate-200 dark:bg-zinc-900 text-primary-900 dark:!text-primary-100'
|
||||
: ''} {$$props.class ?? ''}"
|
||||
|
||||
@@ -38,10 +38,13 @@
|
||||
import { LINKED_INSTANCE_URL } from '$lib/instance'
|
||||
import SiteCard from '$lib/components/lemmy/SiteCard.svelte'
|
||||
import { t } from '$lib/translations'
|
||||
import CommandsWrapper from './commands/CommandsWrapper.svelte'
|
||||
|
||||
let searching = false
|
||||
let promptOpen: boolean = false
|
||||
</script>
|
||||
|
||||
<CommandsWrapper bind:open={promptOpen} />
|
||||
<nav
|
||||
class="flex flex-row gap-2 items-center w-full mx-auto z-50 box-border p-0.5
|
||||
duration-150
|
||||
@@ -49,7 +52,16 @@
|
||||
"
|
||||
style={$$props.style}
|
||||
>
|
||||
<NavButton href="/" label={$t('nav.home')} class="ml-2 logo">
|
||||
<NavButton
|
||||
on:contextmenu={(e) => {
|
||||
e.preventDefault()
|
||||
promptOpen = true
|
||||
return true
|
||||
}}
|
||||
href="/"
|
||||
label={$t('nav.home')}
|
||||
class="ml-2 logo"
|
||||
>
|
||||
<svelte:fragment slot="icon">
|
||||
{#if LINKED_INSTANCE_URL}
|
||||
{#if $site}
|
||||
|
||||
@@ -0,0 +1,40 @@
|
||||
<script lang="ts">
|
||||
import { Button, Material } from 'mono-svelte'
|
||||
import {
|
||||
ArrowUturnDown,
|
||||
Icon,
|
||||
QuestionMarkCircle,
|
||||
type IconSource,
|
||||
} from 'svelte-hero-icons'
|
||||
import Avatar from '../../Avatar.svelte'
|
||||
import type { Action } from './actions'
|
||||
|
||||
export let action: Action
|
||||
</script>
|
||||
|
||||
<Button
|
||||
href={action.href}
|
||||
on:click
|
||||
alignment="left"
|
||||
color="tertiary"
|
||||
size="lg"
|
||||
class="focus:bg-slate-200 focus:dark:bg-zinc-800 block w-full {$$props.class}"
|
||||
data-sveltekit-preload-code="viewport"
|
||||
data-sveltekit-preload-data="tap"
|
||||
>
|
||||
{#if typeof action.icon === 'string'}
|
||||
<Avatar url={action.icon} width={20} />
|
||||
{:else}
|
||||
<Icon src={action.icon ?? QuestionMarkCircle} size="20" />
|
||||
{/if}
|
||||
<slot />
|
||||
<span class="mr-auto">{action.name}</span>
|
||||
{#if action.shortcut}
|
||||
<div class="flex items-center gap-0.5 text-xs font-medium">
|
||||
⌘ {action.shortcut}
|
||||
</div>
|
||||
{/if}
|
||||
{#if action.subActions}
|
||||
<Icon src={ArrowUturnDown} size="16" micro />
|
||||
{/if}
|
||||
</Button>
|
||||
@@ -0,0 +1,288 @@
|
||||
<script lang="ts">
|
||||
import { resumables } from '$lib/lemmy/item'
|
||||
import { TextInput } from 'mono-svelte'
|
||||
import { createEventDispatcher, onMount } from 'svelte'
|
||||
import { Home, Icon, MagnifyingGlass } from 'svelte-hero-icons'
|
||||
import { t } from '$lib/translations'
|
||||
import CommandItem from './CommandItem.svelte'
|
||||
import { browser } from '$app/environment'
|
||||
import { afterNavigate, goto } from '$app/navigation'
|
||||
import { profile } from '$lib/auth'
|
||||
import { getGroups, type Action, type Group } from './actions'
|
||||
|
||||
export let open = false
|
||||
$: if (open) search = ''
|
||||
|
||||
export let groups: Group[] = []
|
||||
|
||||
$: groups = getGroups($resumables, $profile)
|
||||
|
||||
let search = ''
|
||||
let container: HTMLElement
|
||||
const dispatch = createEventDispatcher()
|
||||
let selectedIndex = 0
|
||||
let filteredGroups: Group[] = []
|
||||
let breadcrumbs: Action[] = []
|
||||
|
||||
function fuzzySearch(text: string, pattern: string): number {
|
||||
const textLower = text.toLowerCase()
|
||||
const patternLower = pattern.toLowerCase()
|
||||
let score = 0
|
||||
let lastIndex = -1
|
||||
let consecutiveBonus = 0
|
||||
|
||||
for (let i = 0; i < patternLower.length; i++) {
|
||||
const index = textLower.indexOf(patternLower[i], lastIndex + 1)
|
||||
if (index === -1) return 0
|
||||
|
||||
score += 1
|
||||
if (index === lastIndex + 1) {
|
||||
consecutiveBonus++
|
||||
score += consecutiveBonus
|
||||
} else {
|
||||
consecutiveBonus = 0
|
||||
}
|
||||
|
||||
lastIndex = index
|
||||
}
|
||||
|
||||
// Bonus for matching start of words
|
||||
if (textLower.startsWith(patternLower)) {
|
||||
score += 2
|
||||
} else if (textLower.includes(' ' + patternLower)) {
|
||||
score += 1
|
||||
}
|
||||
|
||||
return score
|
||||
}
|
||||
|
||||
const debounce = (fn: Function, ms = 300) => {
|
||||
let timeoutId: ReturnType<typeof setTimeout>
|
||||
return function (this: any, ...args: any[]) {
|
||||
clearTimeout(timeoutId)
|
||||
timeoutId = setTimeout(() => fn.apply(this, args), ms)
|
||||
}
|
||||
}
|
||||
|
||||
function searchGroup(term: string) {
|
||||
if (term.length < 1) {
|
||||
if (breadcrumbs.length <= 0) {
|
||||
filteredGroups = groups.map((group) => ({
|
||||
...group,
|
||||
actions: flattenActions(group.actions, false),
|
||||
}))
|
||||
}
|
||||
} else {
|
||||
filteredGroups = groups
|
||||
.map((group) => {
|
||||
const scoredActions = flattenActions(group.actions)
|
||||
.map((action) => ({
|
||||
...action,
|
||||
score: Math.max(
|
||||
fuzzySearch(action.name, term),
|
||||
fuzzySearch(group.name, term)
|
||||
),
|
||||
}))
|
||||
.filter((action) => action.score > 0)
|
||||
.sort((a, b) => b.score - a.score)
|
||||
|
||||
return {
|
||||
...group,
|
||||
actions: scoredActions,
|
||||
score: Math.max(
|
||||
fuzzySearch(group.name, term),
|
||||
...scoredActions.map((a) => a.score)
|
||||
),
|
||||
}
|
||||
})
|
||||
.filter((group) => group.actions.length > 0)
|
||||
.sort((a, b) => b.score - a.score)
|
||||
}
|
||||
}
|
||||
|
||||
const debouncedSearch = debounce((term: string) => searchGroup(term), 50)
|
||||
|
||||
function updateFilteredGroups() {
|
||||
if (breadcrumbs.length === 0) {
|
||||
filteredGroups = groups
|
||||
} else {
|
||||
const lastAction = breadcrumbs[breadcrumbs.length - 1]
|
||||
filteredGroups = [
|
||||
{
|
||||
name: lastAction.name,
|
||||
actions: lastAction.subActions || [],
|
||||
},
|
||||
]
|
||||
}
|
||||
selectedIndex = 0
|
||||
search = ''
|
||||
}
|
||||
|
||||
function goBack() {
|
||||
breadcrumbs.pop()
|
||||
updateFilteredGroups()
|
||||
}
|
||||
|
||||
$: flattenedActions = filteredGroups.flatMap((group) => group.actions)
|
||||
$: debouncedSearch(search)
|
||||
|
||||
function flattenActions(
|
||||
actions: Action[],
|
||||
subaction: boolean = true
|
||||
): Action[] {
|
||||
return actions.flatMap((action) => [
|
||||
action,
|
||||
...(action.subActions && subaction
|
||||
? flattenActions(action.subActions)
|
||||
: []),
|
||||
])
|
||||
}
|
||||
|
||||
function togglePalette() {
|
||||
open = !open
|
||||
if (open) {
|
||||
search = ''
|
||||
selectedIndex = 0
|
||||
filteredGroups = groups
|
||||
breadcrumbs = []
|
||||
}
|
||||
}
|
||||
|
||||
function handleKeydown(event: KeyboardEvent) {
|
||||
if (event.ctrlKey) {
|
||||
const actions = groups
|
||||
.flatMap((g) => g.actions)
|
||||
.filter((a) => a.shortcut != undefined)
|
||||
|
||||
actions.forEach((a) => {
|
||||
if (event.key === a.shortcut) {
|
||||
event.preventDefault()
|
||||
if (a.href) goto(a.href)
|
||||
if (a.handle) a.handle()
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
if (!open) return
|
||||
|
||||
switch (event.key) {
|
||||
case 'ArrowDown':
|
||||
event.preventDefault()
|
||||
selectedIndex = (selectedIndex + 1) % flattenedActions.length
|
||||
focusItem(selectedIndex)
|
||||
break
|
||||
case 'ArrowUp':
|
||||
event.preventDefault()
|
||||
selectedIndex =
|
||||
(selectedIndex - 1 + flattenedActions.length) %
|
||||
flattenedActions.length
|
||||
focusItem(selectedIndex)
|
||||
break
|
||||
case 'Enter':
|
||||
searchGroup(search)
|
||||
handleSelect(flattenedActions[selectedIndex])
|
||||
break
|
||||
case 'Escape':
|
||||
event.preventDefault()
|
||||
if (breadcrumbs.length > 0) {
|
||||
breadcrumbs.pop()
|
||||
updateFilteredGroups()
|
||||
} else {
|
||||
togglePalette()
|
||||
}
|
||||
break
|
||||
}
|
||||
|
||||
if (selectedIndex >= flattenedActions.length) selectedIndex = 0
|
||||
}
|
||||
|
||||
function focusItem(index: number) {
|
||||
if (!browser) return
|
||||
|
||||
const listItems = container?.querySelectorAll('li')
|
||||
listItems[index % listItems.length].focus()
|
||||
listItems[index % listItems.length].scrollIntoView({
|
||||
behavior: 'smooth',
|
||||
block: 'center',
|
||||
})
|
||||
}
|
||||
|
||||
async function handleSelect(action: Action) {
|
||||
if (!action) return
|
||||
if (action.subActions && action.subActions.length > 0) {
|
||||
breadcrumbs = [...breadcrumbs, action]
|
||||
updateFilteredGroups()
|
||||
} else {
|
||||
if (action.href) goto(action.href)
|
||||
if (action.handle) action.handle()
|
||||
togglePalette()
|
||||
dispatch('select', action)
|
||||
}
|
||||
}
|
||||
|
||||
afterNavigate(() => {
|
||||
// open = false
|
||||
})
|
||||
</script>
|
||||
|
||||
<svelte:window on:keydown={handleKeydown} />
|
||||
|
||||
<TextInput bind:value={search} autofocus class="sticky" />
|
||||
<div class="h-96 overflow-auto border-slate-200 dark:border-zinc-800">
|
||||
{#if breadcrumbs.length > 0}
|
||||
<div class="flex items-center gap-2 my-1">
|
||||
<button
|
||||
class="text-[13px] font-medium text-slate-600 dark:text-zinc-400"
|
||||
on:click={goBack}
|
||||
>
|
||||
<Icon src={Home} size="16" mini />
|
||||
</button>
|
||||
{#each breadcrumbs as crumb, index}
|
||||
<span class="text-base text-slate-400 dark:text-zinc-600">/</span>
|
||||
<span class="text-[13px] font-medium">
|
||||
{crumb.name}
|
||||
</span>
|
||||
{/each}
|
||||
</div>
|
||||
{/if}
|
||||
<div class="space-y-1" bind:this={container}>
|
||||
{#each filteredGroups as group, groupIndex}
|
||||
<div class="space-y-1">
|
||||
<span class="text-sm font-medium">{group.name}</span>
|
||||
<ul class="flex flex-col gap-1">
|
||||
{#each group.actions as action, actionIndex}
|
||||
{@const globalIndex =
|
||||
filteredGroups
|
||||
.slice(0, groupIndex)
|
||||
.reduce((sum, g) => sum + g.actions.length, 0) + actionIndex}
|
||||
<li>
|
||||
<CommandItem
|
||||
{action}
|
||||
on:click={(e) => {
|
||||
e.stopPropagation()
|
||||
handleSelect(action)
|
||||
}}
|
||||
class="{globalIndex == selectedIndex
|
||||
? '!bg-slate-100 dark:!bg-zinc-800 text-inherit'
|
||||
: 'text-slate-600 dark:text-zinc-400'} block"
|
||||
/>
|
||||
</li>
|
||||
{/each}
|
||||
</ul>
|
||||
</div>
|
||||
{/each}
|
||||
{#if search != ''}
|
||||
<CommandItem
|
||||
action={{
|
||||
name: search,
|
||||
href: `/search?q=${encodeURIComponent(search)}`,
|
||||
icon: MagnifyingGlass,
|
||||
}}
|
||||
>
|
||||
<span class="font-normal text-slate-600 dark:text-zinc-400">
|
||||
{$t('nav.commands.search', { default: '' })}
|
||||
</span>
|
||||
</CommandItem>
|
||||
{/if}
|
||||
</div>
|
||||
</div>
|
||||
@@ -0,0 +1,49 @@
|
||||
<script lang="ts">
|
||||
import { t } from '$lib/translations'
|
||||
import { Modal, Spinner } from 'mono-svelte'
|
||||
import Commands from './Commands.svelte'
|
||||
import { CommandLine, Icon } from 'svelte-hero-icons'
|
||||
|
||||
export let open: boolean = false
|
||||
|
||||
function handleKeydown(event: KeyboardEvent) {
|
||||
if (
|
||||
(event.ctrlKey && event.key === 'p') ||
|
||||
(event.key == '/' && document.activeElement == document.body)
|
||||
) {
|
||||
event.preventDefault()
|
||||
open = !open
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<svelte:window on:keydown={handleKeydown} />
|
||||
|
||||
{#if open}
|
||||
<Modal bind:open>
|
||||
<span slot="title" class="flex items-center gap-1">
|
||||
<svg
|
||||
width="24"
|
||||
height="24"
|
||||
fill="currentColor"
|
||||
viewBox="15 15 70 70"
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
>
|
||||
<path
|
||||
d="M45 20.8868C48.094 19.1004 51.906 19.1004 55 20.8868L72.7128 31.1132C75.8068 32.8996 77.7128 36.2008 77.7128 39.7735V60.2265C77.7128 63.7992 75.8068 67.1004 72.7128 68.8867L55 79.1133C51.906 80.8996 48.094 80.8996 45 79.1133L27.2872 68.8867C24.1932 67.1004 22.2872 63.7992 22.2872 60.2265V39.7735C22.2872 36.2008 24.1932 32.8996 27.2872 31.1132L45 20.8868Z"
|
||||
/>
|
||||
</svg>
|
||||
{$t('nav.commands.prompt')}
|
||||
</span>
|
||||
{#await import('./Commands.svelte')}
|
||||
<div class="h-96 flex flex-col gap-2 items-center justify-center">
|
||||
<Spinner width={32} />
|
||||
<span class="font-medium text-lg">
|
||||
{$t('nav.commands.downloading')}
|
||||
</span>
|
||||
</div>
|
||||
{:then { default: Commands }}
|
||||
<Commands bind:open />
|
||||
{/await}
|
||||
</Modal>
|
||||
{/if}
|
||||
@@ -0,0 +1,381 @@
|
||||
import type { Profile } from '$lib/auth'
|
||||
import {
|
||||
amModOfAny,
|
||||
isAdmin,
|
||||
} from '$lib/components/lemmy/moderation/moderation'
|
||||
import { resumables, type ResumableItem } from '$lib/lemmy/item'
|
||||
import { userSettings } from '$lib/settings'
|
||||
import { t } from '$lib/translations'
|
||||
import { legacyTheme } from '$lib/ui/colors'
|
||||
import { fullCommunityName } from '$lib/util'
|
||||
import {
|
||||
ArrowRightOnRectangle,
|
||||
Bookmark,
|
||||
Cog6Tooth,
|
||||
GlobeAlt,
|
||||
Home,
|
||||
Identification,
|
||||
Inbox,
|
||||
Newspaper,
|
||||
PencilSquare,
|
||||
ServerStack,
|
||||
ShieldCheck,
|
||||
UserCircle,
|
||||
UserGroup,
|
||||
ViewColumns,
|
||||
type IconSource,
|
||||
PaintBrush,
|
||||
ComputerDesktop,
|
||||
Sun,
|
||||
Moon,
|
||||
MapPin,
|
||||
GlobeAmericas,
|
||||
ChartBar,
|
||||
Trophy,
|
||||
ArrowTrendingUp,
|
||||
Fire,
|
||||
Scale,
|
||||
Star,
|
||||
Clock,
|
||||
ArrowTrendingDown,
|
||||
ChatBubbleOvalLeftEllipsis,
|
||||
ChatBubbleLeftRight,
|
||||
} from 'svelte-hero-icons'
|
||||
|
||||
export interface Group {
|
||||
name: string
|
||||
actions: Action[]
|
||||
}
|
||||
|
||||
export interface Action {
|
||||
name: string
|
||||
desc?: string
|
||||
handle?: () => any
|
||||
href?: string
|
||||
shortcut?: string
|
||||
icon: string | IconSource
|
||||
subActions?: Action[]
|
||||
}
|
||||
|
||||
export function getGroups(resumables: ResumableItem[], profile: Profile) {
|
||||
return [
|
||||
{
|
||||
name: t.get('nav.commands.recents'),
|
||||
actions: resumables.map((r) => ({
|
||||
name: r.name,
|
||||
icon: r.avatar ?? PencilSquare,
|
||||
href: r.url,
|
||||
})),
|
||||
},
|
||||
{
|
||||
name: t.get('nav.commands.main'),
|
||||
actions: [
|
||||
{ href: '/', name: t.get('nav.home'), icon: Home, shortcut: 'h' },
|
||||
{
|
||||
href: '/communities',
|
||||
name: t.get('nav.communities'),
|
||||
icon: GlobeAlt,
|
||||
},
|
||||
...(amModOfAny(profile.user)
|
||||
? [
|
||||
{
|
||||
href: '/moderation',
|
||||
name: t.get('nav.moderation'),
|
||||
icon: ShieldCheck,
|
||||
},
|
||||
]
|
||||
: []),
|
||||
...(profile.user && isAdmin(profile.user)
|
||||
? [
|
||||
{
|
||||
href: '/admin',
|
||||
name: t.get('nav.admin'),
|
||||
icon: ServerStack,
|
||||
},
|
||||
]
|
||||
: []),
|
||||
],
|
||||
},
|
||||
{
|
||||
name: t.get('nav.commands.feeds'),
|
||||
actions: [
|
||||
{
|
||||
name: t.get('filter.location.label'),
|
||||
icon: GlobeAmericas,
|
||||
subActions: [
|
||||
{
|
||||
name: t.get('filter.location.all'),
|
||||
icon: GlobeAmericas,
|
||||
href: '/?type=All',
|
||||
},
|
||||
{
|
||||
name: t.get('filter.location.local'),
|
||||
icon: MapPin,
|
||||
href: '/?type=Local',
|
||||
},
|
||||
{
|
||||
name: t.get('filter.location.subscribed'),
|
||||
icon: Newspaper,
|
||||
href: '/?type=Subscribed',
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
name: t.get('filter.sort.label'),
|
||||
icon: ChartBar,
|
||||
subActions: [
|
||||
{
|
||||
name: t.get('filter.sort.top.label'),
|
||||
icon: Trophy,
|
||||
subActions: [
|
||||
{
|
||||
name: t.get('filter.sort.top.time.all'),
|
||||
icon: ChartBar,
|
||||
href: '/?sort=TopAll',
|
||||
},
|
||||
{
|
||||
name: t.get('filter.sort.top.time.9months'),
|
||||
icon: ChartBar,
|
||||
href: '/?sort=Top9Months',
|
||||
},
|
||||
{
|
||||
name: t.get('filter.sort.top.time.6months'),
|
||||
icon: ChartBar,
|
||||
href: '/?sort=Top6Months',
|
||||
},
|
||||
{
|
||||
name: t.get('filter.sort.top.time.3months'),
|
||||
icon: ChartBar,
|
||||
href: '/?sort=Top3Months',
|
||||
},
|
||||
{
|
||||
name: t.get('filter.sort.top.time.month'),
|
||||
icon: ChartBar,
|
||||
href: '/?sort=TopMonth',
|
||||
},
|
||||
{
|
||||
name: t.get('filter.sort.top.time.week'),
|
||||
icon: ChartBar,
|
||||
href: '/?sort=TopWeek',
|
||||
},
|
||||
{
|
||||
name: t.get('filter.sort.top.time.day'),
|
||||
icon: ChartBar,
|
||||
href: '/?sort=TopDay',
|
||||
},
|
||||
{
|
||||
name: t.get('filter.sort.top.time.6hours'),
|
||||
icon: ChartBar,
|
||||
href: '/?sort=Top6Hours',
|
||||
},
|
||||
{
|
||||
name: t.get('filter.sort.top.time.hour'),
|
||||
icon: ChartBar,
|
||||
href: '/?sort=TopHour',
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
name: t.get('filter.sort.active'),
|
||||
icon: ArrowTrendingUp,
|
||||
href: '/?sort=Active',
|
||||
},
|
||||
{
|
||||
name: t.get('filter.sort.hot'),
|
||||
icon: Fire,
|
||||
href: '/?sort=Hot',
|
||||
},
|
||||
{
|
||||
name: t.get('filter.sort.scaled'),
|
||||
icon: Scale,
|
||||
href: '/?sort=Scaled',
|
||||
},
|
||||
{
|
||||
name: t.get('filter.sort.new'),
|
||||
icon: Star,
|
||||
href: '/?sort=New',
|
||||
},
|
||||
{
|
||||
name: t.get('filter.sort.old'),
|
||||
icon: Clock,
|
||||
href: '/?sort=Old',
|
||||
},
|
||||
{
|
||||
name: t.get('filter.sort.controversial'),
|
||||
icon: ArrowTrendingDown,
|
||||
href: '/?sort=Controversial',
|
||||
},
|
||||
{
|
||||
name: t.get('filter.sort.mostcomments'),
|
||||
icon: ChatBubbleOvalLeftEllipsis,
|
||||
href: '/?sort=MostComments',
|
||||
},
|
||||
{
|
||||
name: t.get('filter.sort.newcomments'),
|
||||
icon: ChatBubbleLeftRight,
|
||||
href: '/?sort=NewComments',
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
name: t.get('profile.profile'),
|
||||
actions: profile.jwt
|
||||
? [
|
||||
{
|
||||
href: '/profile/user',
|
||||
name: t.get('profile.profile'),
|
||||
icon: UserCircle,
|
||||
},
|
||||
{
|
||||
href: '/inbox',
|
||||
name: t.get('profile.inbox'),
|
||||
icon: Inbox,
|
||||
shortcut: 'i',
|
||||
},
|
||||
{
|
||||
href: '/saved',
|
||||
name: t.get('profile.saved'),
|
||||
icon: Bookmark,
|
||||
},
|
||||
{
|
||||
href: '/accounts',
|
||||
name: t.get('account.accounts'),
|
||||
icon: UserGroup,
|
||||
},
|
||||
]
|
||||
: [
|
||||
{
|
||||
href: '/login',
|
||||
name: t.get('account.login'),
|
||||
icon: ArrowRightOnRectangle,
|
||||
},
|
||||
{
|
||||
href: '/signup',
|
||||
name: t.get('account.signup'),
|
||||
icon: Identification,
|
||||
},
|
||||
{
|
||||
href: '/accounts',
|
||||
name: t.get('account.accounts'),
|
||||
icon: UserGroup,
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
name: t.get('nav.menu.app'),
|
||||
actions: [
|
||||
{
|
||||
href: '/settings',
|
||||
name: t.get('nav.menu.settings'),
|
||||
icon: Cog6Tooth,
|
||||
},
|
||||
{
|
||||
name: t.get('nav.commands.setView'),
|
||||
icon: ViewColumns,
|
||||
subActions: [
|
||||
{
|
||||
name: t.get('nav.commands.setViewTo', {
|
||||
default: t.get('filter.view.compact'),
|
||||
}),
|
||||
icon: ViewColumns,
|
||||
handle: () =>
|
||||
userSettings.update((s) => ({
|
||||
...s,
|
||||
view: 'compact',
|
||||
})),
|
||||
},
|
||||
{
|
||||
name: t.get('nav.commands.setViewTo', {
|
||||
default: t.get('filter.view.cozy'),
|
||||
}),
|
||||
icon: ViewColumns,
|
||||
handle: () =>
|
||||
userSettings.update((s) => ({
|
||||
...s,
|
||||
view: 'cozy',
|
||||
})),
|
||||
},
|
||||
{
|
||||
name: t.get('nav.commands.setViewTo', {
|
||||
default: t.get('filter.view.list'),
|
||||
}),
|
||||
icon: ViewColumns,
|
||||
handle: () =>
|
||||
userSettings.update((s) => ({
|
||||
...s,
|
||||
view: 'list',
|
||||
})),
|
||||
},
|
||||
{
|
||||
name: t.get('nav.commands.setViewTo', {
|
||||
default: t.get('filter.view.legacy'),
|
||||
}),
|
||||
icon: ViewColumns,
|
||||
handle: () =>
|
||||
userSettings.update((s) => ({
|
||||
...s,
|
||||
view: 'card',
|
||||
})),
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
name: t.get('nav.commands.setColor'),
|
||||
icon: PaintBrush,
|
||||
subActions: [
|
||||
{
|
||||
name: t.get('nav.commands.setColorTo', {
|
||||
default: t.get('nav.menu.colorscheme.system'),
|
||||
}),
|
||||
handle: () => legacyTheme.set('system'),
|
||||
icon: ComputerDesktop,
|
||||
},
|
||||
{
|
||||
name: t.get('nav.commands.setColorTo', {
|
||||
default: t.get('nav.menu.colorscheme.light'),
|
||||
}),
|
||||
handle: () => legacyTheme.set('light'),
|
||||
icon: Sun,
|
||||
},
|
||||
{
|
||||
name: t.get('nav.commands.setColorTo', {
|
||||
default: t.get('nav.menu.colorscheme.dark'),
|
||||
}),
|
||||
handle: () => legacyTheme.set('dark'),
|
||||
icon: Moon,
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
name: t.get('nav.commands.content'),
|
||||
actions: [
|
||||
{
|
||||
href: '/create/post',
|
||||
name: t.get('routes.createPost'),
|
||||
icon: PencilSquare,
|
||||
},
|
||||
{
|
||||
href: '/create/community',
|
||||
name: t.get('routes.createCommunity'),
|
||||
icon: Newspaper,
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
name: t.get('profile.subscribed'),
|
||||
actions:
|
||||
profile?.user?.follows.map((f) => ({
|
||||
icon: f.community.icon,
|
||||
name: f.community.title,
|
||||
href: `/c/${fullCommunityName(
|
||||
f.community.name,
|
||||
f.community.actor_id
|
||||
)}`,
|
||||
})) ?? [],
|
||||
},
|
||||
]
|
||||
}
|
||||
Reference in new issue
Block a user