From 1b929f36ebecda48d4327b9598fce26151f04087 Mon Sep 17 00:00:00 2001 From: nsfisis Date: Sun, 13 Jul 2025 16:01:51 +0900 Subject: refactor(frontend): extract FeedItem from FeedList --- frontend/src/components/FeedItem.tsx | 86 ++++++++++++++++++++++++++++++ frontend/src/components/FeedList.tsx | 100 ++++++----------------------------- 2 files changed, 101 insertions(+), 85 deletions(-) create mode 100644 frontend/src/components/FeedItem.tsx (limited to 'frontend/src/components') diff --git a/frontend/src/components/FeedItem.tsx b/frontend/src/components/FeedItem.tsx new file mode 100644 index 0000000..020825a --- /dev/null +++ b/frontend/src/components/FeedItem.tsx @@ -0,0 +1,86 @@ +import { faCheck, faCircle, faTrash } from "@fortawesome/free-solid-svg-icons"; +import { FontAwesomeIcon } from "@fortawesome/react-fontawesome"; +import { useMutation } from "urql"; +import type { GetFeedsQuery } from "../graphql/generated/graphql"; +import { + MarkFeedReadDocument, + MarkFeedUnreadDocument, + UnsubscribeFeedDocument, +} from "../graphql/generated/graphql"; + +type Feed = NonNullable[0]; + +interface Props { + feed: Feed; + onFeedUnsubscribed?: () => void; +} + +export function FeedItem({ feed, onFeedUnsubscribed }: Props) { + const [, markFeedRead] = useMutation(MarkFeedReadDocument); + const [, markFeedUnread] = useMutation(MarkFeedUnreadDocument); + const [, unsubscribeFeed] = useMutation(UnsubscribeFeedDocument); + + const handleMarkAllRead = async (feedId: string) => { + await markFeedRead({ id: feedId }); + }; + + const handleMarkAllUnread = async (feedId: string) => { + await markFeedUnread({ id: feedId }); + }; + + const handleUnsubscribeFeed = async (feedId: string) => { + const confirmed = window.confirm( + "Are you sure you want to unsubscribe from this feed?", + ); + if (confirmed) { + await unsubscribeFeed({ id: feedId }); + onFeedUnsubscribed?.(); + } + }; + + return ( +
+
+
+

{feed.title}

+

+ + {feed.url} + +

+
+ + Last fetched: {new Date(feed.fetchedAt).toLocaleString()} + +
+
+
+ + + +
+
+
+ ); +} diff --git a/frontend/src/components/FeedList.tsx b/frontend/src/components/FeedList.tsx index db12b13..d1d7bf3 100644 --- a/frontend/src/components/FeedList.tsx +++ b/frontend/src/components/FeedList.tsx @@ -1,12 +1,6 @@ -import { faCheck, faCircle, faTrash } from "@fortawesome/free-solid-svg-icons"; -import { FontAwesomeIcon } from "@fortawesome/react-fontawesome"; -import { useMutation, useQuery } from "urql"; -import { - GetFeedsDocument, - MarkFeedReadDocument, - MarkFeedUnreadDocument, - UnsubscribeFeedDocument, -} from "../graphql/generated/graphql"; +import { useQuery } from "urql"; +import { GetFeedsDocument } from "../graphql/generated/graphql"; +import { FeedItem } from "./FeedItem"; interface Props { onFeedUnsubscribed?: () => void; @@ -17,89 +11,25 @@ export function FeedList({ onFeedUnsubscribed }: Props) { query: GetFeedsDocument, }); - const [, markFeedRead] = useMutation(MarkFeedReadDocument); - const [, markFeedUnread] = useMutation(MarkFeedUnreadDocument); - const [, unsubscribeFeed] = useMutation(UnsubscribeFeedDocument); - - const handleMarkAllRead = async (feedId: string) => { - await markFeedRead({ id: feedId }); - }; - - const handleMarkAllUnread = async (feedId: string) => { - await markFeedUnread({ id: feedId }); - }; - - const handleUnsubscribeFeed = async (feedId: string) => { - const confirmed = window.confirm( - "Are you sure you want to unsubscribe from this feed?", - ); - if (confirmed) { - await unsubscribeFeed({ id: feedId }); - onFeedUnsubscribed?.(); - } - }; - - if (fetching) return
Loading feeds...
; - if (error) + if (fetching) { + return
Loading feeds...
; + } + if (error) { return
Error: {error.message}
; + } if (!data?.feeds || data.feeds.length === 0) { return
No feeds added yet.
; } return (
- {data.feeds.map((feed) => { - return ( -
-
-
-

- {feed.title} -

-

- - {feed.url} - -

-
- - Last fetched: {new Date(feed.fetchedAt).toLocaleString()} - -
-
-
- - - -
-
-
- ); - })} + {data.feeds.map((feed) => ( + + ))}
); } -- cgit v1.2.3-70-g09d2