Skip to content

Commit

Permalink
fix: my feed edit feed (#4021)
Browse files Browse the repository at this point in the history
  • Loading branch information
rebelchris authored Dec 23, 2024
1 parent 8f3fce6 commit 015fb2d
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 6 deletions.
6 changes: 5 additions & 1 deletion packages/shared/src/lib/feed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@ export function adLogEvent(
export interface GetDefaultFeedProps {
hasFiltered?: boolean;
hasUser?: boolean;
isMyFeed?: boolean;
}

export const getDefaultFeed = ({
Expand Down Expand Up @@ -201,7 +202,10 @@ export const getFeedName = (
return OtherFeedPage.UserPosts;
}
if (feed.startsWith('feeds')) {
return SharedFeedPage.Custom;
const isMyFeedEdit =
['edit'].some((item) => feed.endsWith(item)) && options.isMyFeed;

return isMyFeedEdit ? SharedFeedPage.MyFeed : SharedFeedPage.Custom;
}

const [page] = feed.split('?');
Expand Down
21 changes: 16 additions & 5 deletions packages/webapp/components/layouts/MainFeedPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@ import { MainLayoutProps } from '@dailydotdev/shared/src/components/MainLayout';
import type { MainFeedLayoutProps } from '@dailydotdev/shared/src/components/MainFeedLayout';
import AuthContext from '@dailydotdev/shared/src/contexts/AuthContext';
import { getShouldRedirect } from '@dailydotdev/shared/src/components/utilities';
import { getFeedName as getFeedNameLib } from '@dailydotdev/shared/src/lib/feed';
import {
type GetDefaultFeedProps,
getFeedName,
} from '@dailydotdev/shared/src/lib/feed';
import dynamic from 'next/dynamic';
import { getLayout } from './FeedLayout';

Expand All @@ -27,7 +30,10 @@ export type MainFeedPageProps = {
isFinder?: boolean;
} & Pick<MainFeedLayoutProps, 'searchChildren'>;

const getFeedName = (path: string): string => {
const getInternalFeedName = (
path: string,
options?: GetDefaultFeedProps,
): string => {
if (path === '/') {
return 'default';
}
Expand All @@ -37,7 +43,7 @@ const getFeedName = (path: string): string => {
}

if (path.startsWith('/feeds/')) {
return getFeedNameLib(path);
return getFeedName(path, options);
}

return path.replace(/^\/+/, '');
Expand All @@ -51,7 +57,10 @@ export default function MainFeedPage({
const router = useRouter();
const { user } = useContext(AuthContext);
const isFinderPage = router?.pathname === '/search/posts' || isFinder;
const [feedName, setFeedName] = useState(getFeedName(router?.pathname));
const isMyFeedURL = router?.query?.slugOrId === user?.id;
const [feedName, setFeedName] = useState(
getInternalFeedName(router?.pathname, { isMyFeed: isMyFeedURL }),
);
const [isSearchOn, setIsSearchOn] = useState(isFinderPage);
useEffect(() => {
const isMyFeed = router?.pathname === '/my-feed';
Expand All @@ -61,7 +70,9 @@ export default function MainFeedPage({
setIsSearchOn(true);
setFeedName('search');
} else {
const newFeed = getFeedName(router?.pathname);
const newFeed = getInternalFeedName(router?.pathname, {
isMyFeed: isMyFeedURL,
});
if (isSearchOn) {
setIsSearchOn(false);
}
Expand Down

0 comments on commit 015fb2d

Please sign in to comment.