Public
hn_notifier
Viewing readonly version: 1580View latest version
Script
999
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
/** @jsxImportSource https://esm.sh/react@18.2.0 */
import React, { useState } from "https://esm.sh/react@18.2.0";
import { useUrls } from "https://esm.town/v/nbbaier/hn_notifier/frontend/components/ItemContext.tsx";
import type { DBItem } from "https://esm.town/v/nbbaier/hn_notifier/shared/types.ts";
import { HN_BASE_URL } from "https://esm.town/v/nbbaier/hn_notifier/shared/utils.ts";
interface SectionProps {
type: "stories" | "comments";
}
const Section: React.FC<SectionProps> = ({ type }) => {
const [isOpen, setIsOpen] = useState(false); // Default to collapsed
const { items, unfollowUrl, isLoading } = useUrls();
// Filter items based on type if needed
// This is a placeholder - adjust the filtering logic based on your actual data structure
const filteredUrls = items.filter(item => {
if (type === "stories") {
return item.type === "story"; // Assuming there's an is_comment field
} else {
return item.type === "comment";
}
});
async function handleClick(id: number) {
await unfollowUrl(id);
}
return (
<section className="flex flex-col w-full gap-2 mb-8">
<h2
className="flex flex-row items-center gap-2 pb-2 m-0 mb-2 font-medium leading-5 border-b border-stone-300 text-neutral-900 cursor-pointer"
onClick={() => setIsOpen(!isOpen)} // Add toggle function
>
{type.charAt(0).toUpperCase() + type.slice(1)}
<span className="text-red-500 flex items-center">