Skip to content

Commit 0636696

Browse files
committed
feed mode should be per extension not website via localstorage actually, fix manual fetch
1 parent b591322 commit 0636696

File tree

3 files changed

+32
-50
lines changed

3 files changed

+32
-50
lines changed

components/ManualFetchButton.tsx

Lines changed: 28 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,33 @@
11
import { searchBskyPosts } from "@/lib/bsky";
22
import { currentPosts, loading, error, contentSourceUrl } from "@/lib/signals";
3-
import { useRef, useEffect } from "react";
43

5-
export function ManualFetchButton() {
6-
const controllerRef = useRef<AbortController | null>(null);
7-
8-
useEffect(() => {
9-
return () => {
10-
// Cleanup: abort any pending request when component unmounts
11-
if (controllerRef.current) {
12-
controllerRef.current.abort();
13-
}
14-
};
15-
}, []);
4+
const handleFetch = () => {
5+
loading.value = true;
6+
error.value = "";
167

17-
const handleFetch = async () => {
18-
// Abort previous request if it exists
19-
if (controllerRef.current) {
20-
controllerRef.current.abort();
21-
}
22-
23-
loading.value = true;
24-
error.value = '';
25-
26-
controllerRef.current = new AbortController();
27-
28-
try {
29-
currentPosts.value = await searchBskyPosts(contentSourceUrl.value, controllerRef.current.signal) || [];
30-
loading.value = false;
31-
} catch (err: unknown) {
32-
// Don't set error if it was just aborted
33-
if (err instanceof Error && err.name !== 'AbortError') {
34-
console.error('Error fetching posts:', err);
35-
error.value = err.message || 'Failed to fetch Bluesky posts';
36-
}
37-
loading.value = false;
38-
}
39-
};
8+
searchBskyPosts(contentSourceUrl.value)
9+
.then((fetchedPosts) => {
10+
if (fetchedPosts) {
11+
currentPosts.value = fetchedPosts;
12+
// console.log(currentPosts.value.slice(0, 3));
13+
}
14+
loading.value = false;
15+
})
16+
.catch((err) => {
17+
error.value = err.message || "Failed to fetch Bluesky posts";
18+
loading.value = false;
19+
});
20+
};
4021

41-
return (
42-
<button
43-
className="flex items-center justify-center gap-1.5 px-3 py-1.5 bg-green-100 hover:bg-green-200 dark:bg-green-900/30 dark:hover:bg-green-800/40 text-green-700 dark:text-green-300 rounded-md text-sm font-medium transition-colors"
44-
onClick={handleFetch}
45-
aria-label="Search for Bluesky posts"
46-
>
47-
<Icon name="magnifying" className="h-4 w-4" />
48-
Search Posts
49-
</button>
50-
);
51-
}
22+
export function ManualFetchButton() {
23+
return (
24+
<button
25+
className="flex items-center justify-center gap-1.5 px-3 py-1.5 bg-green-100 hover:bg-green-200 dark:bg-green-900/30 dark:hover:bg-green-800/40 text-green-700 dark:text-green-300 rounded-md text-sm font-medium transition-colors"
26+
onClick={handleFetch}
27+
aria-label="Search for Bluesky posts"
28+
>
29+
<Icon name="magnifying" className="h-4 w-4" />
30+
Search Posts
31+
</button>
32+
);
33+
}

lib/signals.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
import type { PostView } from "@atproto/api/dist/client/types/app/bsky/feed/defs";
22
import { signal } from "@preact/signals";
33

4-
import { signalL } from "@/lib/signal";
4+
import { signalBrowserLocal } from "@/lib/signal";
55

66
export const currentPosts = signal<PostView[]>([]);
77
export const loading = signal(false);
88
export const error = signal<string | null>(null);
99
export const contentSourceUrl = signal<string>("");
1010

11-
export const mode = signalL<"full" | "compact">("mode", "full");
11+
export const mode = signalBrowserLocal<"full" | "compact">("mode", "full");
1212

1313
// Search parameters
1414
export const searchSort = signal<'top' | 'latest'>('top');

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
2-
"name": "extension-atproto-annotations",
3-
"description": "annotations using atproto",
2+
"name": "extension-bluesky-annotations",
3+
"description": "see posts from bluesky on your current page",
44
"private": true,
55
"version": "0.0.1",
66
"type": "module",

0 commit comments

Comments
 (0)