diff --git a/src/App/Header.svelte b/src/App/Header.svelte index e724d2cd5..af9db771d 100644 --- a/src/App/Header.svelte +++ b/src/App/Header.svelte @@ -1,8 +1,6 @@ - - diff --git a/src/App/Hotkeys.svelte b/src/App/Hotkeys.svelte index 0a203c22c..49c674f86 100644 --- a/src/App/Hotkeys.svelte +++ b/src/App/Hotkeys.svelte @@ -3,7 +3,6 @@ import ColorPaletteModal from "@app/modals/ColorPaletteModal.svelte"; import HotkeysModal from "@app/modals/HotkeysModal.svelte"; - import { searchPlaceholder } from "@app/lib/shared"; const onKeydown = (event: KeyboardEvent) => { if (event.key === "Escape") { @@ -15,14 +14,6 @@ case "?": modal.toggle({ component: HotkeysModal, props: {} }); break; - case "/": { - event.preventDefault(); - const searchInput: HTMLElement | null = document.querySelector( - `*[placeholder="${searchPlaceholder}"]`, - ); - searchInput?.focus(); - break; - } case "d": if (import.meta.env.PROD) { return; diff --git a/src/lib/projects.ts b/src/lib/projects.ts new file mode 100644 index 000000000..922672835 --- /dev/null +++ b/src/lib/projects.ts @@ -0,0 +1,25 @@ +import type { BaseUrl, Project } from "@httpd-client"; + +import { HttpdClient } from "@httpd-client"; +import { isFulfilled } from "@app/lib/utils"; + +export interface ProjectBaseUrl { + project: Project; + baseUrl: BaseUrl; +} + +export async function getProjectsFromNodes( + params: { id: string; baseUrl: BaseUrl }[], +): Promise { + const projectPromises = params.map(async param => { + const api = new HttpdClient(param.baseUrl); + const project = await api.project.getById(param.id); + return { + project, + baseUrl: param.baseUrl, + }; + }); + + const results = await Promise.allSettled(projectPromises); + return results.filter(isFulfilled).map(r => r.value); +} diff --git a/src/lib/search.ts b/src/lib/search.ts deleted file mode 100644 index 15025fbff..000000000 --- a/src/lib/search.ts +++ /dev/null @@ -1,66 +0,0 @@ -import type { BaseUrl, Project } from "@httpd-client"; - -import * as utils from "@app/lib/utils"; -import { HttpdClient } from "@httpd-client"; -import { config } from "@app/lib/config"; -import { isFulfilled } from "@app/lib/utils"; - -export interface ProjectBaseUrl { - project: Project; - baseUrl: BaseUrl; -} - -type SearchResult = - | { type: "nothing" } - | { type: "error"; message: string } - | { type: "projects"; results: ProjectBaseUrl[] }; - -export async function searchProjectsAndProfiles( - query: string, -): Promise { - try { - const pinned = config.nodes.pinned.map(node => ({ - id: query, - baseUrl: node.baseUrl, - })); - - if (utils.isRepositoryId(query)) { - const results = await getProjectsFromNodes(pinned); - - if (results.length === 0) { - return { type: "nothing" }; - } else { - return { - type: "projects", - results, - }; - } - } - - return { type: "nothing" }; - } catch (error) { - let message = "An unknown error occoured while searching."; - - if (error instanceof Error) { - message = error.message; - } - - return { type: "error", message }; - } -} - -export async function getProjectsFromNodes( - params: { id: string; baseUrl: BaseUrl }[], -): Promise { - const projectPromises = params.map(async param => { - const api = new HttpdClient(param.baseUrl); - const project = await api.project.getById(param.id); - return { - project, - baseUrl: param.baseUrl, - }; - }); - - const results = await Promise.allSettled(projectPromises); - return results.filter(isFulfilled).map(r => r.value); -} diff --git a/src/lib/shared.ts b/src/lib/shared.ts deleted file mode 100644 index 3afd7194b..000000000 --- a/src/lib/shared.ts +++ /dev/null @@ -1,4 +0,0 @@ -// This file is shared between tests and the UI code. It should only contain -// basic JS primitives, so that it works in both browser and node environments. - -export const searchPlaceholder = "Enter an RID"; diff --git a/src/modals/HotkeysModal.svelte b/src/modals/HotkeysModal.svelte index cf2a4e346..420a6450b 100644 --- a/src/modals/HotkeysModal.svelte +++ b/src/modals/HotkeysModal.svelte @@ -40,11 +40,6 @@ ? -
-
Search
- / -
- {#if import.meta.env.DEV}
Color palette
diff --git a/src/modals/SearchResultsModal.svelte b/src/modals/SearchResultsModal.svelte deleted file mode 100644 index 4fb7eb3bd..000000000 --- a/src/modals/SearchResultsModal.svelte +++ /dev/null @@ -1,55 +0,0 @@ - - - - - - - - - {#if results.length > 0} -
    - {#each results as result} -
  • - - - {result.project.name} - -  {formatRepositoryId(result.project.id)} - - - -
  • - {/each} -
- {/if} -
-
diff --git a/src/views/home/router.ts b/src/views/home/router.ts index 5b2a62eeb..3b1962cc4 100644 --- a/src/views/home/router.ts +++ b/src/views/home/router.ts @@ -1,12 +1,12 @@ import type { LoadErrorRoute } from "@app/lib/router/definitions"; -import type { ProjectBaseUrl } from "@app/lib/search"; +import type { ProjectBaseUrl } from "@app/lib/projects"; import type { WeeklyActivity } from "@app/lib/commit"; import { get } from "svelte/store"; import { api, httpdStore } from "@app/lib/httpd"; import { config } from "@app/lib/config"; -import { getProjectsFromNodes } from "@app/lib/search"; +import { getProjectsFromNodes } from "@app/lib/projects"; import { loadProjectActivity } from "@app/lib/commit"; export interface ProjectBaseUrlActivity extends ProjectBaseUrl { diff --git a/tests/e2e/hotkeys.spec.ts b/tests/e2e/hotkeys.spec.ts deleted file mode 100644 index ad07dbd5b..000000000 --- a/tests/e2e/hotkeys.spec.ts +++ /dev/null @@ -1,39 +0,0 @@ -import { searchPlaceholder } from "@app/lib/shared"; -import { test, expect } from "@tests/support/fixtures.js"; - -test("global hotkeys", async ({ page }) => { - await page.goto("/"); - await page.locator("body").press(`/`); - await expect(page.locator(".search.expanded")).toBeVisible(); - // Delaying the input speed a bit to imitate a real user. - await page.keyboard.type("searchquery", { delay: 100 }); - - // Keyboard hint shows up in the search bar. - { - await expect(page.getByText("⏎")).toBeVisible(); - await expect(page.getByPlaceholder(searchPlaceholder)).toHaveValue( - "searchquery", - ); - } - - // Other hotkeys don't trigger while input is focussed. - { - await page.keyboard.type("?"); - await expect(page.getByPlaceholder(searchPlaceholder)).toHaveValue( - "searchquery?", - ); - await expect( - page.locator(".modal").getByText("Keyboard shortcuts"), - ).not.toBeVisible(); - } - - // Hitting `Esc` defocuses the input. - { - await page.locator("body").press("Escape"); - await expect(page.getByPlaceholder(searchPlaceholder)).toHaveValue( - "searchquery?", - ); - await expect(page.getByText("⏎")).toBeHidden(); - await expect(page.getByPlaceholder(searchPlaceholder)).not.toBeFocused(); - } -}); diff --git a/tests/e2e/search.spec.ts b/tests/e2e/search.spec.ts deleted file mode 100644 index be08fb6d5..000000000 --- a/tests/e2e/search.spec.ts +++ /dev/null @@ -1,33 +0,0 @@ -import { searchPlaceholder } from "@app/lib/shared"; -import { - test, - expect, - sourceBrowsingRid, - sourceBrowsingUrl, -} from "@tests/support/fixtures.js"; - -test("navigate to existing project", async ({ page }) => { - await page.goto("/"); - const searchInput = page.getByPlaceholder(searchPlaceholder); - await searchInput.click(); - await searchInput.fill(sourceBrowsingRid); - await searchInput.press("Enter"); - - await expect(page).toHaveURL(sourceBrowsingUrl); - await expect(searchInput).not.toHaveValue(sourceBrowsingRid); -}); - -test("navigate to a project that does not exist", async ({ page }) => { - await page.goto("/"); - const searchInput = page.getByPlaceholder(searchPlaceholder); - await searchInput.click(); - - const nonExistantId = "rad:zAAAAAAAAAAAAAAAAAAAAAAAAAAA"; - await searchInput.fill(nonExistantId); - await searchInput.press("Enter"); - - await page.waitForSelector(".search-bar.shaking"); - - await expect(page).toHaveURL("/"); - await expect(searchInput).toHaveValue(nonExistantId); -});