birdclaw 0.6.0 → 0.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +48 -0
- package/README.md +25 -0
- package/package.json +6 -1
- package/src/cli.ts +438 -26
- package/src/components/AppNav.tsx +10 -0
- package/src/components/MarkdownViewer.tsx +438 -72
- package/src/components/ProfileAnalysisStream.tsx +428 -0
- package/src/components/ProfilePreview.tsx +120 -9
- package/src/components/SavedTimelineView.tsx +30 -8
- package/src/components/SyncNowButton.tsx +5 -2
- package/src/components/TimelineCard.tsx +20 -4
- package/src/components/TimelineRouteFrame.tsx +16 -0
- package/src/components/TweetRichText.tsx +36 -12
- package/src/components/useTimelineRouteData.ts +74 -6
- package/src/lib/account-sync-job.ts +15 -3
- package/src/lib/archive-finder.ts +1 -1
- package/src/lib/archive-import.ts +245 -7
- package/src/lib/authored-live.ts +1 -0
- package/src/lib/avatar-cache.ts +50 -0
- package/src/lib/backup.ts +4 -3
- package/src/lib/bird.ts +33 -0
- package/src/lib/config.ts +35 -2
- package/src/lib/data-sources.ts +219 -0
- package/src/lib/db.ts +62 -1
- package/src/lib/geocoding.ts +296 -0
- package/src/lib/location.ts +137 -0
- package/src/lib/mention-threads-live.ts +94 -1
- package/src/lib/mentions-live.ts +187 -40
- package/src/lib/network-map.ts +382 -0
- package/src/lib/period-digest.ts +377 -13
- package/src/lib/profile-analysis.ts +1272 -0
- package/src/lib/profile-bio-entities.ts +1 -1
- package/src/lib/queries.ts +14 -4
- package/src/lib/search-discussion.ts +1016 -0
- package/src/lib/timeline-live.ts +272 -19
- package/src/lib/tweet-account-edges.ts +2 -0
- package/src/lib/tweet-render.ts +141 -1
- package/src/lib/tweet-search-live.ts +565 -0
- package/src/lib/types.ts +37 -2
- package/src/lib/ui.ts +1 -1
- package/src/lib/web-sync.ts +7 -2
- package/src/lib/xurl-rate-limits.ts +267 -0
- package/src/lib/xurl.ts +551 -41
- package/src/routeTree.gen.ts +231 -0
- package/src/routes/__root.tsx +5 -6
- package/src/routes/api/data-sources.tsx +24 -0
- package/src/routes/api/network-map.tsx +55 -0
- package/src/routes/api/period-digest.tsx +11 -1
- package/src/routes/api/profile-analysis.tsx +152 -0
- package/src/routes/api/query.tsx +1 -0
- package/src/routes/api/search-discussion.tsx +169 -0
- package/src/routes/api/xurl-rate-limits.tsx +24 -0
- package/src/routes/data-sources.tsx +255 -0
- package/src/routes/discuss.tsx +419 -0
- package/src/routes/network-map.tsx +1035 -0
- package/src/routes/profile-analyze.tsx +112 -0
- package/src/routes/profiles.$handle.tsx +228 -0
- package/src/routes/rate-limits.tsx +309 -0
- package/src/routes/today.tsx +22 -8
- package/src/styles.css +22 -0
|
@@ -0,0 +1,428 @@
|
|
|
1
|
+
import { CheckCircle2, Loader2, Sparkles } from "lucide-react";
|
|
2
|
+
import { useCallback, useEffect, useRef, useState } from "react";
|
|
3
|
+
import { MarkdownViewer } from "#/components/MarkdownViewer";
|
|
4
|
+
import type {
|
|
5
|
+
ProfileAnalysisContext,
|
|
6
|
+
ProfileAnalysisRunResult,
|
|
7
|
+
ProfileAnalysisStreamEvent,
|
|
8
|
+
} from "#/lib/profile-analysis";
|
|
9
|
+
import type { ProfileRecord } from "#/lib/types";
|
|
10
|
+
import { errorCopyClass } from "#/lib/ui";
|
|
11
|
+
|
|
12
|
+
export interface ProfileAnalysisRequestOptions {
|
|
13
|
+
refresh: boolean;
|
|
14
|
+
maxTweets: number;
|
|
15
|
+
maxPages: number;
|
|
16
|
+
maxConversations: number;
|
|
17
|
+
maxConversationPages: number;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export interface ProfileAnalysisState {
|
|
21
|
+
context: ProfileAnalysisContext | null;
|
|
22
|
+
error: string | null;
|
|
23
|
+
loading: boolean;
|
|
24
|
+
markdown: string;
|
|
25
|
+
result: ProfileAnalysisRunResult | null;
|
|
26
|
+
run: (refresh?: boolean, overrideHandle?: string) => void;
|
|
27
|
+
status: string;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export const DEFAULT_PROFILE_ANALYSIS_LIMITS = {
|
|
31
|
+
maxTweets: 10000,
|
|
32
|
+
maxPages: 100,
|
|
33
|
+
maxConversations: 80,
|
|
34
|
+
maxConversationPages: 3,
|
|
35
|
+
} as const;
|
|
36
|
+
|
|
37
|
+
const PROFILE_HYDRATION_LIMIT = 50;
|
|
38
|
+
const PROFILE_MENTION_RE = /(^|[^\w@./])@([A-Za-z0-9_]{1,15})\b/g;
|
|
39
|
+
|
|
40
|
+
function normalizeProfileHandle(value: string) {
|
|
41
|
+
return value.trim().replace(/^@/, "").toLowerCase();
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
function handlesFromText(value: string) {
|
|
45
|
+
return Array.from(value.matchAll(PROFILE_MENTION_RE)).map(
|
|
46
|
+
(match) => match[2],
|
|
47
|
+
);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
function knownProfileHandles(context: ProfileAnalysisContext) {
|
|
51
|
+
const handles = new Set<string>();
|
|
52
|
+
handles.add(normalizeProfileHandle(context.profile.handle));
|
|
53
|
+
for (const profile of context.profiles ?? []) {
|
|
54
|
+
handles.add(normalizeProfileHandle(profile.handle));
|
|
55
|
+
}
|
|
56
|
+
for (const tweet of context.conversations) {
|
|
57
|
+
handles.add(normalizeProfileHandle(tweet.author));
|
|
58
|
+
}
|
|
59
|
+
return handles;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
function collectProfileAnalysisHydrationHandles({
|
|
63
|
+
context,
|
|
64
|
+
analysis,
|
|
65
|
+
markdown,
|
|
66
|
+
}: {
|
|
67
|
+
context: ProfileAnalysisContext;
|
|
68
|
+
analysis?: ProfileAnalysisRunResult["analysis"];
|
|
69
|
+
markdown?: string;
|
|
70
|
+
}) {
|
|
71
|
+
const handles = new Set<string>();
|
|
72
|
+
const known = knownProfileHandles(context);
|
|
73
|
+
const add = (value: string | undefined) => {
|
|
74
|
+
if (!value) return;
|
|
75
|
+
const handle = normalizeProfileHandle(value);
|
|
76
|
+
if (!/^[a-z0-9_]{1,15}$/.test(handle) || known.has(handle)) return;
|
|
77
|
+
handles.add(handle);
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
for (const handle of analysis?.sourceHandles ?? []) add(handle);
|
|
81
|
+
for (const theme of analysis?.themes ?? []) {
|
|
82
|
+
for (const handle of theme.handles) add(handle);
|
|
83
|
+
}
|
|
84
|
+
if (markdown) {
|
|
85
|
+
for (const handle of handlesFromText(markdown)) add(handle);
|
|
86
|
+
}
|
|
87
|
+
for (const handle of handlesFromText(context.profile.bio)) add(handle);
|
|
88
|
+
for (const tweet of context.tweets) {
|
|
89
|
+
for (const handle of handlesFromText(tweet.text)) add(handle);
|
|
90
|
+
}
|
|
91
|
+
for (const tweet of context.conversations) {
|
|
92
|
+
for (const handle of handlesFromText(tweet.text)) add(handle);
|
|
93
|
+
for (const handle of handlesFromText(tweet.bio)) add(handle);
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
return [...handles].slice(0, PROFILE_HYDRATION_LIMIT);
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
function applyHydratedProfilesToProfileAnalysisContext(
|
|
100
|
+
context: ProfileAnalysisContext,
|
|
101
|
+
profiles: ProfileRecord[],
|
|
102
|
+
) {
|
|
103
|
+
const existing = new Map<string, ProfileRecord>();
|
|
104
|
+
for (const profile of context.profiles ?? []) {
|
|
105
|
+
existing.set(normalizeProfileHandle(profile.handle), profile);
|
|
106
|
+
}
|
|
107
|
+
for (const profile of profiles) {
|
|
108
|
+
existing.set(normalizeProfileHandle(profile.handle), profile);
|
|
109
|
+
}
|
|
110
|
+
return {
|
|
111
|
+
...context,
|
|
112
|
+
profiles: [...existing.values()],
|
|
113
|
+
};
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
async function hydrateProfileAnalysisContext({
|
|
117
|
+
context,
|
|
118
|
+
analysis,
|
|
119
|
+
markdown,
|
|
120
|
+
requestedHandles,
|
|
121
|
+
}: {
|
|
122
|
+
context: ProfileAnalysisContext;
|
|
123
|
+
analysis?: ProfileAnalysisRunResult["analysis"];
|
|
124
|
+
markdown?: string;
|
|
125
|
+
requestedHandles?: Set<string>;
|
|
126
|
+
}) {
|
|
127
|
+
const handles = collectProfileAnalysisHydrationHandles({
|
|
128
|
+
context,
|
|
129
|
+
analysis,
|
|
130
|
+
markdown,
|
|
131
|
+
}).filter((handle) => !requestedHandles?.has(handle));
|
|
132
|
+
if (handles.length === 0) return context;
|
|
133
|
+
for (const handle of handles) {
|
|
134
|
+
requestedHandles?.add(handle);
|
|
135
|
+
}
|
|
136
|
+
const url = new URL("/api/profile-hydrate", window.location.origin);
|
|
137
|
+
url.searchParams.set("handles", handles.join(","));
|
|
138
|
+
const response = await fetch(url);
|
|
139
|
+
if (!response.ok) return context;
|
|
140
|
+
const payload = (await response.json()) as {
|
|
141
|
+
results?: Array<{ status?: string; profile?: ProfileRecord }>;
|
|
142
|
+
};
|
|
143
|
+
const profiles = (payload.results ?? [])
|
|
144
|
+
.filter((item) => item.status === "hit" && item.profile)
|
|
145
|
+
.map((item) => item.profile as ProfileRecord);
|
|
146
|
+
return profiles.length > 0
|
|
147
|
+
? applyHydratedProfilesToProfileAnalysisContext(context, profiles)
|
|
148
|
+
: context;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
export function profileAnalysisUrl(
|
|
152
|
+
handle: string,
|
|
153
|
+
options: ProfileAnalysisRequestOptions,
|
|
154
|
+
) {
|
|
155
|
+
const params = new URLSearchParams();
|
|
156
|
+
params.set("handle", handle);
|
|
157
|
+
params.set("maxTweets", String(options.maxTweets));
|
|
158
|
+
params.set("maxPages", String(options.maxPages));
|
|
159
|
+
params.set("maxConversations", String(options.maxConversations));
|
|
160
|
+
params.set("maxConversationPages", String(options.maxConversationPages));
|
|
161
|
+
if (options.refresh) {
|
|
162
|
+
params.set("refresh", "true");
|
|
163
|
+
}
|
|
164
|
+
return `/api/profile-analysis?${params.toString()}`;
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
export async function profileAnalysisRequestError(response: Response) {
|
|
168
|
+
const status = `${String(response.status)}${response.statusText ? ` ${response.statusText}` : ""}`;
|
|
169
|
+
let detail = "";
|
|
170
|
+
try {
|
|
171
|
+
const contentType = response.headers.get("content-type") ?? "";
|
|
172
|
+
if (contentType.includes("application/json")) {
|
|
173
|
+
const payload = (await response.json()) as {
|
|
174
|
+
error?: unknown;
|
|
175
|
+
message?: unknown;
|
|
176
|
+
};
|
|
177
|
+
if (typeof payload.message === "string") detail = payload.message;
|
|
178
|
+
else if (typeof payload.error === "string") detail = payload.error;
|
|
179
|
+
} else {
|
|
180
|
+
detail = (await response.text()).trim();
|
|
181
|
+
}
|
|
182
|
+
} catch {
|
|
183
|
+
detail = "";
|
|
184
|
+
}
|
|
185
|
+
return new Error(
|
|
186
|
+
detail
|
|
187
|
+
? `Profile analysis failed (${status}): ${detail}`
|
|
188
|
+
: `Profile analysis failed (${status})`,
|
|
189
|
+
);
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
export function formatProfileAnalysisCounts(
|
|
193
|
+
context: ProfileAnalysisContext | null,
|
|
194
|
+
) {
|
|
195
|
+
if (!context) return "xurl profile backfill with cached AI analysis.";
|
|
196
|
+
return [
|
|
197
|
+
context.fetchCached ? "cached backfill" : "fresh xurl backfill",
|
|
198
|
+
`${String(context.counts.tweets)} tweets`,
|
|
199
|
+
`${String(context.counts.conversationTweets)} conversation tweets`,
|
|
200
|
+
`${String(context.counts.conversationsScanned)} conversations`,
|
|
201
|
+
].join(" · ");
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
export function cleanProfileHandle(value: string) {
|
|
205
|
+
return value.trim().replace(/^@/, "");
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
export function useProfileAnalysisStream(handle: string): ProfileAnalysisState {
|
|
209
|
+
const [markdown, setMarkdown] = useState("");
|
|
210
|
+
const [context, setContext] = useState<ProfileAnalysisContext | null>(null);
|
|
211
|
+
const [result, setResult] = useState<ProfileAnalysisRunResult | null>(null);
|
|
212
|
+
const [status, setStatus] = useState("Ready");
|
|
213
|
+
const [error, setError] = useState<string | null>(null);
|
|
214
|
+
const [loading, setLoading] = useState(false);
|
|
215
|
+
const abortRef = useRef<AbortController | null>(null);
|
|
216
|
+
const requestIdRef = useRef(0);
|
|
217
|
+
|
|
218
|
+
const run = useCallback(
|
|
219
|
+
(refresh = false, overrideHandle?: string) => {
|
|
220
|
+
const trimmed = cleanProfileHandle(overrideHandle ?? handle);
|
|
221
|
+
if (!trimmed) return;
|
|
222
|
+
abortRef.current?.abort();
|
|
223
|
+
const controller = new AbortController();
|
|
224
|
+
const requestId = requestIdRef.current + 1;
|
|
225
|
+
requestIdRef.current = requestId;
|
|
226
|
+
abortRef.current = controller;
|
|
227
|
+
const isActiveRequest = () =>
|
|
228
|
+
abortRef.current === controller &&
|
|
229
|
+
requestIdRef.current === requestId &&
|
|
230
|
+
!controller.signal.aborted;
|
|
231
|
+
const requestedHydrationHandles = new Set<string>();
|
|
232
|
+
const hydratedProfilesByHandle = new Map<string, ProfileRecord>();
|
|
233
|
+
const rememberHydratedProfiles = (
|
|
234
|
+
nextContext: ProfileAnalysisContext,
|
|
235
|
+
) => {
|
|
236
|
+
for (const profile of nextContext.profiles ?? []) {
|
|
237
|
+
hydratedProfilesByHandle.set(
|
|
238
|
+
normalizeProfileHandle(profile.handle),
|
|
239
|
+
profile,
|
|
240
|
+
);
|
|
241
|
+
}
|
|
242
|
+
};
|
|
243
|
+
const mergeKnownHydratedProfiles = (
|
|
244
|
+
nextContext: ProfileAnalysisContext,
|
|
245
|
+
) =>
|
|
246
|
+
hydratedProfilesByHandle.size > 0
|
|
247
|
+
? applyHydratedProfilesToProfileAnalysisContext(nextContext, [
|
|
248
|
+
...hydratedProfilesByHandle.values(),
|
|
249
|
+
])
|
|
250
|
+
: nextContext;
|
|
251
|
+
const hydrateContext = (
|
|
252
|
+
nextContext: ProfileAnalysisContext,
|
|
253
|
+
nextResult?: ProfileAnalysisRunResult,
|
|
254
|
+
) => {
|
|
255
|
+
void hydrateProfileAnalysisContext({
|
|
256
|
+
context: nextContext,
|
|
257
|
+
analysis: nextResult?.analysis,
|
|
258
|
+
markdown: nextResult?.markdown,
|
|
259
|
+
requestedHandles: requestedHydrationHandles,
|
|
260
|
+
})
|
|
261
|
+
.then((hydratedContext) => {
|
|
262
|
+
if (!isActiveRequest()) return;
|
|
263
|
+
if (hydratedContext === nextContext) return;
|
|
264
|
+
rememberHydratedProfiles(hydratedContext);
|
|
265
|
+
const mergedContext = mergeKnownHydratedProfiles(hydratedContext);
|
|
266
|
+
setContext(mergedContext);
|
|
267
|
+
if (nextResult) {
|
|
268
|
+
setResult({
|
|
269
|
+
...nextResult,
|
|
270
|
+
context: mergedContext,
|
|
271
|
+
});
|
|
272
|
+
}
|
|
273
|
+
})
|
|
274
|
+
.catch(() => {
|
|
275
|
+
// Profile hover hydration is best-effort; analysis remains usable.
|
|
276
|
+
});
|
|
277
|
+
};
|
|
278
|
+
setMarkdown("");
|
|
279
|
+
setContext(null);
|
|
280
|
+
setResult(null);
|
|
281
|
+
setError(null);
|
|
282
|
+
setLoading(true);
|
|
283
|
+
setStatus("Starting profile analysis");
|
|
284
|
+
|
|
285
|
+
fetch(
|
|
286
|
+
profileAnalysisUrl(trimmed, {
|
|
287
|
+
refresh,
|
|
288
|
+
...DEFAULT_PROFILE_ANALYSIS_LIMITS,
|
|
289
|
+
}),
|
|
290
|
+
{ signal: controller.signal },
|
|
291
|
+
)
|
|
292
|
+
.then(async (response) => {
|
|
293
|
+
if (!response.ok) {
|
|
294
|
+
throw await profileAnalysisRequestError(response);
|
|
295
|
+
}
|
|
296
|
+
if (!response.body) {
|
|
297
|
+
throw new Error("Profile analysis failed: empty response body");
|
|
298
|
+
}
|
|
299
|
+
const reader = response.body.getReader();
|
|
300
|
+
const decoder = new TextDecoder();
|
|
301
|
+
let buffer = "";
|
|
302
|
+
const pump = (): Promise<void> =>
|
|
303
|
+
reader.read().then(({ done, value }) => {
|
|
304
|
+
if (!isActiveRequest()) return;
|
|
305
|
+
if (done) return;
|
|
306
|
+
buffer += decoder.decode(value, { stream: true });
|
|
307
|
+
let newline = buffer.indexOf("\n");
|
|
308
|
+
while (newline >= 0) {
|
|
309
|
+
const line = buffer.slice(0, newline).trim();
|
|
310
|
+
buffer = buffer.slice(newline + 1);
|
|
311
|
+
if (line) {
|
|
312
|
+
const event = JSON.parse(line) as ProfileAnalysisStreamEvent;
|
|
313
|
+
if (!isActiveRequest()) return;
|
|
314
|
+
if (event.type === "status") {
|
|
315
|
+
setStatus(
|
|
316
|
+
event.detail
|
|
317
|
+
? `${event.label} · ${event.detail}`
|
|
318
|
+
: event.label,
|
|
319
|
+
);
|
|
320
|
+
} else if (event.type === "start") {
|
|
321
|
+
setContext(event.context);
|
|
322
|
+
setStatus(
|
|
323
|
+
event.cached
|
|
324
|
+
? "Loading cached analysis"
|
|
325
|
+
: "Summarizing profile",
|
|
326
|
+
);
|
|
327
|
+
hydrateContext(event.context);
|
|
328
|
+
} else if (event.type === "delta") {
|
|
329
|
+
setMarkdown((current) => current + event.delta);
|
|
330
|
+
} else if (event.type === "done") {
|
|
331
|
+
const mergedContext = mergeKnownHydratedProfiles(
|
|
332
|
+
event.result.context,
|
|
333
|
+
);
|
|
334
|
+
const mergedResult =
|
|
335
|
+
mergedContext === event.result.context
|
|
336
|
+
? event.result
|
|
337
|
+
: {
|
|
338
|
+
...event.result,
|
|
339
|
+
context: mergedContext,
|
|
340
|
+
};
|
|
341
|
+
setResult(mergedResult);
|
|
342
|
+
setContext(mergedContext);
|
|
343
|
+
setMarkdown(event.result.markdown);
|
|
344
|
+
setStatus(event.result.cached ? "Cached" : "Complete");
|
|
345
|
+
hydrateContext(mergedContext, mergedResult);
|
|
346
|
+
} else if (event.type === "error") {
|
|
347
|
+
setError(event.error);
|
|
348
|
+
}
|
|
349
|
+
}
|
|
350
|
+
newline = buffer.indexOf("\n");
|
|
351
|
+
}
|
|
352
|
+
return pump();
|
|
353
|
+
});
|
|
354
|
+
return pump();
|
|
355
|
+
})
|
|
356
|
+
.catch((cause: unknown) => {
|
|
357
|
+
if (!isActiveRequest()) return;
|
|
358
|
+
setError(cause instanceof Error ? cause.message : "Analysis failed");
|
|
359
|
+
})
|
|
360
|
+
.finally(() => {
|
|
361
|
+
if (!isActiveRequest()) return;
|
|
362
|
+
setLoading(false);
|
|
363
|
+
});
|
|
364
|
+
},
|
|
365
|
+
[handle],
|
|
366
|
+
);
|
|
367
|
+
|
|
368
|
+
useEffect(
|
|
369
|
+
() => () => {
|
|
370
|
+
abortRef.current?.abort();
|
|
371
|
+
},
|
|
372
|
+
[],
|
|
373
|
+
);
|
|
374
|
+
|
|
375
|
+
return { context, error, loading, markdown, result, run, status };
|
|
376
|
+
}
|
|
377
|
+
|
|
378
|
+
export function ProfileAnalysisStatusLine({
|
|
379
|
+
analysis,
|
|
380
|
+
className = "",
|
|
381
|
+
}: {
|
|
382
|
+
analysis: ProfileAnalysisState;
|
|
383
|
+
className?: string;
|
|
384
|
+
}) {
|
|
385
|
+
return (
|
|
386
|
+
<div
|
|
387
|
+
className={`flex items-center gap-2 text-[13px] font-medium text-[var(--ink-soft)] ${className}`}
|
|
388
|
+
>
|
|
389
|
+
{analysis.loading ? (
|
|
390
|
+
<Loader2 className="size-4 animate-spin" strokeWidth={1.8} />
|
|
391
|
+
) : analysis.result ? (
|
|
392
|
+
<CheckCircle2 className="size-4" strokeWidth={1.8} />
|
|
393
|
+
) : (
|
|
394
|
+
<Sparkles className="size-4" strokeWidth={1.8} />
|
|
395
|
+
)}
|
|
396
|
+
<span>{analysis.status}</span>
|
|
397
|
+
</div>
|
|
398
|
+
);
|
|
399
|
+
}
|
|
400
|
+
|
|
401
|
+
export function ProfileAnalysisOutput({
|
|
402
|
+
analysis,
|
|
403
|
+
emptyLabel = "No profile selected.",
|
|
404
|
+
}: {
|
|
405
|
+
analysis: ProfileAnalysisState;
|
|
406
|
+
emptyLabel?: string;
|
|
407
|
+
}) {
|
|
408
|
+
return (
|
|
409
|
+
<>
|
|
410
|
+
{analysis.error ? (
|
|
411
|
+
<div className={errorCopyClass}>{analysis.error}</div>
|
|
412
|
+
) : null}
|
|
413
|
+
|
|
414
|
+
{analysis.markdown ? (
|
|
415
|
+
<div className="max-w-3xl">
|
|
416
|
+
<MarkdownViewer
|
|
417
|
+
context={analysis.context}
|
|
418
|
+
markdown={analysis.markdown}
|
|
419
|
+
/>
|
|
420
|
+
</div>
|
|
421
|
+
) : (
|
|
422
|
+
<div className="rounded-[8px] border border-[var(--line)] bg-[var(--panel)] p-6 text-[14px] text-[var(--ink-soft)]">
|
|
423
|
+
{emptyLabel}
|
|
424
|
+
</div>
|
|
425
|
+
)}
|
|
426
|
+
</>
|
|
427
|
+
);
|
|
428
|
+
}
|
|
@@ -1,5 +1,15 @@
|
|
|
1
|
-
import
|
|
1
|
+
import {
|
|
2
|
+
Fragment,
|
|
3
|
+
type ReactNode,
|
|
4
|
+
useLayoutEffect,
|
|
5
|
+
useRef,
|
|
6
|
+
useState,
|
|
7
|
+
} from "react";
|
|
2
8
|
import { formatCompactNumber } from "#/lib/present";
|
|
9
|
+
import {
|
|
10
|
+
collectTweetSegmentsForText,
|
|
11
|
+
profileDescriptionEntitiesFromXurl,
|
|
12
|
+
} from "#/lib/tweet-render";
|
|
3
13
|
import type { ProfileRecord } from "#/lib/types";
|
|
4
14
|
import {
|
|
5
15
|
cx,
|
|
@@ -11,9 +21,74 @@ import {
|
|
|
11
21
|
profilePreviewMetaClass,
|
|
12
22
|
profilePreviewNameClass,
|
|
13
23
|
profilePreviewTriggerClass,
|
|
24
|
+
tweetLinkClass,
|
|
14
25
|
} from "#/lib/ui";
|
|
26
|
+
import { safeHttpUrl } from "#/lib/url-safety";
|
|
15
27
|
import { AvatarChip } from "./AvatarChip";
|
|
16
28
|
|
|
29
|
+
type VerticalBounds = { top: number; bottom: number };
|
|
30
|
+
|
|
31
|
+
function nearestVerticalClipBounds(element: HTMLElement): VerticalBounds {
|
|
32
|
+
let top = 0;
|
|
33
|
+
let bottom = window.innerHeight;
|
|
34
|
+
for (
|
|
35
|
+
let current = element.parentElement;
|
|
36
|
+
current;
|
|
37
|
+
current = current.parentElement
|
|
38
|
+
) {
|
|
39
|
+
const style = window.getComputedStyle(current);
|
|
40
|
+
if (!/(auto|scroll|hidden|clip)/.test(style.overflowY)) continue;
|
|
41
|
+
const rect = current.getBoundingClientRect();
|
|
42
|
+
top = Math.max(top, rect.top);
|
|
43
|
+
bottom = Math.min(bottom, rect.bottom);
|
|
44
|
+
}
|
|
45
|
+
return { top, bottom };
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
function ProfilePreviewBio({ profile }: { profile: ProfileRecord }) {
|
|
49
|
+
const segments = collectTweetSegmentsForText(
|
|
50
|
+
profile.bio,
|
|
51
|
+
profileDescriptionEntitiesFromXurl(profile.entities),
|
|
52
|
+
);
|
|
53
|
+
let cursor = 0;
|
|
54
|
+
|
|
55
|
+
return (
|
|
56
|
+
<span className={profilePreviewBioClass}>
|
|
57
|
+
{segments.map((segment, index) => {
|
|
58
|
+
if (
|
|
59
|
+
segment.kind !== "url" ||
|
|
60
|
+
segment.start < cursor ||
|
|
61
|
+
segment.end <= segment.start ||
|
|
62
|
+
segment.end > profile.bio.length
|
|
63
|
+
) {
|
|
64
|
+
return null;
|
|
65
|
+
}
|
|
66
|
+
const prefix = profile.bio.slice(cursor, segment.start);
|
|
67
|
+
cursor = segment.end;
|
|
68
|
+
const href = safeHttpUrl(segment.expandedUrl);
|
|
69
|
+
return (
|
|
70
|
+
<Fragment key={`${segment.url}-${String(index)}`}>
|
|
71
|
+
{prefix}
|
|
72
|
+
{href ? (
|
|
73
|
+
<a
|
|
74
|
+
className={tweetLinkClass}
|
|
75
|
+
href={href}
|
|
76
|
+
rel="noreferrer"
|
|
77
|
+
target="_blank"
|
|
78
|
+
>
|
|
79
|
+
{segment.expandedUrl}
|
|
80
|
+
</a>
|
|
81
|
+
) : (
|
|
82
|
+
profile.bio.slice(segment.start, segment.end)
|
|
83
|
+
)}
|
|
84
|
+
</Fragment>
|
|
85
|
+
);
|
|
86
|
+
})}
|
|
87
|
+
{profile.bio.slice(cursor)}
|
|
88
|
+
</span>
|
|
89
|
+
);
|
|
90
|
+
}
|
|
91
|
+
|
|
17
92
|
export function ProfilePreview({
|
|
18
93
|
profile,
|
|
19
94
|
children,
|
|
@@ -23,17 +98,55 @@ export function ProfilePreview({
|
|
|
23
98
|
children: ReactNode;
|
|
24
99
|
className?: string;
|
|
25
100
|
}) {
|
|
101
|
+
const [placeAbove, setPlaceAbove] = useState(false);
|
|
102
|
+
const shellRef = useRef<HTMLSpanElement | null>(null);
|
|
103
|
+
const cardRef = useRef<HTMLSpanElement | null>(null);
|
|
104
|
+
|
|
105
|
+
function updatePlacement() {
|
|
106
|
+
const shell = shellRef.current;
|
|
107
|
+
if (!shell) return;
|
|
108
|
+
const shellRect = shell.getBoundingClientRect();
|
|
109
|
+
const card = cardRef.current;
|
|
110
|
+
const cardRect = card?.getBoundingClientRect();
|
|
111
|
+
const cardHeight = Math.max(
|
|
112
|
+
card?.offsetHeight ?? 0,
|
|
113
|
+
cardRect?.height ?? 0,
|
|
114
|
+
180,
|
|
115
|
+
);
|
|
116
|
+
const bounds = nearestVerticalClipBounds(shell);
|
|
117
|
+
const belowSpace = bounds.bottom - shellRect.bottom;
|
|
118
|
+
const aboveSpace = shellRect.top - bounds.top;
|
|
119
|
+
setPlaceAbove(belowSpace < cardHeight + 18 && aboveSpace >= belowSpace);
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
useLayoutEffect(() => {
|
|
123
|
+
updatePlacement();
|
|
124
|
+
const frame = window.requestAnimationFrame(updatePlacement);
|
|
125
|
+
return () => window.cancelAnimationFrame(frame);
|
|
126
|
+
}, []);
|
|
127
|
+
|
|
26
128
|
return (
|
|
27
|
-
<span
|
|
129
|
+
<span
|
|
130
|
+
ref={shellRef}
|
|
131
|
+
className={cx(profilePreviewClass, "group", className)}
|
|
132
|
+
onFocus={updatePlacement}
|
|
133
|
+
onPointerEnter={updatePlacement}
|
|
134
|
+
>
|
|
28
135
|
<a
|
|
29
136
|
className={profilePreviewTriggerClass}
|
|
30
|
-
href={
|
|
31
|
-
rel="noreferrer"
|
|
32
|
-
target="_blank"
|
|
137
|
+
href={`/profiles/${encodeURIComponent(profile.handle)}`}
|
|
33
138
|
>
|
|
34
139
|
{children}
|
|
35
140
|
</a>
|
|
36
|
-
<span
|
|
141
|
+
<span
|
|
142
|
+
ref={cardRef}
|
|
143
|
+
className={cx(
|
|
144
|
+
profilePreviewCardClass,
|
|
145
|
+
placeAbove
|
|
146
|
+
? "bottom-[calc(100%+8px)] -translate-y-1 group-hover:translate-y-0 group-focus-within:translate-y-0"
|
|
147
|
+
: "top-[calc(100%+8px)] translate-y-1 group-hover:translate-y-0 group-focus-within:translate-y-0",
|
|
148
|
+
)}
|
|
149
|
+
>
|
|
37
150
|
<span className={profilePreviewHeaderClass}>
|
|
38
151
|
<AvatarChip
|
|
39
152
|
avatarUrl={profile.avatarUrl}
|
|
@@ -48,9 +161,7 @@ export function ProfilePreview({
|
|
|
48
161
|
<span className={profilePreviewHandleClass}>@{profile.handle}</span>
|
|
49
162
|
</span>
|
|
50
163
|
</span>
|
|
51
|
-
{profile.bio ?
|
|
52
|
-
<span className={profilePreviewBioClass}>{profile.bio}</span>
|
|
53
|
-
) : null}
|
|
164
|
+
{profile.bio ? <ProfilePreviewBio profile={profile} /> : null}
|
|
54
165
|
<span className={profilePreviewMetaClass}>
|
|
55
166
|
{formatCompactNumber(profile.followersCount)} followers
|
|
56
167
|
</span>
|
|
@@ -41,14 +41,24 @@ export function SavedTimelineView({
|
|
|
41
41
|
searchPlaceholder,
|
|
42
42
|
}: SavedTimelineViewProps) {
|
|
43
43
|
const [search, setSearch] = useState("");
|
|
44
|
-
const {
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
44
|
+
const {
|
|
45
|
+
meta,
|
|
46
|
+
items,
|
|
47
|
+
loading,
|
|
48
|
+
error,
|
|
49
|
+
retry,
|
|
50
|
+
refreshLocalView,
|
|
51
|
+
replyToTweet,
|
|
52
|
+
hasMore,
|
|
53
|
+
loadingMore,
|
|
54
|
+
loadMore,
|
|
55
|
+
} = useTimelineRouteData({
|
|
56
|
+
resource: "home",
|
|
57
|
+
search,
|
|
58
|
+
errorFallback: `${TITLES[filter]} unavailable`,
|
|
59
|
+
likedOnly: filter === "liked",
|
|
60
|
+
bookmarkedOnly: filter === "bookmarked",
|
|
61
|
+
});
|
|
52
62
|
|
|
53
63
|
const subtitle = useMemo(() => {
|
|
54
64
|
if (!meta) {
|
|
@@ -126,6 +136,18 @@ export function SavedTimelineView({
|
|
|
126
136
|
showReplyControls={false}
|
|
127
137
|
/>
|
|
128
138
|
))}
|
|
139
|
+
{!loading && !error && hasMore ? (
|
|
140
|
+
<div className="flex justify-center py-4">
|
|
141
|
+
<button
|
|
142
|
+
className="rounded-full bg-[var(--accent)] px-5 py-1.5 text-[14px] font-bold text-white disabled:opacity-60"
|
|
143
|
+
disabled={loadingMore}
|
|
144
|
+
onClick={loadMore}
|
|
145
|
+
type="button"
|
|
146
|
+
>
|
|
147
|
+
{loadingMore ? "Loading…" : "Load more"}
|
|
148
|
+
</button>
|
|
149
|
+
</div>
|
|
150
|
+
) : null}
|
|
129
151
|
</section>
|
|
130
152
|
</ConversationSurfaceScope>
|
|
131
153
|
</>
|
|
@@ -41,8 +41,11 @@ export function SyncNowButton({
|
|
|
41
41
|
[accounts],
|
|
42
42
|
);
|
|
43
43
|
const accountId = globalAccountId ?? defaultAccountId;
|
|
44
|
-
const accountAwareSync = kind !== "
|
|
45
|
-
const waitingForAccount =
|
|
44
|
+
const accountAwareSync = kind !== "dms";
|
|
45
|
+
const waitingForAccount =
|
|
46
|
+
accountAwareSync &&
|
|
47
|
+
accounts === undefined &&
|
|
48
|
+
(showAccountPicker || kind !== "timeline");
|
|
46
49
|
const birdOnlyWrongAccount =
|
|
47
50
|
!accountAwareSync &&
|
|
48
51
|
accountId !== undefined &&
|