Skip to content

Commit

Permalink
update selected component in sidebar
Browse files Browse the repository at this point in the history
  • Loading branch information
clementvt committed Jan 6, 2025
1 parent 023bcb7 commit 3f404b7
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 16 deletions.
7 changes: 7 additions & 0 deletions app/dashboard/[guildId]/loading.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export default function Loading() {
return (
<div>
Loading...
</div>
);
}
8 changes: 4 additions & 4 deletions components/dashboard/guild/editor/appInitialiser.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import { useLeaverStore } from "@/state/leaver";
import { useModuleNameStore } from "@/state/moduleName";
import { useWelcomerStore } from "@/state/welcomer";
import { ModuleName } from "@/types";
import { Leaver, Welcomer } from "@prisma/client";
import { useEffect } from "react";

Expand All @@ -12,13 +13,13 @@ export default function AppInitializer({
children,
}: {
module?: Welcomer | Leaver | null;
moduleName: "welcomer" | "leaver";
moduleName: ModuleName;
guildId: string;
children: React.ReactNode;
}) {

const setModuleName = useModuleNameStore((state) => state.setModuleName);
setModuleName(moduleName);
if (moduleName === "welcomer") {
useModuleNameStore.setState({ moduleName: "welcomer" });
const reset = useWelcomerStore((state) => state.reset);
useEffect(() => {
reset();
Expand All @@ -31,7 +32,6 @@ export default function AppInitializer({
});
}, [module, guildId, reset]);
} else if (moduleName === "leaver") {
useModuleNameStore.setState({ moduleName: "leaver" });
const reset = useLeaverStore((state) => state.reset);
useEffect(() => {
reset();
Expand Down
3 changes: 3 additions & 0 deletions components/dashboard/guild/sideBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ export function Sidebar({
useEffect(() => {
useGuildStore.setState({ id: currentGuild.id });
}, [currentGuild.id]);
useEffect(() => {
setActive(module ?? "dashboard");
}, [module]);
return (
<aside className="h-full z-30 sticky block">
<nav className="h-full flex flex-col bg-slate-800 border-r border-slate-700 shadow-sm">
Expand Down
16 changes: 4 additions & 12 deletions state/moduleName.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { ModuleName } from "@/types";
import { create } from "zustand";
import { persist } from "zustand/middleware";
import { immer } from "zustand/middleware/immer";

export interface ModuleNameParams {
Expand All @@ -9,15 +8,8 @@ export interface ModuleNameParams {
}

export const useModuleNameStore = create<ModuleNameParams>()(
immer(
persist(
(set, get) => ({
moduleName: null,
setModuleName: (moduleName) => set({ moduleName: moduleName }),
}),
{
name: "module",
}
)
)
immer((set, get) => ({
moduleName: null,
setModuleName: (moduleName) => set({ moduleName: moduleName }),
}))
);

0 comments on commit 3f404b7

Please sign in to comment.