Refactor Feed comment handling and pass trending tags to composer
cgen-06d108a1ce4a44ef9003101114454363
This commit is contained in:
parent
add0e3aee0
commit
54a50701a2
1 changed files with 9 additions and 28 deletions
|
|
@ -243,33 +243,11 @@ export default function Feed() {
|
||||||
[toast, user?.id],
|
[toast, user?.id],
|
||||||
);
|
);
|
||||||
|
|
||||||
const handleComment = useCallback(
|
const handleComment = useCallback((postId: string) => {
|
||||||
async (postId: string) => {
|
setItems((prev) =>
|
||||||
if (!user?.id) {
|
prev.map((it) => (it.id === postId ? { ...it, comments: it.comments + 1 } : it)),
|
||||||
toast({ description: "Please sign in to comment." });
|
);
|
||||||
return;
|
}, []);
|
||||||
}
|
|
||||||
const content = prompt("Add a comment:")?.trim();
|
|
||||||
if (!content) return;
|
|
||||||
try {
|
|
||||||
const created = await communityService.addComment(
|
|
||||||
postId,
|
|
||||||
user.id,
|
|
||||||
content,
|
|
||||||
);
|
|
||||||
if (created) {
|
|
||||||
setItems((prev) =>
|
|
||||||
prev.map((it) =>
|
|
||||||
it.id === postId ? { ...it, comments: it.comments + 1 } : it,
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
} catch (e) {
|
|
||||||
console.warn("Comment failed", e);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
[toast, user?.id],
|
|
||||||
);
|
|
||||||
|
|
||||||
const filteredItems = useMemo(() => {
|
const filteredItems = useMemo(() => {
|
||||||
if (activeFilter === "following") {
|
if (activeFilter === "following") {
|
||||||
|
|
@ -472,7 +450,10 @@ export default function Feed() {
|
||||||
Compose
|
Compose
|
||||||
</Button>
|
</Button>
|
||||||
</div>
|
</div>
|
||||||
<PostComposer onPosted={() => fetchFeed()} />
|
<PostComposer
|
||||||
|
onPosted={() => fetchFeed()}
|
||||||
|
suggestedTags={trendingTopics.map((t) => t.topic.replace(/^#/, "")).slice(0, 8)}
|
||||||
|
/>
|
||||||
<div className="flex flex-wrap items-center justify-between gap-3 rounded-2xl border border-border/30 bg-background/60 p-4 text-sm text-muted-foreground">
|
<div className="flex flex-wrap items-center justify-between gap-3 rounded-2xl border border-border/30 bg-background/60 p-4 text-sm text-muted-foreground">
|
||||||
<div className="flex items-center gap-2">
|
<div className="flex items-center gap-2">
|
||||||
<Sparkles className="h-4 w-4 text-aethex-300" />
|
<Sparkles className="h-4 w-4 text-aethex-300" />
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue