diff --git a/web/app/components/explore/index.tsx b/web/app/components/explore/index.tsx index fb4000e3b1..eb452663ab 100644 --- a/web/app/components/explore/index.tsx +++ b/web/app/components/explore/index.tsx @@ -8,6 +8,8 @@ import Sidebar from '@/app/components/explore/sidebar' import { useAppContext } from '@/context/app-context' import { fetchMembers } from '@/service/common' import type { InstalledApp } from '@/models/explore' +import useBreakpoints, { MediaType } from '@/hooks/use-breakpoints' +import { useStore } from '@/app/components/app/store' export type IExploreProps = { children: React.ReactNode @@ -23,6 +25,10 @@ const Explore: FC = ({ const [hasEditPermission, setHasEditPermission] = useState(false) const [installedApps, setInstalledApps] = useState([]) + const media = useBreakpoints() + const isMobile = media === MediaType.mobile + const setAppSiderbarExpand = useStore(state => state.setAppSiderbarExpand) + useEffect(() => { document.title = `${t('explore.title')} - Dify`; (async () => { @@ -39,6 +45,12 @@ const Explore: FC = ({ return router.replace('/datasets') }, [isCurrentWorkspaceDatasetOperator]) + useEffect(() => { + const localeMode = localStorage.getItem('app-detail-collapse-or-expand') || 'expand' + const mode = isMobile ? 'collapse' : 'expand' + setAppSiderbarExpand(isMobile ? mode : localeMode) + }, [isMobile, setAppSiderbarExpand]) + return (
- {isMobile && } - {!isMobile && ( + {!expand && } + {expand && ( <>
diff --git a/web/app/components/explore/sidebar/index.tsx b/web/app/components/explore/sidebar/index.tsx index 4dd6e4ea47..399b9aae7d 100644 --- a/web/app/components/explore/sidebar/index.tsx +++ b/web/app/components/explore/sidebar/index.tsx @@ -1,10 +1,13 @@ 'use client' import type { FC } from 'react' import React, { useEffect, useState } from 'react' +import { useShallow } from 'zustand/react/shallow' import { useTranslation } from 'react-i18next' import { useContext } from 'use-context-selector' import { useSelectedLayoutSegments } from 'next/navigation' import Link from 'next/link' +import { RiLayoutRight2Line } from '@remixicon/react' +import { LayoutRight2LineMod } from '../../base/icons/src/public/knowledge' import Toast from '../../base/toast' import Item from './app-nav-item' import cn from '@/utils/classnames' @@ -13,6 +16,7 @@ import ExploreContext from '@/context/explore-context' import Confirm from '@/app/components/base/confirm' import Divider from '@/app/components/base/divider' import useBreakpoints, { MediaType } from '@/hooks/use-breakpoints' +import { useStore as useAppStore } from '@/app/components/app/store' const SelectedDiscoveryIcon = () => ( @@ -52,6 +56,15 @@ const SideBar: FC = ({ const isChatSelected = lastSegment === 'chat' const { installedApps, setInstalledApps } = useContext(ExploreContext) + const { appSidebarExpand, setAppSiderbarExpand } = useAppStore(useShallow(state => ({ + appSidebarExpand: state.appSidebarExpand, + setAppSiderbarExpand: state.setAppSiderbarExpand, + }))) + const expand = appSidebarExpand === 'expand' + const handleToggle = (state: string) => { + setAppSiderbarExpand(state === 'expand' ? 'collapse' : 'expand') + } + const media = useBreakpoints() const isMobile = media === MediaType.mobile @@ -82,6 +95,13 @@ const SideBar: FC = ({ fetchInstalledAppList() } + useEffect(() => { + if (appSidebarExpand) { + localStorage.setItem('app-detail-collapse-or-expand', appSidebarExpand) + setAppSiderbarExpand(appSidebarExpand) + } + }, [appSidebarExpand, setAppSiderbarExpand]) + useEffect(() => { fetchInstalledAppList() }, []) @@ -92,7 +112,7 @@ const SideBar: FC = ({ const pinnedAppsCount = installedApps.filter(({ is_pinned }) => is_pinned).length return ( -
+
= ({ style={isDiscoverySelected ? { boxShadow: '0px 1px 2px rgba(16, 24, 40, 0.05)' } : {}} > {isDiscoverySelected ? : } - {!isMobile &&
{t('explore.sidebar.discovery')}
} + {expand &&
{t('explore.sidebar.discovery')}
}
{installedApps.length > 0 && ( @@ -115,7 +135,7 @@ const SideBar: FC = ({ {installedApps.map(({ id, is_pinned, uninstallable, app: { name, icon_type, icon, icon_url, icon_background } }, index) => ( = ({ onCancel={() => setShowConfirm(false)} /> )} + { + !isMobile && ( +
+
handleToggle(appSidebarExpand)} + > + { + expand + ? + : + } +
+
+ ) + }
) }