Skip to content

Commit

Permalink
refactor(frontend): Use default as current profile on startup if poss…
Browse files Browse the repository at this point in the history
…ible
  • Loading branch information
maikbasel committed May 18, 2024
1 parent df6887a commit 057b62f
Show file tree
Hide file tree
Showing 6 changed files with 9 additions and 26 deletions.
15 changes: 7 additions & 8 deletions src/sections/dashboard/components/header/profile-nav.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { Avatar, AvatarFallback } from '@/components/ui/avatar';
import React, { useEffect } from 'react';
import { ChevronDown, ChevronUp } from 'lucide-react';
import { Profile } from '@/modules/profiles/domain';
import { useCurrentProfile } from '@/sections/dashboard/hooks/use-current-profile';
import { useCurrentProfile } from '@/sections/dashboard/stores/use-current-profile';
import { useProfileSet } from '@/sections/dashboard/hooks/use-profile-set';

interface ProfileNavItemProps {
Expand Down Expand Up @@ -61,16 +61,15 @@ export function ProfileNav() {
const [open, setOpen] = React.useState(false);
const { profileSet, error, isLoading } = useProfileSet();
const { current, setCurrent } = useCurrentProfile();
// const [profileSet, setProfileSet] = useState<ProfileSet>();

useEffect(() => {
if (!isLoading) {
// const parsed: ProfileSet = profileSetSchema.parse(data);
// setProfileSet(parsed);

// const initialProfile: Profile = parsed.profiles[0];
const initialProfile: Profile = profileSet!.profiles[0];
// setCurrent(initialProfile.name);
const defaultProfile = profileSet!.profiles.find(
(value: Profile) => value.name === 'default'
);
const initialProfile: Profile = defaultProfile
? defaultProfile
: profileSet!.profiles[0];
setCurrent(initialProfile.name);
}
}, [profileSet, error, isLoading, setCurrent]);
Expand Down
2 changes: 1 addition & 1 deletion src/sections/dashboard/components/sidebar/side-nav.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
AccordionItem,
AccordionTrigger,
} from '@/sections/dashboard/components/sidebar/subnav-accordion';
import { useSidebar } from '@/sections/dashboard/hooks/use-sidebar';
import { useSidebar } from '@/sections/dashboard/stores/use-sidebar';

import { type LucideIcon } from 'lucide-react';

Expand Down
2 changes: 1 addition & 1 deletion src/sections/dashboard/components/sidebar/sidebar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { cn } from '@/lib/css-utils';
import { Separator } from '@/components/ui/separator';
import { Button } from '@/components/ui/button';
import { ChevronRight, Settings } from 'lucide-react';
import { useSidebar } from '@/sections/dashboard/hooks/use-sidebar';
import { useSidebar } from '@/sections/dashboard/stores/use-sidebar';
import {
NavItem,
SideNav,
Expand Down
16 changes: 0 additions & 16 deletions src/sections/dashboard/stores/profile-set-store.ts

This file was deleted.

0 comments on commit 057b62f

Please sign in to comment.