From 29a87b7efed209d74279b6ef18fff78538970c50 Mon Sep 17 00:00:00 2001 From: Nikita Galaiko Date: Wed, 5 Apr 2023 13:52:00 +0200 Subject: [PATCH] pnpm format --- .../CommandPalette/QuickCommit.svelte | 2 +- src/lib/components/CommandPalette/commands.ts | 290 +++++++++--------- src/lib/components/icons/GitCommitIcon.svelte | 14 +- src/lib/components/icons/RewindIcon.svelte | 14 +- src/lib/git/index.ts | 8 +- src/lib/utils.ts | 10 +- 6 files changed, 181 insertions(+), 157 deletions(-) diff --git a/src/lib/components/CommandPalette/QuickCommit.svelte b/src/lib/components/CommandPalette/QuickCommit.svelte index c7f256471..a405983c9 100644 --- a/src/lib/components/CommandPalette/QuickCommit.svelte +++ b/src/lib/components/CommandPalette/QuickCommit.svelte @@ -80,7 +80,7 @@
diff --git a/src/lib/components/CommandPalette/commands.ts b/src/lib/components/CommandPalette/commands.ts index fd7c4e51c..8d59c1615 100644 --- a/src/lib/components/CommandPalette/commands.ts +++ b/src/lib/components/CommandPalette/commands.ts @@ -6,183 +6,183 @@ import type { SvelteComponent, SvelteComponentTyped } from 'svelte'; import { format, startOfISOWeek, startOfMonth, subDays, subMonths, subWeeks } from 'date-fns'; type ActionLink = { - href: string; + href: string; }; interface Newable { - new(...args: any[]): ReturnType; + new (...args: any[]): ReturnType; } type ComponentProps = T extends SvelteComponentTyped - ? R - : unknown; + ? R + : unknown; export type ActionComponent = { - title: string; - component: Newable; - props: ComponentProps; + title: string; + component: Newable; + props: ComponentProps; }; export type Action = ActionLink | ActionComponent | Group; export namespace Action { - export const isLink = (action: Action): action is ActionLink => 'href' in action; - export const isComponent = (action: Action): action is ActionComponent => - 'component' in action; - export const isGroup = (action: Action): action is Group => 'commands' in action; + export const isLink = (action: Action): action is ActionLink => 'href' in action; + export const isComponent = (action: Action): action is ActionComponent => + 'component' in action; + export const isGroup = (action: Action): action is Group => 'commands' in action; } export type Command = { - title: string; - hotkey?: string; - action: Action; - icon?: Newable; + title: string; + hotkey?: string; + action: Action; + icon?: Newable; }; export type Group = { - title: string; - description?: string; - commands: Command[]; + title: string; + description?: string; + commands: Command[]; }; const goToProjectGroup = ({ projects, input }: { projects: Project[]; input: string }): Group => ({ - title: 'Go to project', - commands: projects - .map((project, index) => ({ - title: project.title, - hotkey: `${index + 1}`, - action: { - href: `/projects/${project.id}/` - } - })) - .filter(({ title }) => input.length === 0 || title.toLowerCase().includes(input.toLowerCase())) + title: 'Go to project', + commands: projects + .map((project, index) => ({ + title: project.title, + hotkey: `${index + 1}`, + action: { + href: `/projects/${project.id}/` + } + })) + .filter(({ title }) => input.length === 0 || title.toLowerCase().includes(input.toLowerCase())) }); const actionsGroup = ({ project, input }: { project: Project; input: string }): Group => ({ - title: 'Actions', - commands: [ - { - title: 'Quick commit', - hotkey: 'c', - action: { - title: 'Quick commit', - component: QuickCommit, - props: { project } - }, - icon: GitCommitIcon - }, - { - title: 'Commit', - hotkey: 'Shift+c', - action: { - href: `/projects/${project.id}/commit/` - }, - icon: GitCommitIcon - }, - { - title: 'Terminal', - hotkey: 'Shift+t', - action: { - href: `/projects/${project?.id}/terminal/` - }, - icon: IconTerminal - }, - { - title: 'Replay History', - hotkey: 'r', - action: { - title: 'Replay working history', - commands: [ - { - title: 'Eralier today', - icon: RewindIcon, - hotkey: '1', - action: { - href: `/projects/${project.id}/player/${format(new Date(), 'yyyy-MM-dd')}/` - } - }, - { - title: 'Yesterday', - icon: RewindIcon, - hotkey: '2', - action: { - href: `/projects/${project.id}/player/${format( - subDays(new Date(), 1), - 'yyyy-MM-dd' - )}/` - } - }, - { - title: 'The day before yesterday', - icon: RewindIcon, - hotkey: '3', - action: { - href: `/projects/${project.id}/player/${format( - subDays(new Date(), 2), - 'yyyy-MM-dd' - )}/` - } - }, - { - title: 'The beginning of last week', - icon: RewindIcon, - hotkey: '4', - action: { - href: `/projects/${project.id}/player/${format( - startOfISOWeek(subWeeks(new Date(), 1)), - 'yyyy-MM-dd' - )}/` - } - }, - { - title: 'The beginning of last month', - icon: RewindIcon, - hotkey: '5', - action: { - href: `/projects/${project.id}/player/${format( - startOfMonth(subMonths(new Date(), 1)), - 'yyyy-MM-dd' - )}/` - } - } - ] - }, - icon: RewindIcon - } - ].filter(({ title }) => input.length === 0 || title.toLowerCase().includes(input.toLowerCase())) + title: 'Actions', + commands: [ + { + title: 'Quick commit', + hotkey: 'c', + action: { + title: 'Quick commit', + component: QuickCommit, + props: { project } + }, + icon: GitCommitIcon + }, + { + title: 'Commit', + hotkey: 'Shift+c', + action: { + href: `/projects/${project.id}/commit/` + }, + icon: GitCommitIcon + }, + { + title: 'Terminal', + hotkey: 'Shift+t', + action: { + href: `/projects/${project?.id}/terminal/` + }, + icon: IconTerminal + }, + { + title: 'Replay History', + hotkey: 'r', + action: { + title: 'Replay working history', + commands: [ + { + title: 'Eralier today', + icon: RewindIcon, + hotkey: '1', + action: { + href: `/projects/${project.id}/player/${format(new Date(), 'yyyy-MM-dd')}/` + } + }, + { + title: 'Yesterday', + icon: RewindIcon, + hotkey: '2', + action: { + href: `/projects/${project.id}/player/${format( + subDays(new Date(), 1), + 'yyyy-MM-dd' + )}/` + } + }, + { + title: 'The day before yesterday', + icon: RewindIcon, + hotkey: '3', + action: { + href: `/projects/${project.id}/player/${format( + subDays(new Date(), 2), + 'yyyy-MM-dd' + )}/` + } + }, + { + title: 'The beginning of last week', + icon: RewindIcon, + hotkey: '4', + action: { + href: `/projects/${project.id}/player/${format( + startOfISOWeek(subWeeks(new Date(), 1)), + 'yyyy-MM-dd' + )}/` + } + }, + { + title: 'The beginning of last month', + icon: RewindIcon, + hotkey: '5', + action: { + href: `/projects/${project.id}/player/${format( + startOfMonth(subMonths(new Date(), 1)), + 'yyyy-MM-dd' + )}/` + } + } + ] + }, + icon: RewindIcon + } + ].filter(({ title }) => input.length === 0 || title.toLowerCase().includes(input.toLowerCase())) }); const fileGroup = ({ - project, - input + project, + input }: { - project: Project; - input: string; + project: Project; + input: string; }): Group | Promise => - input.length === 0 - ? { - title: 'Files', - description: 'type part of a file name', - commands: [] - } - : matchFiles({ projectId: project.id, matchPattern: input }).then((files) => ({ - title: 'Files', - description: files.length === 0 ? `no files containing '${input}'` : '', - commands: files.map((file) => ({ - title: file, - action: { - href: '/' - } - })) - })); + input.length === 0 + ? { + title: 'Files', + description: 'type part of a file name', + commands: [] + } + : matchFiles({ projectId: project.id, matchPattern: input }).then((files) => ({ + title: 'Files', + description: files.length === 0 ? `no files containing '${input}'` : '', + commands: files.map((file) => ({ + title: file, + action: { + href: '/' + } + })) + })); export default (params: { projects: Project[]; project?: Project; input: string }) => { - const { projects, input, project } = params; - const groups = []; + const { projects, input, project } = params; + const groups = []; - !project && groups.push(goToProjectGroup({ projects, input })); - project && groups.push(actionsGroup({ project, input })); - project && groups.push(fileGroup({ project, input })); + !project && groups.push(goToProjectGroup({ projects, input })); + project && groups.push(actionsGroup({ project, input })); + project && groups.push(fileGroup({ project, input })); - return groups; + return groups; }; diff --git a/src/lib/components/icons/GitCommitIcon.svelte b/src/lib/components/icons/GitCommitIcon.svelte index fb40d7801..4f67f15f2 100644 --- a/src/lib/components/icons/GitCommitIcon.svelte +++ b/src/lib/components/icons/GitCommitIcon.svelte @@ -1,4 +1,16 @@ - + + + + + + - invoke('git_commit', params); + invoke('git_commit', params); export const stage = (params: { projectId: string; paths: Array }) => - invoke('git_stage', params); + invoke('git_stage', params); export const unstage = (params: { projectId: string; paths: Array }) => - invoke('git_unstage', params); + invoke('git_unstage', params); export const matchFiles = (params: { projectId: string; matchPattern: string }) => - invoke('git_match_paths', params); + invoke('git_match_paths', params); diff --git a/src/lib/utils.ts b/src/lib/utils.ts index d963e4187..db7896e4d 100644 --- a/src/lib/utils.ts +++ b/src/lib/utils.ts @@ -1,7 +1,7 @@ export const debounce = any>(fn: T, delay: number) => { - let timeout: ReturnType; - return (...args: any[]) => { - clearTimeout(timeout); - timeout = setTimeout(() => fn(...args), delay); - }; + let timeout: ReturnType; + return (...args: any[]) => { + clearTimeout(timeout); + timeout = setTimeout(() => fn(...args), delay); + }; };