misc: move groups function to actions.ts
This commit is contained in:
1 parent
47b8b21ede
commit
860e0cafab
2 files changed
+125
-88
No files matched your search
@@ -34,6 +34,7 @@
|
||||
import { afterNavigate, goto } from '$app/navigation'
|
||||
import { profile } from '$lib/auth'
|
||||
import { fullCommunityName } from '$lib/util'
|
||||
import { getGroups } from './actions'
|
||||
|
||||
export let open = false
|
||||
$: if (open) search = ''
|
||||
@@ -54,93 +55,7 @@
|
||||
|
||||
export let groups: Group[] = []
|
||||
|
||||
$: groups = [
|
||||
{
|
||||
name: $t('nav.commands.recents'),
|
||||
actions: $resumables.map((r) => ({
|
||||
name: r.name,
|
||||
icon: r.avatar ?? PencilSquare,
|
||||
href: r.url,
|
||||
})),
|
||||
},
|
||||
{
|
||||
name: $t('nav.commands.main'),
|
||||
actions: [
|
||||
{ href: '/', name: $t('nav.home'), icon: Home, shortcut: 'h' },
|
||||
{ href: '/communities', name: $t('nav.communities'), icon: GlobeAlt },
|
||||
],
|
||||
},
|
||||
{
|
||||
name: $t('profile.profile'),
|
||||
actions: [
|
||||
{
|
||||
href: '/profile/user',
|
||||
name: $t('profile.profile'),
|
||||
icon: UserCircle,
|
||||
},
|
||||
{
|
||||
href: '/inbox',
|
||||
name: $t('profile.inbox'),
|
||||
icon: Inbox,
|
||||
shortcut: 'i',
|
||||
},
|
||||
{
|
||||
href: '/saved',
|
||||
name: $t('profile.saved'),
|
||||
icon: Bookmark,
|
||||
},
|
||||
{
|
||||
href: '/accounts',
|
||||
name: $t('account.accounts'),
|
||||
icon: UserGroup,
|
||||
},
|
||||
{
|
||||
href: '/login',
|
||||
name: $t('account.login'),
|
||||
icon: ArrowRightOnRectangle,
|
||||
},
|
||||
{
|
||||
href: '/signup',
|
||||
name: $t('account.signup'),
|
||||
icon: Identification,
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
name: $t('nav.menu.app'),
|
||||
actions: [
|
||||
{
|
||||
href: '/settings',
|
||||
name: $t('nav.menu.settings'),
|
||||
icon: Cog6Tooth,
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
name: $t('nav.commands.content'),
|
||||
actions: [
|
||||
{
|
||||
href: '/create/post',
|
||||
name: $t('routes.createPost'),
|
||||
icon: PencilSquare,
|
||||
},
|
||||
{
|
||||
href: '/create/community',
|
||||
name: $t('routes.createCommunity'),
|
||||
icon: Newspaper,
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
name: $t('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)}`,
|
||||
})) ?? [],
|
||||
},
|
||||
]
|
||||
$: groups = getGroups($resumables, $profile)
|
||||
|
||||
let search = ''
|
||||
let container: HTMLElement
|
||||
@@ -194,7 +109,7 @@
|
||||
actions: scoredActions,
|
||||
score: Math.max(
|
||||
fuzzySearch(group.name, search),
|
||||
...scoredActions.map((a) => a.score),
|
||||
...scoredActions.map((a) => a.score)
|
||||
),
|
||||
}
|
||||
})
|
||||
|
||||
@@ -0,0 +1,122 @@
|
||||
import type { Profile } from '$lib/auth'
|
||||
import { resumables, type ResumableItem } from '$lib/lemmy/item'
|
||||
import { t } from '$lib/translations'
|
||||
import { fullCommunityName } from '$lib/util'
|
||||
import {
|
||||
ArrowRightOnRectangle,
|
||||
Bookmark,
|
||||
Cog6Tooth,
|
||||
GlobeAlt,
|
||||
Home,
|
||||
Identification,
|
||||
Inbox,
|
||||
Newspaper,
|
||||
PencilSquare,
|
||||
UserCircle,
|
||||
UserGroup,
|
||||
} from 'svelte-hero-icons'
|
||||
|
||||
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,
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
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.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