feat: update dependencies to k-ap v0.1.7 and add profileHref utility for user links
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
import { cache } from "react";
|
||||
import { z } from "zod";
|
||||
|
||||
export const UserSchema = z.object({
|
||||
@@ -278,13 +279,14 @@ export const markAllNotificationsRead = (token: string) =>
|
||||
token
|
||||
);
|
||||
|
||||
export const lookupRemoteActor = (handle: string, token: string | null) =>
|
||||
export const lookupRemoteActor = cache((handle: string, token: string | null) =>
|
||||
apiFetch(
|
||||
`/users/lookup?handle=${encodeURIComponent(handle)}`,
|
||||
{ next: { tags: [`remote-actor:${handle}`] } },
|
||||
RemoteActorSchema,
|
||||
token
|
||||
);
|
||||
)
|
||||
);
|
||||
|
||||
export const getRemoteActorPosts = (
|
||||
handle: string,
|
||||
|
||||
@@ -17,6 +17,14 @@ export function fullFediverseHandle(handle: string, actorUrl: string): string {
|
||||
}
|
||||
}
|
||||
|
||||
/** Returns the correct profile URL for an author.
|
||||
* Local users go to /users/:username; remote actors go to /remote-actor?handle=. */
|
||||
export function profileHref(username: string, local: boolean): string {
|
||||
if (local) return `/users/${username}`;
|
||||
const handle = username.startsWith("@") ? username : `@${username}`;
|
||||
return `/remote-actor?handle=${encodeURIComponent(handle)}`;
|
||||
}
|
||||
|
||||
export function buildThoughtThreads(thoughts: Thought[]): ThoughtThreadType[] {
|
||||
const thoughtMap = new Map<string, Thought>();
|
||||
thoughts.forEach((t) => thoughtMap.set(t.id, t));
|
||||
|
||||
Reference in New Issue
Block a user