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
···
import { A, useLocation, useNavigate } from "@solidjs/router";
import { createResource, createSignal, For, onCleanup, onMount, Show } from "solid-js";
import { isTouchDevice } from "../layout";
-
import { appHandleLink, appList } from "../utils/app-urls";
import { createDebouncedValue } from "../utils/hooks/debounced";
export const [showSearch, setShowSearch] = createSignal(false);
···
setShowSearch(false);
if (input === "me" && localStorage.getItem("lastSignedIn") !== null) {
navigate(`/at://${localStorage.getItem("lastSignedIn")}`);
+
} else if (
+
!input.startsWith("https://bsky.app/") &&
+
(input.startsWith("https://") || input.startsWith("http://"))
+
) {
+
navigate(`/${input.replace("https://", "").replace("http://", "").replace("/", "")}`);
} else if (search()?.length) {
navigate(`/at://${search()![0].did}`);
-
} else if (input.startsWith("https://") || input.startsWith("http://")) {
-
const hostLength = input.indexOf("/", 8);
-
const host = input.slice(0, hostLength).replace("https://", "").replace("http://", "");
-
-
if (!(host in appList)) {
-
navigate(`/${input.replace("https://", "").replace("http://", "").replace("/", "")}`);
-
} else {
-
const app = appList[host as keyof typeof appList];
-
const path = input.slice(hostLength + 1).split("/");
-
-
const uri = appHandleLink[app](path);
-
navigate(`/${uri}`);
-
}
} else {
+
const uri = input
+
.replace("at://", "")
+
.replace("https://bsky.app/profile/", "")
+
.replace("/post/", "/app.bsky.feed.post/");
+
const uriParts = uri.split("/");
+
navigate(
+
`/at://${uriParts[0]}${uriParts.length > 1 ? `/${uriParts.slice(1).join("/")}` : ""}`,
+
);
-
navigate(`/at://${input}`);
}
setShowSearch(false);
};
ERROR
src/utils/app-urls.ts

Failed to calculate interdiff for this file.