Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: cleanup plus to be available to all #4095

Merged
merged 4 commits into from
Jan 23, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 9 additions & 17 deletions packages/shared/src/components/BookmarkFeedLayout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,7 @@ import type { ButtonProps } from './buttons/Button';
import { Button, ButtonVariant } from './buttons/Button';
import { ShareIcon } from './icons';
import { generateQueryKey, OtherFeedPage, RequestKey } from '../lib/query';
import {
useFeedLayout,
usePlusSubscription,
useViewSize,
ViewSize,
} from '../hooks';
import { useFeedLayout, useViewSize, ViewSize } from '../hooks';
import { BookmarkSection } from './sidebar/sections/BookmarkSection';
import {
Typography,
Expand Down Expand Up @@ -73,7 +68,6 @@ export default function BookmarkFeedLayout({
FeedPageLayoutComponent,
shouldUseListMode,
} = useFeedLayout();
const { showPlusSubscription } = usePlusSubscription();
const { user, tokenRefreshed } = useContext(AuthContext);
const [showSharedBookmarks, setShowSharedBookmarks] = useState(false);
const isLaptop = useViewSize(ViewSize.Laptop);
Expand Down Expand Up @@ -166,16 +160,14 @@ export default function BookmarkFeedLayout({
onRequestClose={() => setShowSharedBookmarks(false)}
/>
)}
{showPlusSubscription && (
<div className="mb-4 laptop:hidden">
<BookmarkSection
isItemsButton={false}
sidebarExpanded
shouldShowLabel
activePage=""
/>
</div>
)}
<div className="mb-4 laptop:hidden">
<BookmarkSection
isItemsButton={false}
sidebarExpanded
shouldShowLabel
activePage=""
/>
</div>
{tokenRefreshed && <Feed {...feedProps} />}
</FeedPageLayoutComponent>
);
Expand Down
5 changes: 2 additions & 3 deletions packages/shared/src/components/CustomFeedEmptyScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@ import { usePlusSubscription } from '../hooks';
import { IconSize } from './Icon';

export const CustomFeedEmptyScreen = (): ReactElement => {
const { logSubscriptionEvent, showPlusSubscription, isPlus } =
usePlusSubscription();
const { logSubscriptionEvent, isPlus } = usePlusSubscription();
const [selectedAlgo, setSelectedAlgo] = usePersistentContext(
DEFAULT_ALGORITHM_KEY,
DEFAULT_ALGORITHM_INDEX,
Expand All @@ -45,7 +44,7 @@ export const CustomFeedEmptyScreen = (): ReactElement => {
className={EmptyScreenIcon.className}
style={EmptyScreenIcon.style}
/>
{showPlusSubscription && !isPlus ? (
{!isPlus ? (
<>
<Typography
tag={TypographyTag.Span}
Expand Down
23 changes: 4 additions & 19 deletions packages/shared/src/components/CustomFeedOptionsMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import useContextMenu from '../hooks/useContextMenu';
import { Button, ButtonSize, ButtonVariant } from './buttons/Button';
import type { UseShareOrCopyLinkProps } from '../hooks/useShareOrCopyLink';
import { useShareOrCopyLink } from '../hooks/useShareOrCopyLink';
import { useFeeds, usePlusSubscription } from '../hooks';
import { useFeeds } from '../hooks';
import { LazyModal } from './modals/common/types';
import { useLazyModal } from '../hooks/useLazyModal';

Expand All @@ -31,7 +31,6 @@ const CustomFeedOptionsMenu = ({
onCreateNewFeed,
additionalOptions = [],
}: CustomFeedOptionsMenuProps): ReactElement => {
const { showPlusSubscription } = usePlusSubscription();
const { openModal } = useLazyModal();
const [, onShareOrCopyLink] = useShareOrCopyLink(shareProps);
const { isOpen, onMenuClick } = useContextMenu({
Expand Down Expand Up @@ -59,26 +58,12 @@ const CustomFeedOptionsMenu = ({
label: 'Share',
action: () => onShareOrCopyLink(),
},
];

if (showPlusSubscription) {
options.push({
{
icon: <MenuIcon Icon={HashtagIcon} />,
label: 'Add to custom feed',
action: handleOpenModal,
});
}

if (additionalOptions.length === 0 && !showPlusSubscription) {
return (
<Button
variant={ButtonVariant.Float}
size={ButtonSize.Small}
icon={<ShareIcon />}
onClick={() => onShareOrCopyLink()}
/>
);
}
},
];

options.push(...additionalOptions);

Expand Down
5 changes: 2 additions & 3 deletions packages/shared/src/components/PlusUserBadge.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,9 @@ export const PlusUserBadge = ({
user,
tooltip = true,
}: Props): ReactElement => {
const { showPlusSubscription, isPlus, logSubscriptionEvent } =
usePlusSubscription();
const { isPlus, logSubscriptionEvent } = usePlusSubscription();

if (!user.isPlus || !showPlusSubscription) {
if (!user.isPlus) {
return null;
}

Expand Down
4 changes: 2 additions & 2 deletions packages/shared/src/components/PostOptionsMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ export default function PostOptionsMenu({
const isCustomFeed = feedQueryKey?.[0] === 'custom';
const customFeedId = isCustomFeed ? (feedQueryKey?.[2] as string) : undefined;
const post = loadedPost ?? initialPost;
const { showPlusSubscription, isPlus } = usePlusSubscription();
const { isPlus } = usePlusSubscription();
const { feedSettings, advancedSettings, checkSettingsEnabledState } =
useFeedSettings({
enabled: isPostOptionsOpen,
Expand Down Expand Up @@ -419,7 +419,7 @@ export default function PostOptionsMenu({
});
}

if (post?.bookmark && showPlusSubscription) {
if (post?.bookmark) {
postOptions.push({
icon: <MenuIcon Icon={FolderIcon} />,
label: 'Move to...',
Expand Down
44 changes: 19 additions & 25 deletions packages/shared/src/components/ProfileMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,31 +53,9 @@ export default function ProfileMenu({
const { openModal } = useLazyModal();
const { user, logout, isGdprCovered } = useAuthContext();
const { isActive: isDndActive, setShowDnd } = useDndContext();
const { showPlusSubscription, isPlus, logSubscriptionEvent } =
usePlusSubscription();
const { isPlus, logSubscriptionEvent } = usePlusSubscription();

const items: ListItem[] = useMemo(() => {
const plusItem: ListItem = showPlusSubscription
? {
title: isPlus ? 'Manage plus' : 'Upgrade to plus',
buttonProps: {
tag: 'a',
icon: <DevPlusIcon />,
href: isPlus ? managePlusUrl : plusUrl,
className: isPlus ? undefined : 'text-action-plus-default',
target: isPlus ? '_blank' : undefined,
onClick: () => {
logSubscriptionEvent({
event_name: isPlus
? LogEvent.ManageSubscription
: LogEvent.UpgradeSubscription,
target_id: TargetId.ProfileDropdown,
});
},
},
}
: undefined;

const list: ListItem[] = [
{
title: 'Profile',
Expand All @@ -87,7 +65,24 @@ export default function ProfileMenu({
icon: <UserIcon />,
},
},
plusItem,
{
title: isPlus ? 'Manage plus' : 'Upgrade to plus',
buttonProps: {
tag: 'a',
icon: <DevPlusIcon />,
href: isPlus ? managePlusUrl : plusUrl,
className: isPlus ? undefined : 'text-action-plus-default',
target: isPlus ? '_blank' : undefined,
onClick: () => {
logSubscriptionEvent({
event_name: isPlus
? LogEvent.ManageSubscription
: LogEvent.UpgradeSubscription,
target_id: TargetId.ProfileDropdown,
});
},
},
},
{
title: 'Account details',
buttonProps: {
Expand Down Expand Up @@ -171,7 +166,6 @@ export default function ProfileMenu({
logout,
openModal,
setShowDnd,
showPlusSubscription,
user.permalink,
]);

Expand Down
5 changes: 2 additions & 3 deletions packages/shared/src/components/UpgradeToPlus.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,7 @@ export const UpgradeToPlus = ({
}: Props): ReactElement => {
const { isLoggedIn, showLogin } = useAuthContext();
const isMobile = useViewSize(ViewSize.MobileL);
const { showPlusSubscription, isPlus, logSubscriptionEvent } =
usePlusSubscription();
const { isPlus, logSubscriptionEvent } = usePlusSubscription();

const content = isMobile ? 'Upgrade' : 'Upgrade to plus';

Expand All @@ -54,7 +53,7 @@ export const UpgradeToPlus = ({
[isLoggedIn, logSubscriptionEvent, showLogin, target],
);

if (!showPlusSubscription || isPlus) {
if (isPlus) {
return null;
}

Expand Down
4 changes: 2 additions & 2 deletions packages/shared/src/components/cards/ad/AdGrid.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export const AdGrid = forwardRef(function AdGrid(
{ ad, onLinkClick, onRefresh, domProps, index, feedIndex }: AdCardProps,
inViewRef: InViewRef,
): ReactElement {
const { isEnrolledNotPlus } = usePlusSubscription();
const { isPlus } = usePlusSubscription();
const { ref, refetch, isRefetching } = useAutoRotatingAds(
ad,
index,
Expand Down Expand Up @@ -48,7 +48,7 @@ export const AdGrid = forwardRef(function AdGrid(
onClick={onRefreshClick}
loading={isRefetching}
/>
{isEnrolledNotPlus && <RemoveAd size={ButtonSize.Small} />}
{!isPlus && <RemoveAd size={ButtonSize.Small} />}
</div>
</CardTextContainer>
<AdPixel pixel={ad.pixel} />
Expand Down
4 changes: 2 additions & 2 deletions packages/shared/src/components/cards/ad/AdList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export const AdList = forwardRef(function AdCard(
{ ad, onLinkClick, onRefresh, domProps, index, feedIndex }: AdCardProps,
inViewRef: InViewRef,
): ReactElement {
const { isEnrolledNotPlus } = usePlusSubscription();
const { isPlus } = usePlusSubscription();
const { ref, refetch, isRefetching } = useAutoRotatingAds(
ad,
index,
Expand Down Expand Up @@ -71,7 +71,7 @@ export const AdList = forwardRef(function AdCard(

<div className="z-1 flex items-center pt-2">
<AdRefresh onClick={onRefreshClick} loading={isRefetching} />
{isEnrolledNotPlus && <RemoveAd />}
{!isPlus && <RemoveAd />}
</div>
<AdPixel pixel={ad.pixel} />
</FeedItemContainer>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,14 @@ import { webappUrl } from '../../../lib/constants';

export const ClickbaitShield = ({ post }: { post: Post }): ReactElement => {
const { openModal } = useLazyModal();
const { isPlus, showPlusSubscription } = usePlusSubscription();
const { isPlus } = usePlusSubscription();
const { checkHasCompleted } = useActions();
const { fetchSmartTitle, fetchedSmartTitle, shieldActive } =
useSmartTitle(post);
const isMobile = useViewSize(ViewSize.MobileL);
const router = useRouter();
const { user } = useAuthContext();

if (!showPlusSubscription) {
return null;
}

if (!isPlus) {
const hasUsedFreeTrial = checkHasCompleted(ActionType.FetchedSmartTitle);
return (
Expand Down
4 changes: 2 additions & 2 deletions packages/shared/src/components/comments/AdAsComment.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ interface AdAsCommentProps {
export const AdAsComment = ({ postId }: AdAsCommentProps): ReactElement => {
const { logEvent } = useLogContext();
const { user } = useAuthContext();
const { isEnrolledNotPlus } = usePlusSubscription();
const { isPlus } = usePlusSubscription();

const {
data: ad,
Expand Down Expand Up @@ -106,7 +106,7 @@ export const AdAsComment = ({ postId }: AdAsCommentProps): ReactElement => {
onClick={onRefreshClick}
loading={isRefetching}
/>
{isEnrolledNotPlus && (
{!isPlus && (
<RemoveAd
iconOnly
variant={ButtonVariant.Tertiary}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import type { CreateFeedProps } from '../../../hooks';
import {
useActions,
useFeeds,
usePlusSubscription,
useProgressAnimation,
useToastNotification,
} from '../../../hooks';
Expand Down Expand Up @@ -44,7 +43,6 @@ export const FeedSettingsCreate = (): ReactElement => {
const queryClient = useQueryClient();
const { displayToast } = useToastNotification();
const { logEvent } = useLogContext();
const { showPlusSubscription } = usePlusSubscription();
const [data, setData] = useState<CreateFeedProps>(() => ({
icon: '',
}));
Expand Down Expand Up @@ -164,7 +162,7 @@ export const FeedSettingsCreate = (): ReactElement => {
>
New custom feed
</Typography>
{showPlusSubscription && <PlusUser />}
<PlusUser />
</div>
<div className="flex w-full items-center justify-between gap-2 tablet:hidden">
<Button
Expand Down
Loading
Loading