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

fix: my feed edit feed #4021

Merged
merged 3 commits into from
Dec 23, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
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
19 changes: 14 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 {
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 = (
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Renaming because it confused me which one was called for 10 minutes (same as above import)

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 isMyFeed = router?.query?.slugOrId === user?.id;
const [feedName, setFeedName] = useState(
getInternalFeedName(router?.pathname, { isMyFeed }),
);
const [isSearchOn, setIsSearchOn] = useState(isFinderPage);
useEffect(() => {
const isMyFeed = router?.pathname === '/my-feed';
Expand All @@ -61,7 +70,7 @@ export default function MainFeedPage({
setIsSearchOn(true);
setFeedName('search');
} else {
const newFeed = getFeedName(router?.pathname);
const newFeed = getInternalFeedName(router?.pathname, { isMyFeed });
if (isSearchOn) {
setIsSearchOn(false);
}
Expand Down
Loading