Skip to content

Commit

Permalink
feat: add mock create/delete to UserPacksContext
Browse files Browse the repository at this point in the history
  • Loading branch information
lars-berger committed Feb 9, 2025
1 parent 10123ff commit 9643b35
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,17 @@ export type WidgetPack = {
tags: string[];
};

export type CreateWidgetPackForm = {
name: string;
};

type UserPacksContextState = {
communityPacks: Resource<WidgetPack[]>;
localPacks: Resource<WidgetPack[]>;
widgetConfigs: Resource<Record<string, WidgetConfig>>;
widgetStates: Resource<Record<string, Widget>>;
createPack: (pack: CreateWidgetPackForm) => void;
deletePack: (packId: string) => void;
updateWidgetConfig: (
configPath: string,
newConfig: WidgetConfig,
Expand Down Expand Up @@ -146,13 +152,23 @@ export function UserPacksProvider(props: { children: JSX.Element }) {
}
}

async function createPack(pack: CreateWidgetPackForm) {
// TODO
}

async function deletePack(packId: string) {
// TODO
}

const store: UserPacksContextState = {
communityPacks,
localPacks,
widgetConfigs,
widgetStates,
updateWidgetConfig,
togglePreset,
createPack,
deletePack,
};

return (
Expand Down
2 changes: 1 addition & 1 deletion packages/settings-ui/src/common/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export * from './desktop/UserWidgetPacksContext';
export * from './desktop/UserPacksContext';
export * from './layout/AppLayout';
export * from './layout/Sidebar';
export * from './layout/SidebarItem';
2 changes: 1 addition & 1 deletion packages/settings-ui/src/common/layout/Sidebar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
} from '@tabler/icons-solidjs';

import { SidebarItem } from './SidebarItem';
import { useUserPacks } from '../desktop/UserWidgetPacksContext';
import { useUserPacks } from '~/common';

export interface SidebarProps {
initialSize: number;
Expand Down
36 changes: 9 additions & 27 deletions packages/settings-ui/src/user-packs/WidgetPacks.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,28 +12,10 @@ import { For } from 'solid-js';

import { useUserPacks } from '~/common';
import { WidgetPackCard } from './WidgetPackCard';
import {
CreateWidgetPackDialog,
CreateWidgetPackForm,
} from './dialogs/CreateWidgetPackDialog';
import { CreateWidgetPackDialog } from './dialogs/CreateWidgetPackDialog';

export function WidgetPacks() {
const {
widgetConfigs,
widgetStates,
updateWidgetConfig,
togglePreset,
communityPacks,
localPacks,
} = useUserPacks();

function handleDeletePack(packId: string) {
// TODO
}

function handleCreatePack(pack: CreateWidgetPackForm) {
// TODO
}
const userPacks = useUserPacks();

return (
<div class="container mx-auto p-6">
Expand All @@ -47,7 +29,7 @@ export function WidgetPacks() {
Create New Pack
</Button>
</DialogTrigger>
<CreateWidgetPackDialog onSubmit={handleCreatePack} />
<CreateWidgetPackDialog onSubmit={userPacks.createPack} />
</Dialog>

<Button variant="outline">
Expand All @@ -60,32 +42,32 @@ export function WidgetPacks() {
<Tabs defaultValue="installed" class="w-full">
<TabsList>
<TabsTrigger value="installed">
Installed ({communityPacks.length})
Installed ({userPacks.communityPacks()?.length})
</TabsTrigger>
<TabsTrigger value="local">
Local ({localPacks.length})
Local ({userPacks.localPacks()?.length})
</TabsTrigger>
</TabsList>

<TabsContent value="installed" class="mt-6">
<For each={communityPacks()}>
<For each={userPacks.communityPacks()}>
{pack => (
<WidgetPackCard
pack={pack}
isLocal={false}
onDelete={handleDeletePack}
onDelete={userPacks.deletePack}
/>
)}
</For>
</TabsContent>

<TabsContent value="local" class="mt-6">
<For each={localPacks()}>
<For each={userPacks.localPacks()}>
{pack => (
<WidgetPackCard
pack={pack}
isLocal={true}
onDelete={handleDeletePack}
onDelete={userPacks.deletePack}
/>
)}
</For>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,7 @@ import {
} from '@glzr/components';
import { createForm, Field } from 'smorf';

export type CreateWidgetPackForm = {
name: string;
};
import { CreateWidgetPackForm } from '~/common';

export interface CreateWidgetPackDialogProps {
onSubmit: (pack: CreateWidgetPackForm) => void;
Expand Down

0 comments on commit 9643b35

Please sign in to comment.