atproto explorer pdsls.dev
atproto tool

Compare changes

Choose any two refs to compare.

+3 -1
src/views/settings.tsx
···
import { createSignal } from "solid-js";
import { TextInput } from "../components/text-input.jsx";
+
import { ThemeSelection } from "../components/theme.jsx";
export const [hideMedia, setHideMedia] = createSignal(localStorage.hideMedia === "true");
···
<div class="flex items-center gap-1 font-semibold">
<span>Settings</span>
</div>
-
<div class="flex flex-col gap-2">
+
<div class="flex flex-col gap-3">
<div class="flex flex-col gap-0.5">
<label for="plcDirectory" class="select-none">
PLC Directory
···
}}
/>
</div>
+
<ThemeSelection />
<div class="flex justify-between">
<div class="flex items-center gap-1">
<input
+7 -1
src/components/video-player.tsx
···
});
return (
-
<video ref={video} class="max-h-80 max-w-[20rem]" controls playsinline onLoadedData={props.onLoad}>
+
<video
+
ref={video}
+
class="max-h-80 max-w-[20rem]"
+
controls
+
playsinline
+
onLoadedData={props.onLoad}
+
>
<source type="video/mp4" />
</video>
);
+15 -15
src/utils/hooks/debounced.ts
···
-
import { type Accessor, createEffect, createSignal, onCleanup } from 'solid-js';
+
import { type Accessor, createEffect, createSignal, onCleanup } from "solid-js";
export const createDebouncedValue = <T>(
-
accessor: Accessor<T>,
-
delay: number,
-
equals?: false | ((prev: T, next: T) => boolean),
+
accessor: Accessor<T>,
+
delay: number,
+
equals?: false | ((prev: T, next: T) => boolean),
): Accessor<T> => {
-
const initial = accessor();
-
const [state, setState] = createSignal(initial, { equals });
+
const initial = accessor();
+
const [state, setState] = createSignal(initial, { equals });
-
createEffect((prev: T) => {
-
const next = accessor();
+
createEffect((prev: T) => {
+
const next = accessor();
-
if (prev !== next) {
-
const timeout = setTimeout(() => setState(() => next), delay);
-
onCleanup(() => clearTimeout(timeout));
-
}
+
if (prev !== next) {
+
const timeout = setTimeout(() => setState(() => next), delay);
+
onCleanup(() => clearTimeout(timeout));
+
}
-
return next;
-
}, initial);
+
return next;
+
}, initial);
-
return state;
+
return state;
};
+30
src/utils/key.ts
···
+
import { parseDidKey, parsePublicMultikey } from "@atcute/crypto";
+
import { fromBase58Btc } from "@atcute/multibase";
+
+
export const detectKeyType = (key: string): string => {
+
try {
+
return parsePublicMultikey(key).type;
+
} catch (e) {
+
try {
+
const bytes = fromBase58Btc(key.startsWith("z") ? key.slice(1) : key);
+
if (bytes.length >= 2) {
+
const type = (bytes[0] << 8) | bytes[1];
+
if (type === 0xed01) {
+
return "ed25519";
+
}
+
}
+
} catch {}
+
return "unknown";
+
}
+
};
+
+
export const detectDidKeyType = (key: string): string => {
+
try {
+
return parseDidKey(key).type;
+
} catch (e) {
+
if (key.startsWith("did:key:")) {
+
return detectKeyType(key.slice(8));
+
}
+
return "unknown";
+
}
+
};
+1 -1
public/oauth-client-metadata.json
···
"client_uri": "https://pdsls.dev",
"logo_uri": "https://pdsls.dev/favicon.ico",
"redirect_uris": ["https://pdsls.dev/"],
-
"scope": "atproto transition:generic",
+
"scope": "atproto repo:*?action=create repo:*?action=update repo:*?action=delete blob:*/*",
"grant_types": ["authorization_code", "refresh_token"],
"response_types": ["code"],
"token_endpoint_auth_method": "none",
+13
src/auth/oauth-config.ts
···
+
import { configureOAuth, defaultIdentityResolver } from "@atcute/oauth-browser-client";
+
import { didDocumentResolver, handleResolver } from "../utils/api";
+
+
configureOAuth({
+
metadata: {
+
client_id: import.meta.env.VITE_OAUTH_CLIENT_ID,
+
redirect_uri: import.meta.env.VITE_OAUTH_REDIRECT_URL,
+
},
+
identityResolver: defaultIdentityResolver({
+
handleResolver: handleResolver,
+
didDocumentResolver: didDocumentResolver,
+
}),
+
});
+77
src/auth/scope-flow.ts
···
+
import { isDid, isHandle } from "@atcute/lexicons/syntax";
+
import { createAuthorizationUrl } from "@atcute/oauth-browser-client";
+
import { createSignal } from "solid-js";
+
+
interface UseOAuthScopeFlowOptions {
+
onError?: (error: unknown) => void;
+
onRedirecting?: () => void;
+
beforeRedirect?: (account: string) => Promise<void>;
+
}
+
+
export const useOAuthScopeFlow = (options: UseOAuthScopeFlowOptions = {}) => {
+
const [showScopeSelector, setShowScopeSelector] = createSignal(false);
+
const [pendingAccount, setPendingAccount] = createSignal("");
+
const [shouldForceRedirect, setShouldForceRedirect] = createSignal(false);
+
+
const initiate = (account: string) => {
+
if (!account) return;
+
setPendingAccount(account);
+
setShouldForceRedirect(false);
+
setShowScopeSelector(true);
+
};
+
+
const initiateWithRedirect = (account: string) => {
+
if (!account) return;
+
setPendingAccount(account);
+
setShouldForceRedirect(true);
+
setShowScopeSelector(true);
+
};
+
+
const complete = async (scopeString: string, scopeIds: string) => {
+
try {
+
const account = pendingAccount();
+
+
if (options.beforeRedirect && !shouldForceRedirect()) {
+
try {
+
await options.beforeRedirect(account);
+
setShowScopeSelector(false);
+
return;
+
} catch {}
+
}
+
+
localStorage.setItem("pendingScopes", scopeIds);
+
+
options.onRedirecting?.();
+
+
const authUrl = await createAuthorizationUrl({
+
scope: scopeString,
+
target:
+
isHandle(account) || isDid(account) ?
+
{ type: "account", identifier: account }
+
: { type: "pds", serviceUrl: account },
+
});
+
+
await new Promise((resolve) => setTimeout(resolve, 250));
+
location.assign(authUrl);
+
} catch (e) {
+
console.error(e);
+
options.onError?.(e);
+
setShowScopeSelector(false);
+
}
+
};
+
+
const cancel = () => {
+
setShowScopeSelector(false);
+
setPendingAccount("");
+
setShouldForceRedirect(false);
+
};
+
+
return {
+
showScopeSelector,
+
pendingAccount,
+
initiate,
+
initiateWithRedirect,
+
complete,
+
cancel,
+
};
+
};
+53
src/auth/scope-utils.ts
···
+
import { agent, sessions } from "./state";
+
+
export const GRANULAR_SCOPES = [
+
{
+
id: "create",
+
scope: "repo:*?action=create",
+
label: "Create records",
+
},
+
{
+
id: "update",
+
scope: "repo:*?action=update",
+
label: "Update records",
+
},
+
{
+
id: "delete",
+
scope: "repo:*?action=delete",
+
label: "Delete records",
+
},
+
{
+
id: "blob",
+
scope: "blob:*/*",
+
label: "Upload blobs",
+
},
+
];
+
+
export const BASE_SCOPES = ["atproto"];
+
+
export const buildScopeString = (selected: Set<string>): string => {
+
const granular = GRANULAR_SCOPES.filter((s) => selected.has(s.id)).map((s) => s.scope);
+
return [...BASE_SCOPES, ...granular].join(" ");
+
};
+
+
export const scopeIdsToString = (scopeIds: Set<string>): string => {
+
return ["atproto", ...Array.from(scopeIds)].join(",");
+
};
+
+
export const parseScopeString = (scopeIdsString: string): Set<string> => {
+
if (!scopeIdsString) return new Set();
+
const ids = scopeIdsString.split(",").filter(Boolean);
+
return new Set(ids.filter((id) => id !== "atproto"));
+
};
+
+
export const hasScope = (grantedScopes: string | undefined, scopeId: string): boolean => {
+
if (!grantedScopes) return false;
+
return grantedScopes.split(",").includes(scopeId);
+
};
+
+
export const hasUserScope = (scopeId: string): boolean => {
+
if (!agent()) return false;
+
const grantedScopes = sessions[agent()!.sub]?.grantedScopes;
+
if (!grantedScopes) return true;
+
return hasScope(grantedScopes, scopeId);
+
};
+14
src/auth/state.ts
···
+
import { OAuthUserAgent } from "@atcute/oauth-browser-client";
+
import { createSignal } from "solid-js";
+
import { createStore } from "solid-js/store";
+
+
export type Account = {
+
signedIn: boolean;
+
handle?: string;
+
grantedScopes?: string;
+
};
+
+
export type Sessions = Record<string, Account>;
+
+
export const [agent, setAgent] = createSignal<OAuthUserAgent | undefined>();
+
export const [sessions, setSessions] = createStore<Sessions>();
-170
src/components/account.tsx
···
-
import { Client, CredentialManager } from "@atcute/client";
-
import { Did } from "@atcute/lexicons";
-
import {
-
createAuthorizationUrl,
-
deleteStoredSession,
-
getSession,
-
OAuthUserAgent,
-
} from "@atcute/oauth-browser-client";
-
import { A } from "@solidjs/router";
-
import { createSignal, For, onMount, Show } from "solid-js";
-
import { createStore, produce } from "solid-js/store";
-
import { resolveDidDoc } from "../utils/api.js";
-
import { ActionMenu, DropdownMenu, MenuProvider, NavMenu } from "./dropdown.jsx";
-
import { agent, Login, retrieveSession, Sessions, setAgent } from "./login.jsx";
-
import { Modal } from "./modal.jsx";
-
-
export const [sessions, setSessions] = createStore<Sessions>();
-
-
const AccountDropdown = (props: { did: Did }) => {
-
const removeSession = async (did: Did) => {
-
const currentSession = agent()?.sub;
-
try {
-
const session = await getSession(did, { allowStale: true });
-
const agent = new OAuthUserAgent(session);
-
await agent.signOut();
-
} catch {
-
deleteStoredSession(did);
-
}
-
setSessions(
-
produce((accs) => {
-
delete accs[did];
-
}),
-
);
-
localStorage.setItem("sessions", JSON.stringify(sessions));
-
if (currentSession === did) setAgent(undefined);
-
};
-
-
return (
-
<MenuProvider>
-
<DropdownMenu icon="lucide--ellipsis" buttonClass="rounded-md p-2">
-
<NavMenu href={`/at://${props.did}`} label="Go to repo" icon="lucide--user-round" />
-
<ActionMenu
-
icon="lucide--x"
-
label="Remove account"
-
onClick={() => removeSession(props.did)}
-
/>
-
</DropdownMenu>
-
</MenuProvider>
-
);
-
};
-
-
export const AccountManager = () => {
-
const [openManager, setOpenManager] = createSignal(false);
-
const [avatars, setAvatars] = createStore<Record<Did, string>>();
-
-
onMount(async () => {
-
try {
-
await retrieveSession();
-
} catch {}
-
-
const localSessions = localStorage.getItem("sessions");
-
if (localSessions) {
-
const storedSessions: Sessions = JSON.parse(localSessions);
-
const sessionDids = Object.keys(storedSessions) as Did[];
-
sessionDids.forEach(async (did) => {
-
const doc = await resolveDidDoc(did);
-
const alias = doc.alsoKnownAs?.find((alias) => alias.startsWith("at://"));
-
if (alias) {
-
setSessions(did, {
-
signedIn: storedSessions[did].signedIn,
-
handle: alias.replace("at://", ""),
-
});
-
}
-
});
-
sessionDids.forEach(async (did) => {
-
const avatar = await getAvatar(did);
-
if (avatar) setAvatars(did, avatar);
-
});
-
}
-
});
-
-
const resumeSession = async (did: Did) => {
-
try {
-
localStorage.setItem("lastSignedIn", did);
-
await retrieveSession();
-
} catch {
-
const authUrl = await createAuthorizationUrl({
-
scope: import.meta.env.VITE_OAUTH_SCOPE,
-
target: { type: "account", identifier: did },
-
});
-
-
await new Promise((resolve) => setTimeout(resolve, 250));
-
-
location.assign(authUrl);
-
}
-
};
-
-
const getAvatar = async (did: Did) => {
-
const rpc = new Client({
-
handler: new CredentialManager({ service: "https://public.api.bsky.app" }),
-
});
-
const res = await rpc.get("app.bsky.actor.getProfile", { params: { actor: did } });
-
if (res.ok) {
-
return res.data.avatar;
-
}
-
return undefined;
-
};
-
-
return (
-
<>
-
<Modal open={openManager()} onClose={() => setOpenManager(false)}>
-
<div class="dark:bg-dark-300 dark:shadow-dark-700 absolute top-18 left-[50%] w-88 -translate-x-1/2 rounded-lg border-[0.5px] border-neutral-300 bg-neutral-50 p-4 shadow-md transition-opacity duration-200 dark:border-neutral-700 starting:opacity-0">
-
<div class="mb-2 px-1 font-semibold">
-
<span>Manage accounts</span>
-
</div>
-
<div class="mb-3 max-h-80 overflow-y-auto md:max-h-100">
-
<For each={Object.keys(sessions)}>
-
{(did) => (
-
<div class="flex w-full items-center justify-between">
-
<A
-
href={`/at://${did}`}
-
onClick={() => setOpenManager(false)}
-
class="flex items-center rounded-md p-1 hover:bg-neutral-200 active:bg-neutral-300 dark:hover:bg-neutral-700 dark:active:bg-neutral-600"
-
>
-
<Show
-
when={avatars[did as Did]}
-
fallback={<span class="iconify lucide--user-round m-0.5 size-5"></span>}
-
>
-
<img
-
src={avatars[did as Did].replace("img/avatar/", "img/avatar_thumbnail/")}
-
class="size-6 rounded-full"
-
/>
-
</Show>
-
</A>
-
<button
-
class="flex grow items-center justify-between gap-1 truncate rounded-md p-1 hover:bg-neutral-200 active:bg-neutral-300 dark:hover:bg-neutral-700 dark:active:bg-neutral-600"
-
onclick={() => resumeSession(did as Did)}
-
>
-
<span class="truncate">
-
{sessions[did]?.handle ? sessions[did].handle : did}
-
</span>
-
<Show when={did === agent()?.sub && sessions[did].signedIn}>
-
<span class="iconify lucide--check shrink-0 text-green-500 dark:text-green-400"></span>
-
</Show>
-
<Show when={!sessions[did].signedIn}>
-
<span class="iconify lucide--circle-alert shrink-0 text-red-500 dark:text-red-400"></span>
-
</Show>
-
</button>
-
<AccountDropdown did={did as Did} />
-
</div>
-
)}
-
</For>
-
</div>
-
<Login />
-
</div>
-
</Modal>
-
<button
-
onclick={() => setOpenManager(true)}
-
class={`flex items-center rounded-lg ${agent() && avatars[agent()!.sub] ? "p-1.25" : "p-1.5"} hover:bg-neutral-200 active:bg-neutral-300 dark:hover:bg-neutral-700 dark:active:bg-neutral-600`}
-
>
-
{agent() && avatars[agent()!.sub] ?
-
<img
-
src={avatars[agent()!.sub].replace("img/avatar/", "img/avatar_thumbnail/")}
-
class="size-5 rounded-full"
-
/>
-
: <span class="iconify lucide--circle-user-round text-lg"></span>}
-
</button>
-
</>
-
);
-
};
-143
src/components/login.tsx
···
-
import { Client } from "@atcute/client";
-
import { Did } from "@atcute/lexicons";
-
import { isDid, isHandle } from "@atcute/lexicons/syntax";
-
import {
-
configureOAuth,
-
createAuthorizationUrl,
-
defaultIdentityResolver,
-
finalizeAuthorization,
-
getSession,
-
OAuthUserAgent,
-
type Session,
-
} from "@atcute/oauth-browser-client";
-
import { createSignal, Show } from "solid-js";
-
import { didDocumentResolver, handleResolver } from "../utils/api";
-
-
configureOAuth({
-
metadata: {
-
client_id: import.meta.env.VITE_OAUTH_CLIENT_ID,
-
redirect_uri: import.meta.env.VITE_OAUTH_REDIRECT_URL,
-
},
-
identityResolver: defaultIdentityResolver({
-
handleResolver: handleResolver,
-
didDocumentResolver: didDocumentResolver,
-
}),
-
});
-
-
export const [agent, setAgent] = createSignal<OAuthUserAgent | undefined>();
-
-
type Account = {
-
signedIn: boolean;
-
handle?: string;
-
};
-
-
export type Sessions = Record<string, Account>;
-
-
const Login = () => {
-
const [notice, setNotice] = createSignal("");
-
const [loginInput, setLoginInput] = createSignal("");
-
-
const login = async (handle: string) => {
-
try {
-
setNotice("");
-
if (!handle) return;
-
setNotice(`Contacting your data server...`);
-
const authUrl = await createAuthorizationUrl({
-
scope: import.meta.env.VITE_OAUTH_SCOPE,
-
target:
-
isHandle(handle) || isDid(handle) ?
-
{ type: "account", identifier: handle }
-
: { type: "pds", serviceUrl: handle },
-
});
-
-
setNotice(`Redirecting...`);
-
await new Promise((resolve) => setTimeout(resolve, 250));
-
-
location.assign(authUrl);
-
} catch (e) {
-
console.error(e);
-
setNotice(`${e}`);
-
}
-
};
-
-
return (
-
<form class="flex flex-col gap-y-2 px-1" onsubmit={(e) => e.preventDefault()}>
-
<label for="username" class="hidden">
-
Add account
-
</label>
-
<div class="dark:bg-dark-100 dark:inset-shadow-dark-200 flex grow items-center gap-2 rounded-lg border-[0.5px] border-neutral-300 bg-white px-2 inset-shadow-xs focus-within:outline-[1px] focus-within:outline-neutral-600 dark:border-neutral-600 dark:focus-within:outline-neutral-400">
-
<label
-
for="username"
-
class="iconify lucide--user-round-plus shrink-0 text-neutral-500 dark:text-neutral-400"
-
></label>
-
<input
-
type="text"
-
spellcheck={false}
-
placeholder="user.bsky.social"
-
id="username"
-
name="username"
-
autocomplete="username"
-
aria-label="Your AT Protocol handle"
-
class="grow py-1 select-none placeholder:text-sm focus:outline-none"
-
onInput={(e) => setLoginInput(e.currentTarget.value)}
-
/>
-
<button
-
onclick={() => login(loginInput())}
-
class="flex items-center rounded-md p-1 hover:bg-neutral-100 active:bg-neutral-200 dark:hover:bg-neutral-600 dark:active:bg-neutral-500"
-
>
-
<span class="iconify lucide--log-in"></span>
-
</button>
-
</div>
-
<Show when={notice()}>
-
<div class="text-sm">{notice()}</div>
-
</Show>
-
</form>
-
);
-
};
-
-
const retrieveSession = async () => {
-
const init = async (): Promise<Session | undefined> => {
-
const params = new URLSearchParams(location.hash.slice(1));
-
-
if (params.has("state") && (params.has("code") || params.has("error"))) {
-
history.replaceState(null, "", location.pathname + location.search);
-
-
const auth = await finalizeAuthorization(params);
-
const did = auth.session.info.sub;
-
-
localStorage.setItem("lastSignedIn", did);
-
-
const sessions = localStorage.getItem("sessions");
-
const newSessions: Sessions = sessions ? JSON.parse(sessions) : { [did]: {} };
-
newSessions[did] = { signedIn: true };
-
localStorage.setItem("sessions", JSON.stringify(newSessions));
-
return auth.session;
-
} else {
-
const lastSignedIn = localStorage.getItem("lastSignedIn");
-
-
if (lastSignedIn) {
-
const sessions = localStorage.getItem("sessions");
-
const newSessions: Sessions = sessions ? JSON.parse(sessions) : {};
-
try {
-
const session = await getSession(lastSignedIn as Did);
-
const rpc = new Client({ handler: new OAuthUserAgent(session) });
-
const res = await rpc.get("com.atproto.server.getSession");
-
newSessions[lastSignedIn].signedIn = true;
-
localStorage.setItem("sessions", JSON.stringify(newSessions));
-
if (!res.ok) throw res.data.error;
-
return session;
-
} catch (err) {
-
newSessions[lastSignedIn].signedIn = false;
-
localStorage.setItem("sessions", JSON.stringify(newSessions));
-
throw err;
-
}
-
}
-
}
-
};
-
-
const session = await init();
-
-
if (session) setAgent(new OAuthUserAgent(session));
-
};
-
-
export { Login, retrieveSession };
+2 -2
src/views/collection.tsx
···
import { ComAtprotoRepoApplyWrites, ComAtprotoRepoGetRecord } from "@atcute/atproto";
-
import { Client, CredentialManager } from "@atcute/client";
+
import { Client, simpleFetchHandler } from "@atcute/client";
import { $type, ActorIdentifier, InferXRPCBodyOutput } from "@atcute/lexicons";
import * as TID from "@atcute/tid";
import { A, useParams } from "@solidjs/router";
···
const fetchRecords = async () => {
if (!pds) pds = await resolvePDS(did!);
-
if (!rpc) rpc = new Client({ handler: new CredentialManager({ service: pds }) });
+
if (!rpc) rpc = new Client({ handler: simpleFetchHandler({ service: pds }) });
const res = await rpc.get("com.atproto.repo.listRecords", {
params: {
repo: did as ActorIdentifier,
public/favicon.ico

This is a binary file and will not be displayed.

public/fonts/Figtree[wght].woff2

This is a binary file and will not be displayed.

+7 -1
src/styles/index.css
···
@custom-variant dark (&:where(.dark, .dark *));
+
@font-face {
+
font-family: "Figtree";
+
src: url("/fonts/Figtree[wght].woff2") format("woff2");
+
font-display: swap;
+
}
+
@theme {
-
--font-sans: "Inter", sans-serif;
+
--font-sans: "Figtree", sans-serif;
--font-mono: "Roboto Mono", monospace;
--font-pecita: "Pecita", serif;
+5 -1
src/auth/account.tsx
···
return (
<MenuProvider>
<DropdownMenu icon="lucide--ellipsis" buttonClass="rounded-md p-2">
-
<NavMenu href={`/at://${props.did}`} label="Go to repo" icon="lucide--user-round" />
+
<NavMenu
+
href={`/at://${props.did}`}
+
label={agent()?.sub === props.did ? "Go to repo (g)" : "Go to repo"}
+
icon="lucide--user-round"
+
/>
<ActionMenu
icon="lucide--settings"
label="Edit permissions"
+109
src/components/create/file-upload.tsx
···
+
import { Client } from "@atcute/client";
+
import { remove } from "@mary/exif-rm";
+
import { createSignal, onCleanup, Show } from "solid-js";
+
import { agent } from "../../auth/state";
+
import { Button } from "../button.jsx";
+
import { TextInput } from "../text-input.jsx";
+
import { editorInstance } from "./state";
+
+
export const FileUpload = (props: {
+
file: File;
+
blobInput: HTMLInputElement;
+
onClose: () => void;
+
}) => {
+
const [uploading, setUploading] = createSignal(false);
+
const [error, setError] = createSignal("");
+
+
onCleanup(() => (props.blobInput.value = ""));
+
+
const formatFileSize = (bytes: number) => {
+
if (bytes === 0) return "0 Bytes";
+
const k = 1024;
+
const sizes = ["Bytes", "KB", "MB", "GB"];
+
const i = Math.floor(Math.log(bytes) / Math.log(k));
+
return Math.round((bytes / Math.pow(k, i)) * 100) / 100 + " " + sizes[i];
+
};
+
+
const uploadBlob = async () => {
+
let blob: Blob;
+
+
const mimetype = (document.getElementById("mimetype") as HTMLInputElement)?.value;
+
(document.getElementById("mimetype") as HTMLInputElement).value = "";
+
if (mimetype) blob = new Blob([props.file], { type: mimetype });
+
else blob = props.file;
+
+
if ((document.getElementById("exif-rm") as HTMLInputElement).checked) {
+
const exifRemoved = remove(new Uint8Array(await blob.arrayBuffer()));
+
if (exifRemoved !== null) blob = new Blob([exifRemoved], { type: blob.type });
+
}
+
+
const rpc = new Client({ handler: agent()! });
+
setUploading(true);
+
const res = await rpc.post("com.atproto.repo.uploadBlob", {
+
input: blob,
+
});
+
setUploading(false);
+
if (!res.ok) {
+
setError(res.data.error);
+
return;
+
}
+
editorInstance.view.dispatch({
+
changes: {
+
from: editorInstance.view.state.selection.main.head,
+
insert: JSON.stringify(res.data.blob, null, 2),
+
},
+
});
+
props.onClose();
+
};
+
+
return (
+
<div class="dark:bg-dark-300 dark:shadow-dark-700 absolute top-70 left-[50%] w-[20rem] -translate-x-1/2 rounded-lg border-[0.5px] border-neutral-300 bg-neutral-50 p-4 shadow-md transition-opacity duration-200 dark:border-neutral-700 starting:opacity-0">
+
<h2 class="mb-2 font-semibold">Upload blob</h2>
+
<div class="flex flex-col gap-2 text-sm">
+
<div class="flex flex-col gap-1">
+
<p class="flex gap-1">
+
<span class="truncate">{props.file.name}</span>
+
<span class="shrink-0 text-neutral-600 dark:text-neutral-400">
+
({formatFileSize(props.file.size)})
+
</span>
+
</p>
+
</div>
+
<div class="flex items-center gap-x-2">
+
<label for="mimetype" class="shrink-0 select-none">
+
MIME type
+
</label>
+
<TextInput id="mimetype" placeholder={props.file.type} />
+
</div>
+
<div class="flex items-center gap-1">
+
<input id="exif-rm" type="checkbox" checked />
+
<label for="exif-rm" class="select-none">
+
Remove EXIF data
+
</label>
+
</div>
+
<p class="text-xs text-neutral-600 dark:text-neutral-400">
+
Metadata will be pasted after the cursor
+
</p>
+
<Show when={error()}>
+
<span class="text-red-500 dark:text-red-400">Error: {error()}</span>
+
</Show>
+
<div class="flex justify-between gap-2">
+
<Button onClick={props.onClose}>Cancel</Button>
+
<Show when={uploading()}>
+
<div class="flex items-center gap-1">
+
<span class="iconify lucide--loader-circle animate-spin"></span>
+
<span>Uploading</span>
+
</div>
+
</Show>
+
<Show when={!uploading()}>
+
<Button
+
onClick={uploadBlob}
+
class="dark:shadow-dark-700 flex items-center gap-1 rounded-lg bg-blue-500 px-2 py-1.5 text-xs text-white shadow-xs select-none hover:bg-blue-600 active:bg-blue-700 dark:bg-blue-600 dark:hover:bg-blue-500 dark:active:bg-blue-400"
+
>
+
Upload
+
</Button>
+
</Show>
+
</div>
+
</div>
+
</div>
+
);
+
};
+87
src/components/create/handle-input.tsx
···
+
import { Handle } from "@atcute/lexicons";
+
import { createSignal, Show } from "solid-js";
+
import { resolveHandle } from "../../utils/api";
+
import { Button } from "../button.jsx";
+
import { TextInput } from "../text-input.jsx";
+
import { editorInstance } from "./state";
+
+
export const HandleInput = (props: { onClose: () => void }) => {
+
const [resolving, setResolving] = createSignal(false);
+
const [error, setError] = createSignal("");
+
let handleFormRef!: HTMLFormElement;
+
+
const resolveDid = async (e: SubmitEvent) => {
+
e.preventDefault();
+
const formData = new FormData(handleFormRef);
+
const handleValue = formData.get("handle")?.toString().trim();
+
+
if (!handleValue) {
+
setError("Please enter a handle");
+
return;
+
}
+
+
setResolving(true);
+
setError("");
+
try {
+
const did = await resolveHandle(handleValue as Handle);
+
editorInstance.view.dispatch({
+
changes: {
+
from: editorInstance.view.state.selection.main.head,
+
insert: `"${did}"`,
+
},
+
});
+
props.onClose();
+
handleFormRef.reset();
+
} catch (err: any) {
+
setError(err.message || "Failed to resolve handle");
+
} finally {
+
setResolving(false);
+
}
+
};
+
+
return (
+
<div class="dark:bg-dark-300 dark:shadow-dark-700 absolute top-70 left-[50%] w-[20rem] -translate-x-1/2 rounded-lg border-[0.5px] border-neutral-300 bg-neutral-50 p-4 shadow-md transition-opacity duration-200 dark:border-neutral-700 starting:opacity-0">
+
<h2 class="mb-2 font-semibold">Insert DID from handle</h2>
+
<form ref={handleFormRef} onSubmit={resolveDid} class="flex flex-col gap-2 text-sm">
+
<div class="flex flex-col gap-1">
+
<label for="handle-input" class="select-none">
+
Handle
+
</label>
+
<TextInput id="handle-input" name="handle" placeholder="user.bsky.social" />
+
</div>
+
<p class="text-xs text-neutral-600 dark:text-neutral-400">
+
DID will be pasted after the cursor
+
</p>
+
<Show when={error()}>
+
<span class="text-red-500 dark:text-red-400">Error: {error()}</span>
+
</Show>
+
<div class="flex justify-between gap-2">
+
<Button
+
type="button"
+
onClick={() => {
+
props.onClose();
+
handleFormRef.reset();
+
setError("");
+
}}
+
>
+
Cancel
+
</Button>
+
<Show when={resolving()}>
+
<div class="flex items-center gap-1">
+
<span class="iconify lucide--loader-circle animate-spin"></span>
+
<span>Resolving</span>
+
</div>
+
</Show>
+
<Show when={!resolving()}>
+
<Button
+
type="submit"
+
class="dark:shadow-dark-700 flex items-center gap-1 rounded-lg bg-blue-500 px-2 py-1.5 text-xs text-white shadow-xs select-none hover:bg-blue-600 active:bg-blue-700 dark:bg-blue-600 dark:hover:bg-blue-500 dark:active:bg-blue-400"
+
>
+
Insert
+
</Button>
+
</Show>
+
</div>
+
</form>
+
</div>
+
);
+
};
+12
src/components/create/menu-item.tsx
···
+
export const MenuItem = (props: { icon: string; label: string; onClick: () => void }) => {
+
return (
+
<button
+
type="button"
+
class="flex items-center gap-2 rounded-md p-2 text-left text-xs hover:bg-neutral-100 active:bg-neutral-200 dark:hover:bg-neutral-700 dark:active:bg-neutral-600"
+
onClick={props.onClick}
+
>
+
<span class={`iconify ${props.icon}`}></span>
+
<span>{props.label}</span>
+
</button>
+
);
+
};
+4
src/components/create/state.ts
···
+
import { createSignal } from "solid-js";
+
+
export const editorInstance = { view: null as any };
+
export const [placeholder, setPlaceholder] = createSignal<any>();
+1 -1
src/views/record.tsx
···
import { agent } from "../auth/state";
import { Backlinks } from "../components/backlinks.jsx";
import { Button } from "../components/button.jsx";
-
import { RecordEditor, setPlaceholder } from "../components/create.jsx";
+
import { RecordEditor, setPlaceholder } from "../components/create";
import {
CopyMenu,
DropdownMenu,
+1 -1
src/components/lexicon-schema.tsx
···
{props.name === "main" ? "Main Definition" : props.name}
</a>
<span class={`rounded px-2 py-0.5 text-xs font-semibold uppercase ${defTypeColor()}`}>
-
{props.def.type}
+
{props.def.type.replace("-", " ")}
</span>
</div>
+1
src/components/editor.tsx
···
keymap.of([indentWithTab]),
linter(jsonParseLinter()),
themeColor.of(document.documentElement.classList.contains("dark") ? basicDark : basicLight),
+
EditorView.lineWrapping,
],
});
editorInstance.view = view;
+29 -48
src/components/create/index.tsx
···
import { addNotification, removeNotification } from "../notification.jsx";
import { TextInput } from "../text-input.jsx";
import Tooltip from "../tooltip.jsx";
+
import { ConfirmSubmit } from "./confirm-submit";
import { FileUpload } from "./file-upload";
import { HandleInput } from "./handle-input";
import { MenuItem } from "./menu-item";
···
const [openUpload, setOpenUpload] = createSignal(false);
const [openInsertMenu, setOpenInsertMenu] = createSignal(false);
const [openHandleDialog, setOpenHandleDialog] = createSignal(false);
-
const [validate, setValidate] = createSignal<boolean | undefined>(undefined);
+
const [openConfirmDialog, setOpenConfirmDialog] = createSignal(false);
const [isMaximized, setIsMaximized] = createSignal(false);
const [isMinimized, setIsMinimized] = createSignal(false);
const [collectionError, setCollectionError] = createSignal("");
···
};
};
-
const getValidateIcon = () => {
-
return (
-
validate() === true ? "lucide--circle-check"
-
: validate() === false ? "lucide--circle-x"
-
: "lucide--circle"
-
);
-
};
-
-
const getValidateLabel = () => {
-
return (
-
validate() === true ? "True"
-
: validate() === false ? "False"
-
: "Unset"
-
);
-
};
-
createEffect(() => {
if (openDialog()) {
-
setValidate(undefined);
setCollectionError("");
setRkeyError("");
}
});
-
const createRecord = async (formData: FormData) => {
+
const createRecord = async (validate: boolean | undefined) => {
+
const formData = new FormData(formRef);
const repo = formData.get("repo")?.toString();
if (!repo) return;
const rpc = new Client({ handler: new OAuthUserAgent(await getSession(repo as Did)) });
···
collection: collection ? collection.toString() : record.$type,
rkey: rkey?.toString().length ? rkey?.toString() : undefined,
record: record,
-
validate: validate(),
+
validate: validate,
},
});
if (!res.ok) {
setNotice(`${res.data.error}: ${res.data.message}`);
return;
}
+
setOpenConfirmDialog(false);
setOpenDialog(false);
const id = addNotification({
message: "Record created",
···
navigate(`/${res.data.uri}`);
};
-
const editRecord = async (recreate?: boolean) => {
+
const editRecord = async (validate: boolean | undefined, recreate: boolean) => {
const record = editorInstance.view.state.doc.toString();
if (!record) return;
const rpc = new Client({ handler: agent()! });
···
const res = await rpc.post("com.atproto.repo.applyWrites", {
input: {
repo: agent()!.sub,
-
validate: validate(),
+
validate: validate,
writes: [
{
collection: params.collection as `${string}.${string}.${string}`,
···
const res = await rpc.post("com.atproto.repo.applyWrites", {
input: {
repo: agent()!.sub,
-
validate: validate(),
+
validate: validate,
writes: [
{
collection: params.collection as `${string}.${string}.${string}`,
···
return;
}
}
+
setOpenConfirmDialog(false);
setOpenDialog(false);
const id = addNotification({
message: "Record edited",
···
>
<HandleInput onClose={() => setOpenHandleDialog(false)} />
</Modal>
+
<Modal
+
open={openConfirmDialog()}
+
onClose={() => setOpenConfirmDialog(false)}
+
closeOnClick={false}
+
>
+
<ConfirmSubmit
+
isCreate={props.create}
+
onConfirm={(validate, recreate) => {
+
if (props.create) {
+
createRecord(validate);
+
} else {
+
editRecord(validate, recreate);
+
}
+
}}
+
onClose={() => setOpenConfirmDialog(false)}
+
/>
+
</Modal>
<div class="flex items-center justify-end gap-2">
-
<button
-
type="button"
-
class="flex items-center gap-1 rounded-sm p-1.5 text-xs hover:bg-neutral-200 active:bg-neutral-300 dark:hover:bg-neutral-700 dark:active:bg-neutral-600"
-
onClick={() =>
-
setValidate(
-
validate() === true ? false
-
: validate() === false ? undefined
-
: true,
-
)
-
}
-
>
-
<Tooltip text={getValidateLabel()}>
-
<span class={`iconify ${getValidateIcon()}`}></span>
-
</Tooltip>
-
<span>Validate</span>
-
</button>
-
<Show when={!props.create && hasUserScope("create") && hasUserScope("delete")}>
-
<Button onClick={() => editRecord(true)}>Recreate</Button>
-
</Show>
-
<Button
-
onClick={() =>
-
props.create ? createRecord(new FormData(formRef)) : editRecord()
-
}
-
>
-
{props.create ? "Create" : "Edit"}
+
<Button onClick={() => setOpenConfirmDialog(true)}>
+
{props.create ? "Create..." : "Edit..."}
</Button>
</div>
</div>
+2 -2
src/components/create/confirm-submit.tsx
···
return (
<div class="dark:bg-dark-300 dark:shadow-dark-700 absolute top-70 left-[50%] w-[24rem] -translate-x-1/2 rounded-lg border-[0.5px] border-neutral-300 bg-neutral-50 p-4 shadow-md transition-opacity duration-200 dark:border-neutral-700 starting:opacity-0">
-
<h2 class="mb-3 font-semibold">{props.isCreate ? "Create" : "Edit"} record</h2>
<div class="flex flex-col gap-3 text-sm">
+
<h2 class="font-semibold">{props.isCreate ? "Create" : "Edit"} record</h2>
<div class="flex flex-col gap-1.5">
<div class="flex items-center gap-2">
<button
···
</p>
</div>
</Show>
-
<div class="mt-1 flex justify-between gap-2">
+
<div class="flex justify-between gap-2">
<Button onClick={props.onClose}>Cancel</Button>
<Button
onClick={() => props.onConfirm(validate(), recreate())}
+1 -1
src/views/logs.tsx
···
</div>
<div class="flex items-center gap-1.5 text-sm font-medium">
<Show when={validLog() === true}>
-
<span class="iconify lucide--check-circle-2 text-green-500 dark:text-green-400"></span>
+
<span class="iconify lucide--check-circle-2 text-green-600 dark:text-green-400"></span>
<span>Valid log</span>
</Show>
<Show when={validLog() === false}>