From 0aca2e8400ce00cfa896af6e065120772542ea44 Mon Sep 17 00:00:00 2001 From: Scott Chacon Date: Sun, 12 Mar 2023 08:14:39 -0700 Subject: [PATCH] command palette is everywhere, but only shows project stuff when there is an active project also, contact us page --- src/lib/components/CommandPalette.svelte | 89 ++++++++++++------- src/lib/components/icons/ContactIcon.svelte | 14 +++ src/lib/current_project.ts | 4 + src/routes/+layout.svelte | 2 + src/routes/+page.svelte | 5 +- src/routes/contact/+page.svelte | 74 +++++++++++++++ .../projects/[projectId]/+layout.svelte | 13 ++- 7 files changed, 162 insertions(+), 39 deletions(-) create mode 100644 src/lib/components/icons/ContactIcon.svelte create mode 100644 src/lib/current_project.ts create mode 100644 src/routes/contact/+page.svelte diff --git a/src/lib/components/CommandPalette.svelte b/src/lib/components/CommandPalette.svelte index 99ef84859..8ae41c85f 100644 --- a/src/lib/components/CommandPalette.svelte +++ b/src/lib/components/CommandPalette.svelte @@ -4,9 +4,11 @@ import CommitIcon from './icons/CommitIcon.svelte'; import BookmarkIcon from './icons/BookmarkIcon.svelte'; import BranchIcon from './icons/BranchIcon.svelte'; + import ContactIcon from './icons/ContactIcon.svelte'; import { invoke } from '@tauri-apps/api'; import { goto } from '$app/navigation'; import { shortPath } from '$lib/paths'; + import { currentProject } from '$lib/current_project'; let showCommand = false; let showCommit = false; @@ -15,8 +17,6 @@ let is_k_down = false; let is_c_down = false; - export let projectId: string; - let palette: HTMLElement; let commitPalette: HTMLElement; @@ -165,7 +165,9 @@ } console.log('active', active); } else { - goto('/projects/' + projectId + '/search?search=' + search); + if ($currentProject) { + goto('/projects/' + $currentProject.id + '/search?search=' + search); + } } } } @@ -173,14 +175,20 @@ function executeCommand(command: string) { switch (command) { case 'commit': - listFiles({ projectId: projectId }).then((files) => { - console.log('files', files); - changedFiles = files; - }); - showCommit = true; - setTimeout(function () { - commitMessageInput.focus(); - }, 100); + if ($currentProject) { + listFiles({ projectId: $currentProject.id }).then((files) => { + console.log('files', files); + changedFiles = files; + }); + showCommit = true; + setTimeout(function () { + commitMessageInput.focus(); + }, 100); + } + break; + case 'contact': + console.log('contact us'); + goto('/contact'); break; case 'bookmark': break; @@ -195,13 +203,24 @@ searchChanged(search, showCommand); } - let baseCommands = [ + let projectCommands = [ { text: 'Commit', key: 'C', icon: CommitIcon, command: 'commit' }, { text: 'Bookmark', key: 'B', icon: BookmarkIcon, command: 'bookmark' }, - { text: 'Branch', key: 'H', icon: BranchIcon, command: 'branch' } + { text: 'Branch', key: 'R', icon: BranchIcon, command: 'branch' } ]; - $: menuItems = baseCommands; + let baseCommands = [{ text: 'Contact Us', key: 'H', icon: ContactIcon, command: 'contact' }]; + + function commandList() { + let commands = []; + if ($currentProject) { + commands = projectCommands; + } + commands = commands.concat(baseCommands); + return commands; + } + + $: menuItems = commandList(); function searchChanged(searchValue: string, showCommand: boolean) { if (!showCommand) { @@ -211,26 +230,27 @@ updateMenu([]); return; } - const searchPattern = '.*' + Array.from(searchValue).join('(.*)'); - matchFiles({ projectId: projectId, matchPattern: searchPattern }).then((files) => { - let searchResults = []; - files.slice(0, 5).forEach((f) => { - searchResults.push({ text: f, icon: FileIcon }); + if ($currentProject) { + const searchPattern = '.*' + Array.from(searchValue).join('(.*)'); + matchFiles({ projectId: $currentProject.id, matchPattern: searchPattern }).then((files) => { + let searchResults = []; + files.slice(0, 5).forEach((f) => { + searchResults.push({ text: f, icon: FileIcon }); + }); + updateMenu(searchResults); }); - updateMenu(searchResults); - }); + } } function updateMenu(searchResults: Array<{ text: string }>) { if (searchResults.length == 0) { - menuItems = baseCommands; + menuItems = commandList(); } else { menuItems = searchResults; } } function doCommit() { - console.log('do commit', commitMessage); // get checked files let changedFiles: Array = []; let doc = document.getElementsByClassName('file-checkbox'); @@ -239,17 +259,18 @@ changedFiles.push(c.dataset['file']); } }); - console.log('files', changedFiles, commitMessage); - commit({ - projectId: projectId, - message: commitMessage, - files: changedFiles, - push: false - }).then((result) => { - console.log('commit result', result); - commitMessage = ''; - showCommit = false; - }); + if ($currentProject) { + commit({ + projectId: $currentProject.id, + message: commitMessage, + files: changedFiles, + push: false + }).then((result) => { + console.log('commit result', result); + commitMessage = ''; + showCommit = false; + }); + } } diff --git a/src/lib/components/icons/ContactIcon.svelte b/src/lib/components/icons/ContactIcon.svelte new file mode 100644 index 000000000..bdba7d036 --- /dev/null +++ b/src/lib/components/icons/ContactIcon.svelte @@ -0,0 +1,14 @@ + + + diff --git a/src/lib/current_project.ts b/src/lib/current_project.ts new file mode 100644 index 000000000..10024dc0e --- /dev/null +++ b/src/lib/current_project.ts @@ -0,0 +1,4 @@ +import { writable } from 'svelte/store'; +import type { Project } from '$lib/projects'; + +export const currentProject = writable(undefined); \ No newline at end of file diff --git a/src/routes/+layout.svelte b/src/routes/+layout.svelte index 4b459900e..fb79d075a 100644 --- a/src/routes/+layout.svelte +++ b/src/routes/+layout.svelte @@ -8,6 +8,7 @@ import { writable } from 'svelte/store'; import Breadcrumbs from '$lib/components/Breadcrumbs.svelte'; import CommandPalette from '$lib/components/CommandPalette.svelte'; + import { currentProject } from '$lib/current_project'; export let data: LayoutData; const { user, posthog, projects } = data; @@ -45,4 +46,5 @@ + diff --git a/src/routes/+page.svelte b/src/routes/+page.svelte index 4db6cd777..981be2f7e 100644 --- a/src/routes/+page.svelte +++ b/src/routes/+page.svelte @@ -2,11 +2,14 @@ import { open } from '@tauri-apps/api/dialog'; import type { LayoutData } from './$types'; import { toasts } from '$lib'; + import { currentProject } from '$lib/current_project'; export let data: LayoutData; const { projects } = data; + $: currentProject.set(undefined); + const onAddLocalRepositoryClick = async () => { const selectedPath = await open({ directory: true, @@ -185,7 +188,7 @@
{#if project.api}
diff --git a/src/routes/contact/+page.svelte b/src/routes/contact/+page.svelte new file mode 100644 index 000000000..9bb94ac45 --- /dev/null +++ b/src/routes/contact/+page.svelte @@ -0,0 +1,74 @@ +
+
+

Contact Us

+

+ Thanks for using GitButler! We would love to help with any questions, problems or requests. + Select your weapon of choice. +

+
+
+
+
+ +
+
+

Email Us

+

+ We love our emails. For bugs, feature requests, general questions or anything else, just + fire off an emain from your favorite client. +

+

+ hello@gitbutler.com +

+
+
+
+
+ +
+
+

Chat with Us

+

+ If you prefer chatting in public, join our Discord community for something a little more + real time. +

+

+ Join our Discord +

+
+
+
+
diff --git a/src/routes/projects/[projectId]/+layout.svelte b/src/routes/projects/[projectId]/+layout.svelte index 05ab7fc13..84a46cc8e 100644 --- a/src/routes/projects/[projectId]/+layout.svelte +++ b/src/routes/projects/[projectId]/+layout.svelte @@ -5,11 +5,12 @@ import type { Project } from '$lib/projects'; import { onDestroy } from 'svelte'; import { page } from '$app/stores'; - import CommandPalette from '$lib/components/CommandPalette.svelte'; + import { currentProject } from '$lib/current_project'; export let data: LayoutData; $: project = data.project; + $: currentProject.set($project); function projectUrl(project: Project) { const gitUrl = project.api?.git_url; @@ -126,8 +127,13 @@
Open in GitButler Cloud
- -
+ +
{:else} @@ -141,4 +147,3 @@
-