Skip to content

Commit 64a1b94

Browse files
vamsikrishnamathalalifeiscontent
authored andcommitted
[WEB-3175]fix: favorites menu (#6773)
* fix: favrotites menu open * fix: open fav menu on starring projec * chore: added constant for hardcoded text
1 parent bc2f508 commit 64a1b94

File tree

9 files changed

+78
-16
lines changed

9 files changed

+78
-16
lines changed

packages/constants/src/workspace.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -325,6 +325,7 @@ export const WORKSPACE_SIDEBAR_STATIC_NAVIGATION_ITEMS_LINKS: IWorkspaceSidebarN
325325
WORKSPACE_SIDEBAR_STATIC_NAVIGATION_ITEMS["projects"],
326326
];
327327

328+
export const IS_FAVORITE_MENU_OPEN = "is_favorite_menu_open";
328329
export const WORKSPACE_DEFAULT_SEARCH_RESULT: IWorkspaceSearchResults = {
329330
results: {
330331
workspace: [],

web/core/components/cycles/list/cycle-list-item-action.tsx

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,14 @@ import { useParams, usePathname, useSearchParams } from "next/navigation";
66
import { useForm } from "react-hook-form";
77
import { Eye, Users } from "lucide-react";
88
// types
9-
import { CYCLE_FAVORITED, CYCLE_UNFAVORITED, EUserPermissions, EUserPermissionsLevel } from "@plane/constants";
9+
import {
10+
CYCLE_FAVORITED,
11+
CYCLE_UNFAVORITED,
12+
EUserPermissions,
13+
EUserPermissionsLevel,
14+
IS_FAVORITE_MENU_OPEN,
15+
} from "@plane/constants";
16+
import { useLocalStorage } from "@plane/hooks";
1017
import { useTranslation } from "@plane/i18n";
1118
import { ICycle, TCycleGroups } from "@plane/types";
1219
// ui
@@ -15,8 +22,6 @@ import { Avatar, AvatarGroup, FavoriteStar, LayersIcon, Tooltip, TransferIcon, s
1522
import { CycleQuickActions, TransferIssuesModal } from "@/components/cycles";
1623
import { DateRangeDropdown } from "@/components/dropdowns";
1724
import { ButtonAvatars } from "@/components/dropdowns/member/avatar";
18-
// constants
19-
// helpers
2025
import { getDate } from "@/helpers/date-time.helper";
2126
import { getFileURL } from "@/helpers/file.helper";
2227
// hooks
@@ -59,6 +64,12 @@ export const CycleListItemAction: FC<Props> = observer((props) => {
5964
const { captureEvent } = useEventTracker();
6065
const { allowPermissions } = useUserPermissions();
6166

67+
// local storage
68+
const { setValue: toggleFavoriteMenu, storedValue: isFavoriteMenuOpen } = useLocalStorage<boolean>(
69+
IS_FAVORITE_MENU_OPEN,
70+
false
71+
);
72+
6273
const { getUserDetails } = useMember();
6374

6475
// form
@@ -91,6 +102,7 @@ export const CycleListItemAction: FC<Props> = observer((props) => {
91102

92103
const addToFavoritePromise = addCycleToFavorites(workspaceSlug?.toString(), projectId.toString(), cycleId).then(
93104
() => {
105+
if (!isFavoriteMenuOpen) toggleFavoriteMenu(true);
94106
captureEvent(CYCLE_FAVORITED, {
95107
cycle_id: cycleId,
96108
element: "List layout",

web/core/components/modules/module-card-item.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@ import {
1313
MODULE_UNFAVORITED,
1414
EUserPermissions,
1515
EUserPermissionsLevel,
16+
IS_FAVORITE_MENU_OPEN,
1617
} from "@plane/constants";
18+
import { useLocalStorage } from "@plane/hooks";
1719
import { IModule } from "@plane/types";
1820
import {
1921
Card,
@@ -30,7 +32,6 @@ import { DateRangeDropdown } from "@/components/dropdowns";
3032
import { ButtonAvatars } from "@/components/dropdowns/member/avatar";
3133
import { ModuleQuickActions } from "@/components/modules";
3234
import { ModuleStatusDropdown } from "@/components/modules/module-status-dropdown";
33-
// constants
3435
// helpers
3536
import { getDate, renderFormattedPayloadDate } from "@/helpers/date-time.helper";
3637
import { generateQueryParams } from "@/helpers/router.helper";
@@ -59,6 +60,9 @@ export const ModuleCardItem: React.FC<Props> = observer((props) => {
5960
const { getUserDetails } = useMember();
6061
const { captureEvent } = useEventTracker();
6162

63+
// local storage
64+
const { setValue: toggleFavoriteMenu, storedValue } = useLocalStorage<boolean>(IS_FAVORITE_MENU_OPEN, false);
65+
6266
// derived values
6367
const moduleDetails = getModuleById(moduleId);
6468
const isEditingAllowed = allowPermissions(
@@ -76,6 +80,7 @@ export const ModuleCardItem: React.FC<Props> = observer((props) => {
7680

7781
const addToFavoritePromise = addModuleToFavorites(workspaceSlug.toString(), projectId.toString(), moduleId).then(
7882
() => {
83+
if (!storedValue) toggleFavoriteMenu(true);
7984
captureEvent(MODULE_FAVORITED, {
8085
module_id: moduleId,
8186
element: "Grid layout",

web/core/components/modules/module-list-item-action.tsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@ import {
1212
MODULE_UNFAVORITED,
1313
EUserPermissions,
1414
EUserPermissionsLevel,
15+
IS_FAVORITE_MENU_OPEN,
1516
} from "@plane/constants";
17+
import { useLocalStorage } from "@plane/hooks";
1618
import { useTranslation } from "@plane/i18n";
1719
import { IModule } from "@plane/types";
1820
// ui
@@ -45,6 +47,8 @@ export const ModuleListItemAction: FC<Props> = observer((props) => {
4547

4648
const { t } = useTranslation();
4749

50+
// local storage
51+
const { setValue: toggleFavoriteMenu, storedValue } = useLocalStorage<boolean>(IS_FAVORITE_MENU_OPEN, false);
4852
// derived values
4953

5054
const moduleStatus = MODULE_STATUS.find((status) => status.value === moduleDetails.status);
@@ -63,6 +67,8 @@ export const ModuleListItemAction: FC<Props> = observer((props) => {
6367

6468
const addToFavoritePromise = addModuleToFavorites(workspaceSlug.toString(), projectId.toString(), moduleId).then(
6569
() => {
70+
// open favorites menu if closed
71+
if (!storedValue) toggleFavoriteMenu(true);
6672
captureEvent(MODULE_FAVORITED, {
6773
module_id: moduleId,
6874
element: "Grid layout",

web/core/components/pages/editor/header/extra-options.tsx

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
"use client";
22

33
import { observer } from "mobx-react";
4+
// constants
5+
import { IS_FAVORITE_MENU_OPEN } from "@plane/constants";
46
// editor
57
import { EditorRefApi } from "@plane/editor";
8+
// plane hooks
9+
import { useLocalStorage } from "@plane/hooks";
610
// ui
711
import { ArchiveIcon, FavoriteStar, setToast, TOAST_TYPE, Tooltip } from "@plane/ui";
812
// components
@@ -37,6 +41,11 @@ export const PageExtraOptions: React.FC<Props> = observer((props) => {
3741
} = page;
3842
// use online status
3943
const { isOnline } = useOnlineStatus();
44+
// local storage
45+
const { setValue: toggleFavoriteMenu, storedValue: isFavoriteMenuOpen } = useLocalStorage<boolean>(
46+
IS_FAVORITE_MENU_OPEN,
47+
false
48+
);
4049
// favorite handler
4150
const handleFavorite = () => {
4251
if (is_favorite) {
@@ -48,13 +57,14 @@ export const PageExtraOptions: React.FC<Props> = observer((props) => {
4857
})
4958
);
5059
} else {
51-
addToFavorites().then(() =>
60+
addToFavorites().then(() => {
61+
if (!isFavoriteMenuOpen) toggleFavoriteMenu(true);
5262
setToast({
5363
type: TOAST_TYPE.SUCCESS,
5464
title: "Success!",
5565
message: "Page added to favorites.",
56-
})
57-
);
66+
});
67+
});
5868
}
5969
};
6070

web/core/components/project/card.tsx

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ import Link from "next/link";
66
import { useParams } from "next/navigation";
77
import { ArchiveRestoreIcon, Check, ExternalLink, LinkIcon, Lock, Settings, Trash2, UserPlus } from "lucide-react";
88
// types
9-
import { EUserPermissions, EUserPermissionsLevel } from "@plane/constants";
9+
import { EUserPermissions, EUserPermissionsLevel, IS_FAVORITE_MENU_OPEN } from "@plane/constants";
10+
import { useLocalStorage } from "@plane/hooks";
1011
import type { IProject } from "@plane/types";
1112
// ui
1213
import {
@@ -68,6 +69,11 @@ export const ProjectCard: React.FC<Props> = observer((props) => {
6869
const hasMemberRole = project.member_role === EUserPermissions.MEMBER;
6970
// archive
7071
const isArchived = !!project.archived_at;
72+
// local storage
73+
const { setValue: toggleFavoriteMenu, storedValue: isFavoriteMenuOpen } = useLocalStorage<boolean>(
74+
IS_FAVORITE_MENU_OPEN,
75+
false
76+
);
7177

7278
const handleAddToFavorites = () => {
7379
if (!workspaceSlug) return;
@@ -78,6 +84,10 @@ export const ProjectCard: React.FC<Props> = observer((props) => {
7884
success: {
7985
title: "Success!",
8086
message: () => "Project added to favorites.",
87+
actionItems: () => {
88+
if (!isFavoriteMenuOpen) toggleFavoriteMenu(true);
89+
return <></>;
90+
},
8191
},
8292
error: {
8393
title: "Error!",

web/core/components/views/view-list-item-action.tsx

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@ import { observer } from "mobx-react";
33
import { useParams } from "next/navigation";
44
import { Earth, Lock } from "lucide-react";
55
// types
6-
import { EViewAccess, EUserPermissions, EUserPermissionsLevel } from "@plane/constants";
6+
import { EViewAccess, EUserPermissions, EUserPermissionsLevel, IS_FAVORITE_MENU_OPEN } from "@plane/constants";
7+
import { useLocalStorage } from "@plane/hooks";
78
import { IProjectView } from "@plane/types";
89
// ui
910
import { Tooltip, FavoriteStar } from "@plane/ui";
1011
// components
1112
import { DeleteProjectViewModal, CreateUpdateProjectViewModal, ViewQuickActions } from "@/components/views";
12-
// constants
1313
// helpers
1414
import { calculateTotalFilters } from "@/helpers/filter.helper";
1515
import { getPublishViewLink } from "@/helpers/project-views.helpers";
@@ -37,6 +37,12 @@ export const ViewListItemAction: FC<Props> = observer((props) => {
3737
const { addViewToFavorites, removeViewFromFavorites } = useProjectView();
3838
const { getUserDetails } = useMember();
3939

40+
// local storage
41+
const { setValue: toggleFavoriteMenu, storedValue: isFavoriteOpen } = useLocalStorage<boolean>(
42+
IS_FAVORITE_MENU_OPEN,
43+
false
44+
);
45+
4046
// derived values
4147
const isEditingAllowed = allowPermissions(
4248
[EUserPermissions.ADMIN, EUserPermissions.MEMBER],
@@ -50,10 +56,11 @@ export const ViewListItemAction: FC<Props> = observer((props) => {
5056
const publishLink = getPublishViewLink(view?.anchor);
5157

5258
// handlers
53-
const handleAddToFavorites = () => {
59+
const handleAddToFavorites = async () => {
5460
if (!workspaceSlug || !projectId) return;
5561

56-
addViewToFavorites(workspaceSlug.toString(), projectId.toString(), view.id);
62+
await addViewToFavorites(workspaceSlug.toString(), projectId.toString(), view.id);
63+
if (!isFavoriteOpen) toggleFavoriteMenu(true);
5764
};
5865

5966
const handleRemoveFromFavorites = () => {

web/core/components/workspace/sidebar/favorites/favorites-menu.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import { observer } from "mobx-react";
1313
import { useParams } from "next/navigation";
1414
import { ChevronRight, FolderPlus } from "lucide-react";
1515
import { Disclosure, Transition } from "@headlessui/react";
16+
import { IS_FAVORITE_MENU_OPEN } from "@plane/constants";
1617
import { useTranslation } from "@plane/i18n";
1718
// ui
1819
import { IFavorite } from "@plane/types";
@@ -54,7 +55,7 @@ export const SidebarFavoritesMenu = observer(() => {
5455
const { isMobile } = usePlatformOS();
5556

5657
// local storage
57-
const { setValue: toggleFavoriteMenu, storedValue } = useLocalStorage<boolean>("is_favorite_menu_open", false);
58+
const { setValue: toggleFavoriteMenu, storedValue } = useLocalStorage<boolean>(IS_FAVORITE_MENU_OPEN, false);
5859
// derived values
5960
const isFavoriteMenuOpen = !!storedValue;
6061
// refs

web/core/hooks/use-page-operations.ts

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
import { useMemo } from "react";
2+
// plane constants
3+
import { IS_FAVORITE_MENU_OPEN } from "@plane/constants";
24
// plane editor
35
import { EditorRefApi } from "@plane/editor";
46
// plane types
@@ -11,6 +13,8 @@ import { copyUrlToClipboard } from "@/helpers/string.helper";
1113
import { useCollaborativePageActions } from "@/hooks/use-collaborative-page-actions";
1214
// store types
1315
import { TPageInstance } from "@/store/pages/base-page";
16+
// local storage
17+
import useLocalStorage from "./use-local-storage";
1418

1519
export type TPageOperations = {
1620
toggleLock: () => void;
@@ -46,6 +50,11 @@ export const usePageOperations = (
4650
} = page;
4751
// collaborative actions
4852
const { executeCollaborativeAction } = useCollaborativePageActions(props);
53+
// local storage
54+
const { setValue: toggleFavoriteMenu, storedValue: isfavoriteMenuOpen } = useLocalStorage<boolean>(
55+
IS_FAVORITE_MENU_OPEN,
56+
false
57+
);
4958
// page operations
5059
const pageOperations: TPageOperations = useMemo(() => {
5160
const pageLink = getRedirectionLink();
@@ -141,13 +150,14 @@ export const usePageOperations = (
141150
})
142151
);
143152
} else {
144-
addToFavorites().then(() =>
153+
addToFavorites().then(() => {
154+
if (!isfavoriteMenuOpen) toggleFavoriteMenu(true);
145155
setToast({
146156
type: TOAST_TYPE.SUCCESS,
147157
title: "Success!",
148158
message: "Page added to favorites.",
149-
})
150-
);
159+
});
160+
});
151161
}
152162
},
153163
toggleLock: async () => {

0 commit comments

Comments
 (0)