Skip to content

Commit

Permalink
Show total count in feed list
Browse files Browse the repository at this point in the history
  • Loading branch information
synzen committed Dec 29, 2024
1 parent 4e352e3 commit d4873ff
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 62 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Box, Center, Checkbox, Divider, Spinner, Stack, chakra } from "@chakra-ui/react";
import { Box, Center, Checkbox, Divider, Spinner, Stack, Text, chakra } from "@chakra-ui/react";
import { useInView } from "react-intersection-observer";
import { useCallback, useEffect } from "react";
import { useUserFeedsInfinite } from "../../hooks/useUserFeedsInfinite";
Expand All @@ -15,6 +15,7 @@ export const SelectableUserFeedList = ({ selectedIds, onSelectedIdsChange }: Pro
useUserFeedsInfinite({
limit: 10,
});
const totalCount = data?.pages[0].total;

const fetchMoreOnBottomReached = useCallback(() => {
if (inView && !isFetchingNextPage && hasNextPage) {
Expand All @@ -26,64 +27,71 @@ export const SelectableUserFeedList = ({ selectedIds, onSelectedIdsChange }: Pro
fetchMoreOnBottomReached();
}, [fetchMoreOnBottomReached]);

const fetchedSoFarCount = data?.pages.reduce((acc, page) => acc + page.results.length, 0) ?? 0;

return (
<Stack
gap={1}
bg="blackAlpha.300"
px={4}
py={3}
borderRadius="md"
maxHeight={350}
border="2px"
borderColor="gray.600"
overflow="auto"
divider={<Divider />}
>
{data?.pages.map((page) => {
if (!page.results.length) {
return null;
}
<Stack>
<Stack
gap={1}
bg="blackAlpha.300"
px={4}
py={3}
borderRadius="md"
maxHeight={350}
border="2px"
borderColor="gray.600"
overflow="auto"
divider={<Divider />}
>
{data?.pages.map((page) => {
if (!page.results.length) {
return null;
}

return (
<Stack gap={1} divider={<Divider />}>
{page.results.map((userFeed) => (
<Box key={`feed-${userFeed.id}`}>
<Checkbox
width="100%"
onChange={(e) => {
if (e.target.checked && !selectedIds.includes(userFeed.id)) {
onSelectedIdsChange([...selectedIds, userFeed.id]);
} else if (!e.target.checked && selectedIds.includes(userFeed.id)) {
onSelectedIdsChange(selectedIds.filter((id) => id !== userFeed.id));
}
}}
isChecked={selectedIds.includes(userFeed.id)}
>
<chakra.span ml={2} display="block" fontSize="sm" fontWeight={600}>
{userFeed.title}
</chakra.span>
<chakra.span
ml={2}
display="block"
color="whiteAlpha.600"
fontSize="sm"
whiteSpace="nowrap"
return (
<Stack gap={1} divider={<Divider />}>
{page.results.map((userFeed) => (
<Box key={`feed-${userFeed.id}`}>
<Checkbox
width="100%"
onChange={(e) => {
if (e.target.checked && !selectedIds.includes(userFeed.id)) {
onSelectedIdsChange([...selectedIds, userFeed.id]);
} else if (!e.target.checked && selectedIds.includes(userFeed.id)) {
onSelectedIdsChange(selectedIds.filter((id) => id !== userFeed.id));
}
}}
isChecked={selectedIds.includes(userFeed.id)}
>
{userFeed.url}
</chakra.span>
</Checkbox>
</Box>
))}
</Stack>
);
})}
{(status === "loading" || isFetchingNextPage) && (
<Center>
<Spinner margin={4} />
</Center>
)}
{error && <InlineErrorAlert title="Failed to list feeds" description={error.message} />}
<div ref={scrollRef} />
<chakra.span ml={2} display="block" fontSize="sm" fontWeight={600}>
{userFeed.title}
</chakra.span>
<chakra.span
ml={2}
display="block"
color="whiteAlpha.600"
fontSize="sm"
whiteSpace="nowrap"
>
{userFeed.url}
</chakra.span>
</Checkbox>
</Box>
))}
</Stack>
);
})}
{(status === "loading" || isFetchingNextPage) && (
<Center>
<Spinner margin={4} />
</Center>
)}
{error && <InlineErrorAlert title="Failed to list feeds" description={error.message} />}
<div ref={scrollRef} />
</Stack>
<Text color="whiteAlpha.600" fontSize="sm">
Showing {fetchedSoFarCount} of {totalCount} feeds
</Text>
</Stack>
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -251,10 +251,6 @@ export const CopyUserFeedSettingsDialog = ({ isOpen, onClose, onCloseRef }: Prop
onSelectedIdsChange={setCheckedUserFeeds}
selectedIds={checkedUserFeeds}
/>
<Text>
Selected {checkedUserFeeds.length}{" "}
{checkedUserFeeds.length === 1 ? "feed" : "feeds"}
</Text>
</Stack>
</Stack>
{error && (
Expand All @@ -280,7 +276,10 @@ export const CopyUserFeedSettingsDialog = ({ isOpen, onClose, onCloseRef }: Prop
checkedSettings.length === 0 || status === "loading"
}
>
<span>Confirm</span>
<span>
Copy to{" "}
{checkedUserFeeds.length === 1 ? "1 feed" : `${checkedUserFeeds.length} feeds`}
</span>
</Button>
</HStack>
</ModalFooter>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -404,7 +404,12 @@ export const CopyDiscordChannelConnectionSettingsDialog = ({
status === "loading"
}
>
<span>Confirm</span>
<span>
Copy to{" "}
{checkedConnections.length === 1
? "1 connection"
: `${checkedConnections.length} connections`}
</span>
</Button>
</HStack>
</ModalFooter>
Expand Down

0 comments on commit d4873ff

Please sign in to comment.