update chat favorites

This commit is contained in:
Nate Kelley 2025-05-13 22:15:04 -06:00
parent 7afa3cf399
commit adb7a9640e
No known key found for this signature in database
GPG Key ID: FD90372AB8D98B4F
2 changed files with 40 additions and 36 deletions

View File

@ -1,14 +1,13 @@
'use client';
import React, { useMemo, useState } from 'react';
import React, { useMemo } from 'react';
import { Sidebar } from '@/components/ui/sidebar/Sidebar';
import { BusterLogoWithText } from '@/assets/svg/BusterLogoWithText';
import { BusterRoutes, createBusterRoute } from '@/routes';
import type { ISidebarGroup, ISidebarList, SidebarProps } from '@/components/ui/sidebar';
import { BookOpen4, Flag, Gear, House4, Table, UnorderedList2, Plus } from '@/components/ui/icons';
import { Flag, Gear, House4, Table, UnorderedList2, Plus } from '@/components/ui/icons';
import { PencilSquareIcon } from '@/components/ui/icons/customIcons/Pencil_Square';
import { ASSET_ICONS, assetTypeToIcon, assetTypeToRoute } from '../config/assetIcons';
import type { BusterUserFavorite } from '@/api/asset_interfaces/users';
import { ASSET_ICONS } from '../config/assetIcons';
import { Button } from '@/components/ui/buttons';
import { Tooltip } from '@/components/ui/tooltip/Tooltip';
import Link from 'next/link';
@ -21,46 +20,44 @@ import { SupportModal } from '../modal/SupportModal';
import { InvitePeopleModal } from '../modal/InvitePeopleModal';
import { useMemoizedFn } from '@/hooks';
import { SidebarUserFooter } from './SidebarUserFooter/SidebarUserFooter';
import {
useDeleteUserFavorite,
useGetUserFavorites,
useUpdateUserFavorites
} from '@/api/buster_rest';
import { useHotkeys } from 'react-hotkeys-hook';
import { useInviteModalStore } from '@/context/BusterAppLayout';
import { useFavoriteSidebarPanel } from './useFavoritesSidebarPanel';
import { ShareAssetType } from '@/api/asset_interfaces/share';
const topItems = (currentParentRoute: BusterRoutes): ISidebarList => ({
id: 'top-items',
items: [
{
label: 'Home',
icon: <House4 />,
route: BusterRoutes.APP_HOME,
id: BusterRoutes.APP_HOME
},
{
label: 'Chat history',
icon: <ASSET_ICONS.chats />,
route: BusterRoutes.APP_CHAT,
id: BusterRoutes.APP_CHAT
}
].map((x) => ({
...x,
active: x.route === currentParentRoute
}))
});
const topItems = (
currentParentRoute: BusterRoutes,
favoritedPageType: ShareAssetType | null
): ISidebarList => {
const isActiveCheck = (type: ShareAssetType, route: BusterRoutes) => currentParentRoute === route;
return {
id: 'top-items',
items: [
{
label: 'Home',
icon: <House4 />,
route: BusterRoutes.APP_HOME,
id: BusterRoutes.APP_HOME,
active: currentParentRoute === BusterRoutes.APP_HOME
},
{
label: 'Chat history',
icon: <ASSET_ICONS.chats />,
route: BusterRoutes.APP_CHAT,
id: BusterRoutes.APP_CHAT,
active: isActiveCheck(ShareAssetType.CHAT, BusterRoutes.APP_CHAT)
}
]
};
};
const yourStuff = (
currentParentRoute: BusterRoutes,
favoritedPageType: ShareAssetType | null
): ISidebarGroup => {
const isActiveCheck = (type: ShareAssetType, route: BusterRoutes) => {
if (favoritedPageType === type) return false;
if (favoritedPageType === null) return currentParentRoute === route;
return false;
};
const isActiveCheck = (type: ShareAssetType, route: BusterRoutes) =>
favoritedPageType !== type && favoritedPageType === null && currentParentRoute === route;
return {
label: 'Your stuff',
@ -154,7 +151,10 @@ export const SidebarPrimary = React.memo(() => {
const { favoritesDropdownItems, favoritedPageType } = useFavoriteSidebarPanel();
const topItemsItems = useMemo(() => topItems(currentParentRoute), [currentParentRoute]);
const topItemsItems = useMemo(
() => topItems(currentParentRoute, favoritedPageType),
[currentParentRoute, favoritedPageType]
);
const adminToolsItems = useMemo(() => {
if (!isAdmin) return null;

View File

@ -3,7 +3,6 @@ import { ISidebarGroup } from '@/components/ui/sidebar';
import { assetTypeToIcon, assetTypeToRoute } from '../config/assetIcons';
import { useMemoizedFn } from '@/hooks';
import {
updateUserFavorites,
useDeleteUserFavorite,
useGetUserFavorites,
useUpdateUserFavorites
@ -42,6 +41,7 @@ export const useFavoriteSidebarPanel = () => {
case ShareAssetType.COLLECTION:
return id === collectionId;
default:
const _exhaustiveCheck: never = assetType;
return false;
}
});
@ -51,6 +51,10 @@ export const useFavoriteSidebarPanel = () => {
return null;
}
if (chatId && favorites.some((f) => f.id === chatId)) {
return ShareAssetType.CHAT;
}
if (metricId && favorites.some((f) => f.id === metricId)) {
return ShareAssetType.METRIC;
}