437 lines
11 KiB
TypeScript
437 lines
11 KiB
TypeScript
import { goto } from '$app/navigation'
|
|
import { page } from '$app/state'
|
|
import {
|
|
profile as currentProfile,
|
|
type ProfileInfo,
|
|
} from '$lib/app/auth.svelte'
|
|
import { t } from '$lib/app/i18n'
|
|
import { settings } from '$lib/app/settings.svelte'
|
|
import { theme, type ThemeData } from '$lib/app/theme/theme.svelte'
|
|
import { fullCommunityName } from '$lib/app/util.svelte'
|
|
import type { ResumableItem } from '$lib/feature/legacy/item'
|
|
import {
|
|
ArrowRightOnRectangle,
|
|
ArrowTrendingDown,
|
|
ArrowTrendingUp,
|
|
Bookmark,
|
|
ChartBar,
|
|
ChatBubbleLeftRight,
|
|
ChatBubbleOvalLeftEllipsis,
|
|
Clock,
|
|
Cog6Tooth,
|
|
ComputerDesktop,
|
|
Fire,
|
|
GlobeAlt,
|
|
GlobeAmericas,
|
|
Home,
|
|
Identification,
|
|
Inbox,
|
|
MagnifyingGlass,
|
|
MapPin,
|
|
Moon,
|
|
Newspaper,
|
|
PaintBrush,
|
|
PencilSquare,
|
|
Plus,
|
|
Scale,
|
|
ServerStack,
|
|
ShieldCheck,
|
|
Star,
|
|
Sun,
|
|
Swatch,
|
|
Trophy,
|
|
UserCircle,
|
|
UserGroup,
|
|
ViewColumns,
|
|
type IconSource,
|
|
} from '@xylightdev/svelte-hero-icons'
|
|
import { SvelteURL } from 'svelte/reactivity'
|
|
|
|
export interface Group {
|
|
name: string
|
|
actions: Action[]
|
|
}
|
|
|
|
export interface Action {
|
|
name: string
|
|
desc?: string
|
|
handle?: () => void
|
|
href?: string
|
|
shortcut?: string
|
|
icon: string | IconSource
|
|
subActions?: Action[]
|
|
detail?: string
|
|
}
|
|
|
|
export function getGroups(
|
|
resumables: ResumableItem[],
|
|
profile: ProfileInfo,
|
|
profiles: ProfileInfo[],
|
|
td: ThemeData,
|
|
contextual?: Action[],
|
|
): Group[] {
|
|
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.contextual'),
|
|
actions: contextual ?? [],
|
|
},
|
|
{
|
|
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,
|
|
},
|
|
...(currentProfile.isMod()
|
|
? [
|
|
{
|
|
href: '/moderation',
|
|
name: t.get('nav.moderation'),
|
|
icon: ShieldCheck,
|
|
},
|
|
]
|
|
: []),
|
|
...(currentProfile.isAdmin
|
|
? [
|
|
{
|
|
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=TopNineMonths',
|
|
},
|
|
{
|
|
name: t.get('filter.sort.top.time.6months'),
|
|
icon: ChartBar,
|
|
href: '/?sort=TopSixMonths',
|
|
},
|
|
{
|
|
name: t.get('filter.sort.top.time.3months'),
|
|
icon: ChartBar,
|
|
href: '/?sort=TopThreeMonths',
|
|
},
|
|
{
|
|
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=TopSixHour',
|
|
},
|
|
{
|
|
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: '/login/guest',
|
|
name: t.get('account.addGuest'),
|
|
icon: Plus,
|
|
},
|
|
{
|
|
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: '/login/guest',
|
|
name: t.get('account.addGuest'),
|
|
icon: Plus,
|
|
},
|
|
{
|
|
href: '/accounts',
|
|
name: t.get('account.accounts'),
|
|
icon: UserGroup,
|
|
},
|
|
],
|
|
},
|
|
{
|
|
name: t.get('account.accounts'),
|
|
actions: profiles.map((p) => ({
|
|
name: p.username ?? t.get('account.guest'),
|
|
icon: p.avatar ?? UserCircle,
|
|
detail: p.instance,
|
|
handle: async () => {
|
|
if (profile.id != p.id) {
|
|
currentProfile.meta.profile = p.id
|
|
}
|
|
|
|
await goto(page.url, {
|
|
invalidateAll: true,
|
|
})
|
|
},
|
|
})),
|
|
},
|
|
{
|
|
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: () => (settings.view = 'compact'),
|
|
},
|
|
{
|
|
name: t.get('nav.commands.setViewTo', {
|
|
default: t.get('filter.view.cozy'),
|
|
}),
|
|
icon: ViewColumns,
|
|
handle: () => (settings.view = 'cozy'),
|
|
},
|
|
],
|
|
},
|
|
{
|
|
name: t.get('nav.commands.setColor'),
|
|
icon: PaintBrush,
|
|
subActions: [
|
|
{
|
|
name: t.get('nav.commands.setColorTo', {
|
|
default: t.get('nav.menu.colorscheme.system'),
|
|
}),
|
|
handle: () => (theme.colorScheme = 'system'),
|
|
icon: ComputerDesktop,
|
|
},
|
|
{
|
|
name: t.get('nav.commands.setColorTo', {
|
|
default: t.get('nav.menu.colorscheme.light'),
|
|
}),
|
|
handle: () => (theme.colorScheme = 'light'),
|
|
icon: Sun,
|
|
},
|
|
{
|
|
name: t.get('nav.commands.setColorTo', {
|
|
default: t.get('nav.menu.colorscheme.dark'),
|
|
}),
|
|
handle: () => (theme.colorScheme = 'dark'),
|
|
icon: Moon,
|
|
},
|
|
],
|
|
},
|
|
{
|
|
name: t.get('nav.commands.setTheme'),
|
|
icon: Swatch,
|
|
subActions: td.themes.map((th) => ({
|
|
name: t.get('nav.commands.setThemeTo', { default: th.name }),
|
|
icon: Swatch,
|
|
handle: () => (theme.data.currentTheme = th.id),
|
|
})),
|
|
},
|
|
],
|
|
},
|
|
{
|
|
name: t.get('nav.commands.content'),
|
|
actions: [
|
|
{
|
|
href: '/create/post',
|
|
name: t.get('form.post.create'),
|
|
icon: PencilSquare,
|
|
},
|
|
],
|
|
},
|
|
{
|
|
name: t.get('profile.subscribed'),
|
|
actions:
|
|
profile.user?.follows.map((f) => ({
|
|
icon: f.community.icon ?? Newspaper,
|
|
name: f.community.title,
|
|
href: `/c/${fullCommunityName(
|
|
f.community.name,
|
|
f.community.actor_id,
|
|
)}`,
|
|
detail: new SvelteURL(f.community.actor_id).hostname,
|
|
})) ?? [],
|
|
},
|
|
]
|
|
}
|
|
|
|
// this should really be rewritten, but a temporary change
|
|
// to make sure we don't recalculate ALL of that per keypress
|
|
export function dynamicActions(query: string): Group {
|
|
const actions = [
|
|
{
|
|
name: t.get('nav.commands.search', { default: query }),
|
|
icon: MagnifyingGlass,
|
|
href: `/search?q=${query}`,
|
|
},
|
|
{
|
|
name: t.get('nav.commands.communities', { default: query }),
|
|
icon: Newspaper,
|
|
href: `/explore/communities?q=${query}`,
|
|
},
|
|
]
|
|
|
|
return {
|
|
name: t.get('routes.search.other'),
|
|
actions: actions,
|
|
}
|
|
}
|