back interdiff of round #1 and #0

add handling of app links on search #8

merged
opened by aylac.top targeting main from aylac.top/pdsls: apphandling

adds handling of links for some (the same that are in the templates.ts file) atproto apps

it lets you paste links like https://tangled.org/@pdsls.dev/pdsls and it will convert it to the at:// link

unfortunately doesn't work with links that don't provide all the necessary information to get the record (like the links for issues on tangled)

if it detects a link on the search it will try seeing if it has an app that matches it and then runs a function to handle it

it uses an enum for the apps thing because i thought it would look cool, but can easily be replaced with strings if that's preferred

really hope i didn't mess anything up

files
src
components
utils
REVERTED
src/components/search.tsx
··· 2 2 import { A, useLocation, useNavigate } from "@solidjs/router"; 3 3 import { createResource, createSignal, For, onCleanup, onMount, Show } from "solid-js"; 4 4 import { isTouchDevice } from "../layout"; 5 - import { appHandleLink, appList } from "../utils/app-urls"; 6 5 import { createDebouncedValue } from "../utils/hooks/debounced"; 7 6 8 7 export const [showSearch, setShowSearch] = createSignal(false); ··· 69 68 setShowSearch(false); 70 69 if (input === "me" && localStorage.getItem("lastSignedIn") !== null) { 71 70 navigate(`/at://${localStorage.getItem("lastSignedIn")}`); 71 + } else if ( 72 + !input.startsWith("https://bsky.app/") && 73 + (input.startsWith("https://") || input.startsWith("http://")) 74 + ) { 75 + navigate(`/${input.replace("https://", "").replace("http://", "").replace("/", "")}`); 72 76 } else if (search()?.length) { 73 77 navigate(`/at://${search()![0].did}`); 74 - } else if (input.startsWith("https://") || input.startsWith("http://")) { 75 - const hostLength = input.indexOf("/", 8); 76 - const host = input.slice(0, hostLength).replace("https://", "").replace("http://", ""); 77 - 78 - if (!(host in appList)) { 79 - navigate(`/${input.replace("https://", "").replace("http://", "").replace("/", "")}`); 80 - } else { 81 - const app = appList[host as keyof typeof appList]; 82 - const path = input.slice(hostLength + 1).split("/"); 83 - 84 - const uri = appHandleLink[app](path); 85 - navigate(`/${uri}`); 86 - } 87 78 } else { 79 + const uri = input 80 + .replace("at://", "") 81 + .replace("https://bsky.app/profile/", "") 82 + .replace("/post/", "/app.bsky.feed.post/"); 83 + const uriParts = uri.split("/"); 84 + navigate( 85 + `/at://${uriParts[0]}${uriParts.length > 1 ? `/${uriParts.slice(1).join("/")}` : ""}`, 86 + ); 88 - navigate(`/at://${input}`); 89 87 } 90 88 setShowSearch(false); 91 89 };
ERROR
src/utils/app-urls.ts

Failed to calculate interdiff for this file.