Skip to content

Commit

Permalink
fix: feed deletion (#4023)
Browse files Browse the repository at this point in the history
  • Loading branch information
rebelchris authored Dec 24, 2024
1 parent 015fb2d commit 7dae2ed
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 9 deletions.
27 changes: 19 additions & 8 deletions packages/shared/src/components/CustomFeedEmptyScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,11 @@ import { HashtagIcon } from './icons';
import { PageContainer } from './utilities';
import { ButtonSize } from './buttons/common';
import { webappUrl } from '../lib/constants';
import { usePlusSubscription } from '../hooks';
import { DeleteCustomFeed } from './buttons/DeleteCustomFeed';

export const CustomFeedEmptyScreen = (): ReactElement => {
const { isPlus } = usePlusSubscription();
const router = useRouter();

return (
Expand All @@ -27,14 +30,22 @@ export const CustomFeedEmptyScreen = (): ReactElement => {
Start by configuring your feed settings to tailor content to your
interests. Add tags, filters, and sources to make it truly yours.
</EmptyScreenDescription>
<EmptyScreenButton
onClick={() => {
router.push(`${webappUrl}feeds/${router.query.slugOrId}/edit`);
}}
size={ButtonSize.Large}
>
Set up feed
</EmptyScreenButton>
<div className="flex flex-col items-center gap-4 tablet:flex-row">
<EmptyScreenButton
onClick={() => {
router.push(`${webappUrl}feeds/${router.query.slugOrId}/edit`);
}}
size={ButtonSize.Large}
>
Set up feed
</EmptyScreenButton>
{!isPlus ? (
<DeleteCustomFeed
className="mt-10"
feedId={router.query.slugOrId as string}
/>
) : null}
</div>
</EmptyScreenContainer>
</PageContainer>
);
Expand Down
35 changes: 35 additions & 0 deletions packages/shared/src/components/buttons/DeleteCustomFeed.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import React, { type ReactElement } from 'react';
import { ButtonSize, ButtonVariant, type ButtonProps, Button } from './Button';
import { SimpleTooltip } from '../tooltips';
import { useFeedSettingsEdit } from '../feeds/FeedSettings/useFeedSettingsEdit';
import { TrashIcon } from '../icons';
import { WithClassNameProps } from '../utilities';

type DeleteCustomFeedProps = {
feedId: string;
} & WithClassNameProps;
export const DeleteCustomFeed = ({
feedId,
className,
}: DeleteCustomFeedProps): ReactElement => {
const { onDelete } = useFeedSettingsEdit({ feedSlugOrId: feedId });

const commonIconProps: ButtonProps<'button'> = {
size: ButtonSize.Medium,
variant: ButtonVariant.Float,
iconSecondaryOnHover: true,
className,
};

return (
<SimpleTooltip
placement="bottom"
content="Delete custom feed"
container={{
className: 'max-w-64 text-center',
}}
>
<Button {...commonIconProps} icon={<TrashIcon />} onClick={onDelete} />
</SimpleTooltip>
);
};
7 changes: 6 additions & 1 deletion packages/shared/src/components/layout/common.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import { useAuthContext } from '../../contexts/AuthContext';
import useCustomDefaultFeed from '../../hooks/feed/useCustomDefaultFeed';
import { useLazyModal } from '../../hooks/useLazyModal';
import { LazyModal } from '../modals/common/types';
import { DeleteCustomFeed } from '../buttons/DeleteCustomFeed';

type State<T> = [T, Dispatch<SetStateAction<T>>];

Expand Down Expand Up @@ -76,7 +77,8 @@ export const SearchControlHeader = ({
const isLaptop = useViewSize(ViewSize.Laptop);
const isMobile = useViewSize(ViewSize.MobileL);
const { streak, isLoading, isStreaksEnabled } = useReadingStreak();
const { showPlusSubscription, isEnrolledNotPlus } = usePlusSubscription();
const { showPlusSubscription, isEnrolledNotPlus, isPlus } =
usePlusSubscription();
const { user } = useAuthContext();
const { isCustomDefaultFeed, defaultFeedId } = useCustomDefaultFeed();
const { openModal } = useLazyModal();
Expand Down Expand Up @@ -157,6 +159,9 @@ export const SearchControlHeader = ({
key="toggle-clickbait-shield"
/>
) : null,
!isPlus && feedName === SharedFeedPage.Custom ? (
<DeleteCustomFeed feedId={router?.query?.slugOrId as string} />
) : null,
];
const actions = actionButtons.filter((button) => !!button);

Expand Down

0 comments on commit 7dae2ed

Please sign in to comment.