birdclaw 0.8.2 → 0.8.4
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 +33 -0
- package/README.md +10 -8
- package/bin/birdclaw.mjs +4 -66
- package/dist/cli/birdclaw.js +28165 -0
- package/dist/client/assets/AvatarChip-DLoqM5xD.js +1 -0
- package/dist/client/assets/ProfilePreview-BejAuYsJ.js +1 -0
- package/dist/client/assets/SavedTimelineView-BIS7HKpp.js +1 -0
- package/dist/client/assets/SmartTimestamp-BR0-9se2.js +1 -0
- package/dist/client/assets/TimelineRouteFrame-CyGPj0eM.js +1 -0
- package/dist/client/assets/blocks-7UDKQp8H.js +1 -0
- package/dist/client/assets/bookmarks-CbBkMvXk.js +1 -0
- package/dist/client/assets/chunk-C0phanGV.js +1 -0
- package/dist/client/assets/circle-check-C_Vq3ElD.js +1 -0
- package/dist/client/assets/client-stream-contracts-ys3XhWG4.js +5 -0
- package/dist/client/assets/createLucideIcon-JV8isFFR.js +1 -0
- package/dist/client/assets/data-sources-Cm2bpNvg.js +1 -0
- package/dist/client/assets/discuss-DTjaOugw.js +1 -0
- package/dist/client/assets/dms-CGd6Eogq.js +1 -0
- package/dist/client/assets/inbox-BHlGuOy2.js +1 -0
- package/dist/client/assets/index-CEIG7S6s.js +31 -0
- package/dist/client/assets/index-bpFrQ5yG.css +1 -0
- package/dist/client/assets/likes-cLrcAQem.js +1 -0
- package/dist/client/assets/links-CM9QO1LC.js +1 -0
- package/dist/client/assets/mapbox-BxTlqXt9.js +2 -0
- package/dist/client/assets/mapbox-gl-dgf_hX3a.js +3215 -0
- package/dist/client/assets/mentions-CxKCgzIf.js +1 -0
- package/dist/client/assets/network-map-B5a3whqj.js +2 -0
- package/dist/client/assets/profile-analyze-CRtNEwlb.js +1 -0
- package/dist/client/assets/profile-hydration-client-YEtJsNTv.js +1 -0
- package/dist/client/assets/profiles._handle-C82_HoKX.js +1 -0
- package/dist/client/assets/query-client-fYu2rzRC.js +17 -0
- package/dist/client/assets/rate-limits-ScaEwdVK.js +1 -0
- package/dist/client/assets/react-dom-DHl6Ug7F.js +1 -0
- package/dist/client/assets/react-nBylq1U5.js +1 -0
- package/dist/client/assets/repeat-2-xCwHM9hD.js +1 -0
- package/dist/client/assets/routes-q7ZaW4En.js +1 -0
- package/dist/client/assets/schemas-I9r6F6ya.js +64 -0
- package/dist/client/assets/search-Dq5kYsxA.js +1 -0
- package/dist/client/assets/sparkles-CQVlvHsZ.js +1 -0
- package/dist/client/assets/styles-B8s3tt3r.css +2 -0
- package/dist/client/assets/today-CeG1O7Py.js +1 -0
- package/dist/client/assets/triangle-alert-CBL7s2pf.js +1 -0
- package/dist/client/assets/useTimelineRouteData-1HsqgvUi.js +1 -0
- package/dist/client/assets/users-CHbKlqUr.js +1 -0
- package/dist/server/assets/AvatarChip-zUDAEmjL.js +105 -0
- package/dist/server/assets/FeedState-ntW0Q2GB.js +214 -0
- package/dist/server/assets/ProfileAnalysisStream-BFvhVdhn.js +198 -0
- package/dist/server/assets/ProfilePreview-C6gAor_j.js +752 -0
- package/dist/server/assets/SavedTimelineView-BG1jnBp1.js +64 -0
- package/dist/server/assets/SmartTimestamp-DfwE1NGf.js +45 -0
- package/dist/server/assets/SyncNowButton-BOn_IBXS.js +76 -0
- package/dist/server/assets/TimelineRouteFrame-CU7ilM7U.js +85 -0
- package/dist/server/assets/TweetRichText-DhCVv1-6.js +74 -0
- package/dist/server/assets/_tanstack-start-manifest_v-C-ZRnG_n.js +148 -0
- package/dist/server/assets/account-selection-CTdFGWRk.js +44 -0
- package/dist/server/assets/blocks-C1mgGTB3.js +299 -0
- package/dist/server/assets/blocks-DSgQghqP.js +17 -0
- package/dist/server/assets/bookmarks-BJN8tykY.js +14 -0
- package/dist/server/assets/client-stream-contracts-C2xbWVjm.js +769 -0
- package/dist/server/assets/data-sources-BnA1Q94p.js +180 -0
- package/dist/server/assets/discuss-CJ1dau1j.js +15 -0
- package/dist/server/assets/discuss-QTo08NCN.js +338 -0
- package/dist/server/assets/dms-BuLj4bp8.js +368 -0
- package/dist/server/assets/dms-DAyQrVM2.js +240 -0
- package/dist/server/assets/empty-plugin-adapters-DzrEkdBF.js +5 -0
- package/dist/server/assets/inbox-CkGOaW1q.js +214 -0
- package/dist/server/assets/inbox-DpWd1EzC.js +146 -0
- package/dist/server/assets/likes-DBOAtsJU.js +14 -0
- package/dist/server/assets/links-DAhSjynu.js +240 -0
- package/dist/server/assets/links-DmH5lxHO.js +468 -0
- package/dist/server/assets/mentions-BH2MzKtB.js +26 -0
- package/dist/server/assets/network-map-D3CzRcC4.js +224 -0
- package/dist/server/assets/network-map-D5DoLOwR.js +582 -0
- package/dist/server/assets/profile-analyze-BP65PED0.js +90 -0
- package/dist/server/assets/profile-analyze-C1NoM0tV.js +9 -0
- package/dist/server/assets/profile-hydration-client-GJ4kwJS8.js +133 -0
- package/dist/server/assets/profiles._handle-DjwlN_ac.js +184 -0
- package/dist/server/assets/profiles._handle-DsLNj2Ca.js +12 -0
- package/dist/server/assets/query-client-BdauHBgd.js +923 -0
- package/dist/server/assets/rate-limits-VAr2qzYD.js +262 -0
- package/dist/server/assets/route-search-BUlQ5lGM.js +117 -0
- package/dist/server/assets/router-DqkwSPiM.js +17026 -0
- package/dist/server/assets/routes-A9c9ZhwN.js +26 -0
- package/dist/server/assets/start-FaDOTmto.js +4 -0
- package/dist/server/assets/today-B5hVM57Z.js +17 -0
- package/dist/server/assets/today-fvGiZ7ud.js +303 -0
- package/dist/server/assets/ui-qbmcMSSX.js +137 -0
- package/{src/components/useDebouncedValue.ts → dist/server/assets/useDebouncedValue-DOnA6Xcy.js} +4 -4
- package/dist/server/assets/useTimelineRouteData-27cxynxa.js +1101 -0
- package/dist/server/server.js +5520 -0
- package/package.json +27 -34
- package/playwright.config.ts +0 -35
- package/scripts/browser-perf.mjs +0 -427
- package/scripts/build-docs-site.mjs +0 -967
- package/scripts/docs-site-assets.mjs +0 -311
- package/scripts/run-vitest.mjs +0 -21
- package/scripts/sanitize-node-options.mjs +0 -23
- package/scripts/start-test-server.mjs +0 -42
- package/src/cli-moderation.ts +0 -210
- package/src/cli.ts +0 -2336
- package/src/components/AccountSwitcher.tsx +0 -186
- package/src/components/AppNav.tsx +0 -118
- package/src/components/AvatarChip.tsx +0 -58
- package/src/components/BrandMark.tsx +0 -67
- package/src/components/ConversationThread.tsx +0 -131
- package/src/components/DmWorkspace.tsx +0 -286
- package/src/components/EmbeddedTweetCard.tsx +0 -55
- package/src/components/FeedState.tsx +0 -147
- package/src/components/FloatingPreview.tsx +0 -382
- package/src/components/InboxCard.tsx +0 -152
- package/src/components/LinkPreviewCard.tsx +0 -292
- package/src/components/MarkdownViewer.tsx +0 -777
- package/src/components/ProfileAnalysisStream.tsx +0 -428
- package/src/components/ProfilePreview.tsx +0 -129
- package/src/components/SavedTimelineView.tsx +0 -155
- package/src/components/SmartTimestamp.tsx +0 -72
- package/src/components/SyncNowButton.tsx +0 -140
- package/src/components/ThemeSlider.tsx +0 -80
- package/src/components/TimelineCard.tsx +0 -533
- package/src/components/TimelineRouteFrame.tsx +0 -186
- package/src/components/TweetArticleCard.tsx +0 -66
- package/src/components/TweetMediaGrid.tsx +0 -185
- package/src/components/TweetRichText.tsx +0 -159
- package/src/components/account-selection.ts +0 -64
- package/src/components/useTimelineRouteData.ts +0 -323
- package/src/lib/account-sync-job.ts +0 -666
- package/src/lib/actions-transport.ts +0 -300
- package/src/lib/api-client.ts +0 -419
- package/src/lib/archive-finder.ts +0 -185
- package/src/lib/archive-import.ts +0 -2764
- package/src/lib/authored-live.ts +0 -1072
- package/src/lib/avatar-cache.ts +0 -349
- package/src/lib/backup.ts +0 -2741
- package/src/lib/bird-actions.ts +0 -294
- package/src/lib/bird-command.ts +0 -130
- package/src/lib/bird.ts +0 -1140
- package/src/lib/blocklist.ts +0 -136
- package/src/lib/blocks-write.ts +0 -167
- package/src/lib/blocks.ts +0 -389
- package/src/lib/bookmark-sync-job.ts +0 -536
- package/src/lib/client-cache.ts +0 -109
- package/src/lib/config.ts +0 -224
- package/src/lib/conversation-surface.ts +0 -205
- package/src/lib/data-sources.ts +0 -219
- package/src/lib/db.ts +0 -1135
- package/src/lib/dms-live.ts +0 -933
- package/src/lib/effect-runtime.ts +0 -45
- package/src/lib/follow-graph.ts +0 -1097
- package/src/lib/geocoding.ts +0 -296
- package/src/lib/http-effect.ts +0 -222
- package/src/lib/identity-search-index.ts +0 -369
- package/src/lib/inbox.ts +0 -241
- package/src/lib/link-index.ts +0 -641
- package/src/lib/link-insights.ts +0 -860
- package/src/lib/link-preview-metadata.ts +0 -754
- package/src/lib/location.ts +0 -137
- package/src/lib/media-fetch.ts +0 -860
- package/src/lib/media-includes.ts +0 -165
- package/src/lib/mention-threads-live.ts +0 -917
- package/src/lib/mentions-export.ts +0 -147
- package/src/lib/mentions-live.ts +0 -1238
- package/src/lib/moderation-target.ts +0 -216
- package/src/lib/moderation-write.ts +0 -131
- package/src/lib/mutes-write.ts +0 -167
- package/src/lib/mutes.ts +0 -84
- package/src/lib/ndjson-stream.ts +0 -106
- package/src/lib/network-map.ts +0 -382
- package/src/lib/openai.ts +0 -117
- package/src/lib/period-digest.ts +0 -1552
- package/src/lib/present.ts +0 -118
- package/src/lib/profile-affiliation-hydration.ts +0 -228
- package/src/lib/profile-affiliations.ts +0 -262
- package/src/lib/profile-analysis.ts +0 -1272
- package/src/lib/profile-bio-entities.ts +0 -318
- package/src/lib/profile-history.ts +0 -164
- package/src/lib/profile-hydration.ts +0 -180
- package/src/lib/profile-replies.ts +0 -77
- package/src/lib/profile-resolver.ts +0 -650
- package/src/lib/queries.ts +0 -2381
- package/src/lib/research.ts +0 -652
- package/src/lib/search-discussion.ts +0 -1016
- package/src/lib/seed.ts +0 -613
- package/src/lib/sqlite.ts +0 -147
- package/src/lib/sync-cache.ts +0 -65
- package/src/lib/theme-transition.ts +0 -113
- package/src/lib/theme.tsx +0 -165
- package/src/lib/timeline-collections-live.ts +0 -581
- package/src/lib/timeline-live.ts +0 -452
- package/src/lib/tweet-account-edges.ts +0 -48
- package/src/lib/tweet-lookup.ts +0 -46
- package/src/lib/tweet-render.ts +0 -430
- package/src/lib/tweet-search-live.ts +0 -566
- package/src/lib/types.ts +0 -723
- package/src/lib/ui.ts +0 -529
- package/src/lib/url-expansion-store.ts +0 -110
- package/src/lib/url-expansion.ts +0 -343
- package/src/lib/url-safety.ts +0 -220
- package/src/lib/web-sync.ts +0 -516
- package/src/lib/whois.ts +0 -1079
- package/src/lib/x-profile.ts +0 -365
- package/src/lib/x-web.ts +0 -199
- package/src/lib/xurl-rate-limits.ts +0 -267
- package/src/lib/xurl.ts +0 -1677
- package/src/routeTree.gen.ts +0 -723
- package/src/router.tsx +0 -20
- package/src/routes/__root.tsx +0 -79
- package/src/routes/api/action.tsx +0 -147
- package/src/routes/api/avatar.tsx +0 -50
- package/src/routes/api/blocks.tsx +0 -35
- package/src/routes/api/conversation.tsx +0 -45
- package/src/routes/api/data-sources.tsx +0 -24
- package/src/routes/api/inbox.tsx +0 -43
- package/src/routes/api/link-insights.tsx +0 -85
- package/src/routes/api/link-preview.tsx +0 -47
- package/src/routes/api/network-map.tsx +0 -55
- package/src/routes/api/period-digest.tsx +0 -101
- package/src/routes/api/profile-analysis.tsx +0 -97
- package/src/routes/api/profile-hydrate.tsx +0 -54
- package/src/routes/api/query.tsx +0 -115
- package/src/routes/api/search-discussion.tsx +0 -113
- package/src/routes/api/status.tsx +0 -28
- package/src/routes/api/sync.tsx +0 -105
- package/src/routes/api/xurl-rate-limits.tsx +0 -24
- package/src/routes/blocks.tsx +0 -377
- package/src/routes/bookmarks.tsx +0 -18
- package/src/routes/data-sources.tsx +0 -257
- package/src/routes/discuss.tsx +0 -419
- package/src/routes/dms.tsx +0 -432
- package/src/routes/inbox.tsx +0 -226
- package/src/routes/index.tsx +0 -32
- package/src/routes/likes.tsx +0 -18
- package/src/routes/links.tsx +0 -994
- package/src/routes/mentions.tsx +0 -32
- package/src/routes/network-map.tsx +0 -1035
- package/src/routes/profile-analyze.tsx +0 -112
- package/src/routes/profiles.$handle.tsx +0 -228
- package/src/routes/rate-limits.tsx +0 -309
- package/src/routes/today.tsx +0 -511
- package/src/styles.css +0 -257
- package/tsconfig.json +0 -29
- package/vite.config.ts +0 -29
- /package/{public → dist/client}/birdclaw-mark.png +0 -0
- /package/{public → dist/client}/favicon.ico +0 -0
- /package/{public → dist/client}/logo192.png +0 -0
- /package/{public → dist/client}/logo512.png +0 -0
- /package/{public → dist/client}/manifest.json +0 -0
- /package/{public → dist/client}/robots.txt +0 -0
|
@@ -1,323 +0,0 @@
|
|
|
1
|
-
import { useEffect, useRef, useState } from "react";
|
|
2
|
-
import type {
|
|
3
|
-
QueryEnvelope,
|
|
4
|
-
ReplyFilter,
|
|
5
|
-
ResourceKind,
|
|
6
|
-
TimelineItem,
|
|
7
|
-
} from "#/lib/types";
|
|
8
|
-
import {
|
|
9
|
-
fetchCachedQueryResponse,
|
|
10
|
-
fetchQueryEnvelope,
|
|
11
|
-
invalidateCachedQueryResponse,
|
|
12
|
-
invalidateCachedQueryResponses,
|
|
13
|
-
postAction,
|
|
14
|
-
readCachedQueryEnvelope,
|
|
15
|
-
} from "#/lib/api-client";
|
|
16
|
-
import {
|
|
17
|
-
deleteClientCache,
|
|
18
|
-
deleteClientCacheByPrefix,
|
|
19
|
-
readClientCache,
|
|
20
|
-
writeClientCache,
|
|
21
|
-
} from "#/lib/client-cache";
|
|
22
|
-
import { useSelectedAccountId } from "./account-selection";
|
|
23
|
-
import { useDebouncedValue } from "./useDebouncedValue";
|
|
24
|
-
|
|
25
|
-
const PAGE_SIZE = 50;
|
|
26
|
-
const TIMELINE_VIEW_CACHE_PREFIX = "timeline-view:";
|
|
27
|
-
const TIMELINE_VIEW_CACHE_MAX_AGE_MS = 5 * 60_000;
|
|
28
|
-
|
|
29
|
-
interface TimelineViewSnapshot {
|
|
30
|
-
items: TimelineItem[];
|
|
31
|
-
hasMore: boolean;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
interface UseTimelineRouteDataOptions {
|
|
35
|
-
resource: Exclude<ResourceKind, "dms">;
|
|
36
|
-
search: string;
|
|
37
|
-
errorFallback: string;
|
|
38
|
-
replyFilter?: ReplyFilter;
|
|
39
|
-
likedOnly?: boolean;
|
|
40
|
-
bookmarkedOnly?: boolean;
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
function buildTimelineQueryUrl({
|
|
44
|
-
resource,
|
|
45
|
-
search,
|
|
46
|
-
replyFilter,
|
|
47
|
-
likedOnly,
|
|
48
|
-
bookmarkedOnly,
|
|
49
|
-
selectedAccountId,
|
|
50
|
-
refreshTick,
|
|
51
|
-
until,
|
|
52
|
-
untilId,
|
|
53
|
-
}: {
|
|
54
|
-
resource: Exclude<ResourceKind, "dms">;
|
|
55
|
-
search: string;
|
|
56
|
-
replyFilter?: ReplyFilter;
|
|
57
|
-
likedOnly: boolean;
|
|
58
|
-
bookmarkedOnly: boolean;
|
|
59
|
-
selectedAccountId?: string;
|
|
60
|
-
refreshTick: number;
|
|
61
|
-
until?: string;
|
|
62
|
-
untilId?: string;
|
|
63
|
-
}) {
|
|
64
|
-
const params = new URLSearchParams({
|
|
65
|
-
resource,
|
|
66
|
-
limit: String(PAGE_SIZE),
|
|
67
|
-
});
|
|
68
|
-
if (selectedAccountId) params.set("account", selectedAccountId);
|
|
69
|
-
params.set("refresh", String(refreshTick));
|
|
70
|
-
if (replyFilter) params.set("replyFilter", replyFilter);
|
|
71
|
-
if (likedOnly) params.set("liked", "true");
|
|
72
|
-
if (bookmarkedOnly) params.set("bookmarked", "true");
|
|
73
|
-
if (search.trim()) params.set("search", search.trim());
|
|
74
|
-
if (until) params.set("until", until);
|
|
75
|
-
if (untilId) params.set("untilId", untilId);
|
|
76
|
-
params.sort();
|
|
77
|
-
const base =
|
|
78
|
-
typeof window === "undefined"
|
|
79
|
-
? "http://birdclaw.local"
|
|
80
|
-
: window.location.origin;
|
|
81
|
-
return new URL(`/api/query?${params.toString()}`, base).toString();
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
function timelineViewCacheKey(requestUrl: string) {
|
|
85
|
-
const url = new URL(requestUrl, "http://birdclaw.local");
|
|
86
|
-
url.searchParams.delete("refresh");
|
|
87
|
-
return `${TIMELINE_VIEW_CACHE_PREFIX}${url.pathname}?${url.searchParams.toString()}`;
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
export function useTimelineRouteData({
|
|
91
|
-
resource,
|
|
92
|
-
search,
|
|
93
|
-
errorFallback,
|
|
94
|
-
replyFilter,
|
|
95
|
-
likedOnly = false,
|
|
96
|
-
bookmarkedOnly = false,
|
|
97
|
-
}: UseTimelineRouteDataOptions) {
|
|
98
|
-
const [meta, setMeta] = useState<QueryEnvelope | null>(
|
|
99
|
-
() => readCachedQueryEnvelope() ?? null,
|
|
100
|
-
);
|
|
101
|
-
const selectedAccountId = useSelectedAccountId(meta?.accounts);
|
|
102
|
-
const debouncedSearch = useDebouncedValue(search, 180);
|
|
103
|
-
const initialRequestUrl = buildTimelineQueryUrl({
|
|
104
|
-
resource,
|
|
105
|
-
search: debouncedSearch,
|
|
106
|
-
replyFilter,
|
|
107
|
-
likedOnly,
|
|
108
|
-
bookmarkedOnly,
|
|
109
|
-
selectedAccountId,
|
|
110
|
-
refreshTick: 0,
|
|
111
|
-
});
|
|
112
|
-
const initialSnapshot = useRef(
|
|
113
|
-
readClientCache<TimelineViewSnapshot>(
|
|
114
|
-
timelineViewCacheKey(initialRequestUrl),
|
|
115
|
-
TIMELINE_VIEW_CACHE_MAX_AGE_MS,
|
|
116
|
-
),
|
|
117
|
-
);
|
|
118
|
-
const [items, setItems] = useState<TimelineItem[]>(
|
|
119
|
-
() => initialSnapshot.current?.items ?? [],
|
|
120
|
-
);
|
|
121
|
-
const [loading, setLoading] = useState(() => !initialSnapshot.current);
|
|
122
|
-
const [error, setError] = useState<string | null>(null);
|
|
123
|
-
const [replyError, setReplyError] = useState<string | null>(null);
|
|
124
|
-
const [refreshTick, setRefreshTick] = useState(0);
|
|
125
|
-
const [hasMore, setHasMore] = useState(
|
|
126
|
-
() => initialSnapshot.current?.hasMore ?? false,
|
|
127
|
-
);
|
|
128
|
-
const [loadingMore, setLoadingMore] = useState(false);
|
|
129
|
-
// Bumped whenever the active filters change. A `loadMore` request that
|
|
130
|
-
// resolves against a stale generation is discarded so its older page is
|
|
131
|
-
// never appended to a freshly loaded feed.
|
|
132
|
-
const generationRef = useRef(0);
|
|
133
|
-
const loadMoreControllerRef = useRef<AbortController | null>(null);
|
|
134
|
-
const activeRequestUrlRef = useRef(initialRequestUrl);
|
|
135
|
-
|
|
136
|
-
async function loadStatus(force = false) {
|
|
137
|
-
setMeta(await fetchQueryEnvelope(undefined, { force }));
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
useEffect(() => {
|
|
141
|
-
void loadStatus();
|
|
142
|
-
}, []);
|
|
143
|
-
|
|
144
|
-
useEffect(() => {
|
|
145
|
-
generationRef.current += 1;
|
|
146
|
-
loadMoreControllerRef.current?.abort();
|
|
147
|
-
const controller = new AbortController();
|
|
148
|
-
let active = true;
|
|
149
|
-
const requestUrl = buildTimelineQueryUrl({
|
|
150
|
-
resource,
|
|
151
|
-
search: debouncedSearch,
|
|
152
|
-
replyFilter,
|
|
153
|
-
likedOnly,
|
|
154
|
-
bookmarkedOnly,
|
|
155
|
-
selectedAccountId,
|
|
156
|
-
refreshTick,
|
|
157
|
-
});
|
|
158
|
-
const viewCacheKey = timelineViewCacheKey(requestUrl);
|
|
159
|
-
activeRequestUrlRef.current = requestUrl;
|
|
160
|
-
setError(null);
|
|
161
|
-
setLoadingMore(false);
|
|
162
|
-
const cached = readClientCache<TimelineViewSnapshot>(
|
|
163
|
-
viewCacheKey,
|
|
164
|
-
TIMELINE_VIEW_CACHE_MAX_AGE_MS,
|
|
165
|
-
);
|
|
166
|
-
if (cached) {
|
|
167
|
-
setItems(cached.items);
|
|
168
|
-
setHasMore(cached.hasMore);
|
|
169
|
-
setLoading(false);
|
|
170
|
-
return () => {
|
|
171
|
-
active = false;
|
|
172
|
-
controller.abort();
|
|
173
|
-
};
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
setItems([]);
|
|
177
|
-
setHasMore(false);
|
|
178
|
-
setLoading(true);
|
|
179
|
-
fetchCachedQueryResponse(requestUrl, { signal: controller.signal })
|
|
180
|
-
.then((data) => {
|
|
181
|
-
if (!active) return;
|
|
182
|
-
const next = data.items as TimelineItem[];
|
|
183
|
-
setItems(next);
|
|
184
|
-
const nextHasMore = next.length >= PAGE_SIZE;
|
|
185
|
-
setHasMore(nextHasMore);
|
|
186
|
-
writeClientCache(viewCacheKey, {
|
|
187
|
-
items: next,
|
|
188
|
-
hasMore: nextHasMore,
|
|
189
|
-
});
|
|
190
|
-
})
|
|
191
|
-
.catch((fetchError: unknown) => {
|
|
192
|
-
if (
|
|
193
|
-
fetchError instanceof DOMException &&
|
|
194
|
-
fetchError.name === "AbortError"
|
|
195
|
-
) {
|
|
196
|
-
return;
|
|
197
|
-
}
|
|
198
|
-
if (!active) return;
|
|
199
|
-
setError(
|
|
200
|
-
fetchError instanceof Error ? fetchError.message : errorFallback,
|
|
201
|
-
);
|
|
202
|
-
setItems([]);
|
|
203
|
-
setHasMore(false);
|
|
204
|
-
})
|
|
205
|
-
.finally(() => {
|
|
206
|
-
if (active) {
|
|
207
|
-
setLoading(false);
|
|
208
|
-
}
|
|
209
|
-
});
|
|
210
|
-
|
|
211
|
-
return () => {
|
|
212
|
-
active = false;
|
|
213
|
-
controller.abort();
|
|
214
|
-
};
|
|
215
|
-
}, [
|
|
216
|
-
bookmarkedOnly,
|
|
217
|
-
debouncedSearch,
|
|
218
|
-
errorFallback,
|
|
219
|
-
likedOnly,
|
|
220
|
-
refreshTick,
|
|
221
|
-
replyFilter,
|
|
222
|
-
resource,
|
|
223
|
-
selectedAccountId,
|
|
224
|
-
]);
|
|
225
|
-
|
|
226
|
-
async function loadMore() {
|
|
227
|
-
if (loading || loadingMore || !hasMore || items.length === 0) return;
|
|
228
|
-
const lastItem = items[items.length - 1];
|
|
229
|
-
const until = lastItem?.createdAt;
|
|
230
|
-
const untilId = lastItem?.id;
|
|
231
|
-
if (!until || !untilId) return;
|
|
232
|
-
const generation = generationRef.current;
|
|
233
|
-
const controller = new AbortController();
|
|
234
|
-
loadMoreControllerRef.current = controller;
|
|
235
|
-
setLoadingMore(true);
|
|
236
|
-
try {
|
|
237
|
-
const nextPageUrl = new URL(
|
|
238
|
-
activeRequestUrlRef.current,
|
|
239
|
-
window.location.origin,
|
|
240
|
-
);
|
|
241
|
-
nextPageUrl.searchParams.set("until", until);
|
|
242
|
-
nextPageUrl.searchParams.set("untilId", untilId);
|
|
243
|
-
const data = await fetchCachedQueryResponse(nextPageUrl, {
|
|
244
|
-
signal: controller.signal,
|
|
245
|
-
});
|
|
246
|
-
// Discard if the filters changed (new generation) while in flight.
|
|
247
|
-
if (generation !== generationRef.current) return;
|
|
248
|
-
const page = data.items as TimelineItem[];
|
|
249
|
-
setItems((prev) => {
|
|
250
|
-
const seen = new Set(prev.map((item) => item.id));
|
|
251
|
-
const next = [...prev, ...page.filter((item) => !seen.has(item.id))];
|
|
252
|
-
writeClientCache(timelineViewCacheKey(activeRequestUrlRef.current), {
|
|
253
|
-
items: next,
|
|
254
|
-
hasMore: page.length >= PAGE_SIZE,
|
|
255
|
-
});
|
|
256
|
-
return next;
|
|
257
|
-
});
|
|
258
|
-
setHasMore(page.length >= PAGE_SIZE);
|
|
259
|
-
} catch (loadError) {
|
|
260
|
-
if (
|
|
261
|
-
loadError instanceof DOMException &&
|
|
262
|
-
loadError.name === "AbortError"
|
|
263
|
-
) {
|
|
264
|
-
return;
|
|
265
|
-
}
|
|
266
|
-
if (generation !== generationRef.current) return;
|
|
267
|
-
setError(loadError instanceof Error ? loadError.message : errorFallback);
|
|
268
|
-
} finally {
|
|
269
|
-
if (generation === generationRef.current) {
|
|
270
|
-
setLoadingMore(false);
|
|
271
|
-
}
|
|
272
|
-
}
|
|
273
|
-
}
|
|
274
|
-
|
|
275
|
-
function retry() {
|
|
276
|
-
invalidateCachedQueryResponse(activeRequestUrlRef.current);
|
|
277
|
-
deleteClientCache(timelineViewCacheKey(activeRequestUrlRef.current));
|
|
278
|
-
setRefreshTick((value) => value + 1);
|
|
279
|
-
}
|
|
280
|
-
|
|
281
|
-
function refreshLocalView() {
|
|
282
|
-
invalidateCachedQueryResponses();
|
|
283
|
-
deleteClientCacheByPrefix(TIMELINE_VIEW_CACHE_PREFIX);
|
|
284
|
-
setRefreshTick((value) => value + 1);
|
|
285
|
-
void loadStatus(true);
|
|
286
|
-
}
|
|
287
|
-
|
|
288
|
-
async function replyToTweet(tweetId: string) {
|
|
289
|
-
const text = window.prompt("Reply text");
|
|
290
|
-
if (!text?.trim()) return;
|
|
291
|
-
|
|
292
|
-
setReplyError(null);
|
|
293
|
-
try {
|
|
294
|
-
await postAction({
|
|
295
|
-
kind: "replyTweet",
|
|
296
|
-
accountId: selectedAccountId ?? "acct_primary",
|
|
297
|
-
tweetId,
|
|
298
|
-
text,
|
|
299
|
-
});
|
|
300
|
-
|
|
301
|
-
retry();
|
|
302
|
-
} catch (replyError) {
|
|
303
|
-
setReplyError(
|
|
304
|
-
replyError instanceof Error ? replyError.message : "Reply failed",
|
|
305
|
-
);
|
|
306
|
-
}
|
|
307
|
-
}
|
|
308
|
-
|
|
309
|
-
return {
|
|
310
|
-
meta,
|
|
311
|
-
items,
|
|
312
|
-
loading,
|
|
313
|
-
error,
|
|
314
|
-
replyError,
|
|
315
|
-
retry,
|
|
316
|
-
refreshLocalView,
|
|
317
|
-
replyToTweet,
|
|
318
|
-
selectedAccountId,
|
|
319
|
-
hasMore,
|
|
320
|
-
loadingMore,
|
|
321
|
-
loadMore,
|
|
322
|
-
};
|
|
323
|
-
}
|