Remove global collapse expand

pull/8189/head
Kamran Ahmed 3 months ago
parent 9e352be949
commit eb0dac034d
  1. 27
      src/components/Dashboard/PersonalDashboard.tsx
  2. 14
      src/components/HeroSection/FavoriteRoadmaps.tsx
  3. 28
      src/components/HeroSection/HeroItemsGroup.tsx

@ -59,8 +59,6 @@ type DashboardStatsProps = {
topicsDoneToday?: number; topicsDoneToday?: number;
finishedProjectsCount?: number; finishedProjectsCount?: number;
isLoading: boolean; isLoading: boolean;
isAllCollapsed: boolean;
onToggleCollapseAll: () => void;
}; };
type DashboardStatItemProps = { type DashboardStatItemProps = {
@ -101,8 +99,6 @@ function DashboardStats(props: DashboardStatsProps) {
topicsDoneToday = 0, topicsDoneToday = 0,
finishedProjectsCount = 0, finishedProjectsCount = 0,
isLoading, isLoading,
onToggleCollapseAll,
isAllCollapsed,
} = props; } = props;
return ( return (
@ -130,23 +126,6 @@ function DashboardStats(props: DashboardStatsProps) {
isLoading={isLoading} isLoading={isLoading}
/> */} /> */}
</div> </div>
<button
className="flex items-center gap-1 rounded-lg border border-transparent py-1.5 pl-3 pr-3 text-xs uppercase tracking-wide text-slate-400 hover:border-slate-800 hover:bg-slate-800"
onClick={onToggleCollapseAll}
>
{isAllCollapsed ? (
<>
<ChevronsUpDown className="size-3" />
<span>Expand All</span>
</>
) : (
<>
<ChevronsDownUp className="size-3" />
<span>Collapse All</span>
</>
)}
</button>
</div> </div>
); );
} }
@ -161,7 +140,6 @@ export function PersonalDashboard(props: PersonalDashboardProps) {
const toast = useToast(); const toast = useToast();
const [isLoading, setIsLoading] = useState(true); const [isLoading, setIsLoading] = useState(true);
const [isAllCollapsed, setIsAllCollapsed] = useState(false);
const [personalDashboardDetails, setPersonalDashboardDetails] = const [personalDashboardDetails, setPersonalDashboardDetails] =
useState<UserDashboardResponse>(); useState<UserDashboardResponse>();
const [projectDetails, setProjectDetails] = useState<PageType[]>([]); const [projectDetails, setProjectDetails] = useState<PageType[]>([]);
@ -305,10 +283,6 @@ export function PersonalDashboard(props: PersonalDashboardProps) {
isLoading={isLoading} isLoading={isLoading}
accountStreak={accountStreak} accountStreak={accountStreak}
topicsDoneToday={personalDashboardDetails?.topicDoneToday} topicsDoneToday={personalDashboardDetails?.topicDoneToday}
onToggleCollapseAll={() => {
setIsAllCollapsed(!isAllCollapsed);
}}
isAllCollapsed={isAllCollapsed}
finishedProjectsCount={ finishedProjectsCount={
enrichedProjects?.filter((p) => p.submittedAt && p.repositoryUrl) enrichedProjects?.filter((p) => p.submittedAt && p.repositoryUrl)
.length .length
@ -321,7 +295,6 @@ export function PersonalDashboard(props: PersonalDashboardProps) {
aiRoadmaps={aiGeneratedRoadmaps} aiRoadmaps={aiGeneratedRoadmaps}
projects={enrichedProjects || []} projects={enrichedProjects || []}
isLoading={isLoading} isLoading={isLoading}
isAllCollapsed={isAllCollapsed}
/> />
<div className="relative mt-6 border-t border-t-[#1e293c] pt-12"> <div className="relative mt-6 border-t border-t-[#1e293c] pt-12">

@ -29,18 +29,10 @@ type FavoriteRoadmapsProps = {
customRoadmaps: UserProgress[]; customRoadmaps: UserProgress[];
aiRoadmaps: AIRoadmapType[]; aiRoadmaps: AIRoadmapType[];
isLoading: boolean; isLoading: boolean;
isAllCollapsed: boolean;
}; };
export function FavoriteRoadmaps(props: FavoriteRoadmapsProps) { export function FavoriteRoadmaps(props: FavoriteRoadmapsProps) {
const { const { progress, isLoading, customRoadmaps, aiRoadmaps, projects } = props;
progress,
isLoading,
customRoadmaps,
aiRoadmaps,
projects,
isAllCollapsed,
} = props;
const [showCompleted, setShowCompleted] = useState(false); const [showCompleted, setShowCompleted] = useState(false);
const completedProjects = projects.filter( const completedProjects = projects.filter(
@ -61,7 +53,6 @@ export function FavoriteRoadmaps(props: FavoriteRoadmapsProps) {
icon={<CheckIcon additionalClasses="mr-1.5 h-[14px] w-[14px]" />} icon={<CheckIcon additionalClasses="mr-1.5 h-[14px] w-[14px]" />}
isLoading={isLoading} isLoading={isLoading}
title="Your progress and bookmarks" title="Your progress and bookmarks"
isAllCollapsed={isAllCollapsed}
> >
{progress.map((resource) => ( {progress.map((resource) => (
<HeroRoadmap <HeroRoadmap
@ -87,7 +78,6 @@ export function FavoriteRoadmaps(props: FavoriteRoadmapsProps) {
icon={<MapIcon className="mr-1.5 h-[14px] w-[14px]" />} icon={<MapIcon className="mr-1.5 h-[14px] w-[14px]" />}
isLoading={isLoading} isLoading={isLoading}
title="Your custom roadmaps" title="Your custom roadmaps"
isAllCollapsed={isAllCollapsed}
> >
{customRoadmaps.map((customRoadmap) => ( {customRoadmaps.map((customRoadmap) => (
<HeroRoadmap <HeroRoadmap
@ -111,7 +101,6 @@ export function FavoriteRoadmaps(props: FavoriteRoadmapsProps) {
icon={<Sparkle className="mr-1.5 h-[14px] w-[14px]" />} icon={<Sparkle className="mr-1.5 h-[14px] w-[14px]" />}
isLoading={isLoading} isLoading={isLoading}
title="Your AI roadmaps" title="Your AI roadmaps"
isAllCollapsed={isAllCollapsed}
> >
{aiRoadmaps.map((aiRoadmap) => ( {aiRoadmaps.map((aiRoadmap) => (
<HeroRoadmap <HeroRoadmap
@ -141,7 +130,6 @@ export function FavoriteRoadmaps(props: FavoriteRoadmapsProps) {
icon={<FolderKanban className="mr-1.5 h-[14px] w-[14px]" />} icon={<FolderKanban className="mr-1.5 h-[14px] w-[14px]" />}
isLoading={isLoading} isLoading={isLoading}
title="Your active projects" title="Your active projects"
isAllCollapsed={isAllCollapsed}
rightContent={ rightContent={
completedProjects.length > 0 && ( completedProjects.length > 0 && (
<button <button

@ -1,4 +1,4 @@
import { useEffect, useState, type ReactNode } from 'react'; import { useEffect, useRef, useState, type ReactNode } from 'react';
import { cn } from '../../lib/classname'; import { cn } from '../../lib/classname';
import { HeroTitle } from './HeroTitle'; import { HeroTitle } from './HeroTitle';
@ -7,7 +7,6 @@ type HeroItemsGroupProps = {
isLoading?: boolean; isLoading?: boolean;
title: string | ReactNode; title: string | ReactNode;
rightContent?: ReactNode; rightContent?: ReactNode;
isAllCollapsed?: boolean;
children?: ReactNode; children?: ReactNode;
className?: string; className?: string;
}; };
@ -18,24 +17,34 @@ export function HeroItemsGroup(props: HeroItemsGroupProps) {
isLoading = false, isLoading = false,
title, title,
rightContent, rightContent,
isAllCollapsed = false,
children, children,
className, className,
} = props; } = props;
const [isCollapsed, setIsCollapsed] = useState(isLoading || isAllCollapsed); const isInitialRender = useRef(true);
const storageKey = `hero-group-${title}-collapsed`;
const [isCollapsed, setIsCollapsed] = useState(true);
function isCollapsedByStorage() {
const stored = localStorage.getItem(storageKey);
return stored === 'true';
}
useEffect(() => { useEffect(() => {
setIsCollapsed(isAllCollapsed || isLoading); setIsCollapsed(isCollapsedByStorage());
}, [isAllCollapsed, isLoading]); }, [isLoading]);
const isLoadingOrCollapsed = isLoading || isCollapsed;
return ( return (
<div <div
className={cn( className={cn(
'border-b border-gray-800/50', 'border-b border-gray-800/50',
{ {
'py-4': !isCollapsed, 'py-4': !isLoadingOrCollapsed,
'py-3': isCollapsed, 'py-3': isLoadingOrCollapsed,
'opacity-50 transition-opacity hover:opacity-100': 'opacity-50 transition-opacity hover:opacity-100':
isCollapsed && !isLoading, isCollapsed && !isLoading,
}, },
@ -51,9 +60,10 @@ export function HeroItemsGroup(props: HeroItemsGroupProps) {
isCollapsed={isCollapsed} isCollapsed={isCollapsed}
onToggleCollapse={() => { onToggleCollapse={() => {
setIsCollapsed(!isCollapsed); setIsCollapsed(!isCollapsed);
localStorage.setItem(storageKey, (!isCollapsed).toString());
}} }}
/> />
{!isCollapsed && ( {!isLoadingOrCollapsed && (
<div className="mt-4 grid grid-cols-1 gap-2.5 sm:grid-cols-2 md:grid-cols-3"> <div className="mt-4 grid grid-cols-1 gap-2.5 sm:grid-cols-2 md:grid-cols-3">
{children} {children}
</div> </div>

Loading…
Cancel
Save