Skip to content

Commit ed025e8

Browse files
committed
refactor: improve widget pack type definitions and card component
1 parent 4f18854 commit ed025e8

File tree

4 files changed

+45
-26
lines changed

4 files changed

+45
-26
lines changed

packages/settings-ui/src/common/desktop/MarketplacePacksContext.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ const marketplacePacksMock: MarketplaceWidgetPack[] = [
129129

130130
type MarketplacePacksContextState = {
131131
allPacks: Resource<MarketplaceWidgetPack[]>;
132-
selectedPack: Resource<MarketplaceWidgetPack>;
132+
selectedPack: Resource<MarketplaceWidgetPack | null>;
133133
previewPack: Accessor<MarketplaceWidgetPack | null>;
134134
install: (pack: MarketplaceWidgetPack) => void;
135135
selectPack: (packId: string) => void;

packages/settings-ui/src/common/desktop/UserPacksContext.tsx

Lines changed: 25 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -87,19 +87,31 @@ const downloadedPacksMock: WidgetPack[] = [
8787
},
8888
];
8989

90-
export type WidgetPack = {
91-
id: string;
92-
name: string;
93-
author: string;
94-
type: 'local' | 'marketplace';
95-
previewImages: string[];
96-
excludeFiles: string;
97-
directoryPath: string;
98-
description: string;
99-
version: string;
100-
widgetConfigs: WidgetConfigEntry[];
101-
tags: string[];
102-
};
90+
export type WidgetPack =
91+
| {
92+
type: 'marketplace';
93+
id: string;
94+
name: string;
95+
author: string;
96+
previewImages: string[];
97+
excludeFiles: string;
98+
directoryPath: string;
99+
description: string;
100+
version: string;
101+
widgetConfigs: WidgetConfigEntry[];
102+
tags: string[];
103+
}
104+
| {
105+
type: 'local';
106+
id: string;
107+
name: string;
108+
previewImages: string[];
109+
excludeFiles: string;
110+
directoryPath: string;
111+
description: string;
112+
widgetConfigs: WidgetConfigEntry[];
113+
tags: string[];
114+
};
103115

104116
export type WidgetConfigEntry = {
105117
absolutePath: string;

packages/settings-ui/src/user-packs/WidgetPackCard.tsx

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,13 @@ import {
1111
} from '@glzr/components';
1212
import { useNavigate } from '@solidjs/router';
1313
import { IconPackage, IconTrash } from '@tabler/icons-solidjs';
14+
import { Show } from 'solid-js';
1415

1516
import { WidgetPack } from '~/common';
1617
import { DeleteWidgetPackDialog } from './dialogs';
1718

1819
export interface WidgetPackCardProps {
1920
pack: WidgetPack;
20-
isLocal: boolean;
2121
onDelete: (packId: string) => void;
2222
}
2323

@@ -35,14 +35,19 @@ export function WidgetPackCard(props: WidgetPackCardProps) {
3535
<CardTitle class="flex items-center gap-2">
3636
<IconPackage class="h-5 w-5" />
3737
{props.pack.name}
38-
<Badge variant="outline" class="ml-2">
39-
{props.pack.version}
40-
</Badge>
38+
39+
{props.pack.type === 'marketplace' && (
40+
<Badge variant="outline" class="ml-2">
41+
{props.pack.version}
42+
</Badge>
43+
)}
4144
</CardTitle>
4245

43-
<CardDescription class="mt-1">
44-
by {props.pack.author}
45-
</CardDescription>
46+
{props.pack.type === 'marketplace' && (
47+
<CardDescription class="mt-1">
48+
by {props.pack.author}
49+
</CardDescription>
50+
)}
4651
</div>
4752

4853
<div class="flex gap-2" onClick={e => e.stopPropagation()}>
@@ -66,16 +71,20 @@ export function WidgetPackCard(props: WidgetPackCardProps) {
6671
</CardHeader>
6772

6873
<CardContent>
69-
<p class="text-sm text-gray-600 dark:text-gray-400 mb-4">
70-
{props.pack.description}
71-
</p>
74+
<Show when={props.pack.description !== ''}>
75+
<p class="text-sm text-gray-600 dark:text-gray-400 mb-4">
76+
{props.pack.description}
77+
</p>
78+
</Show>
79+
7280
<div class="flex flex-wrap gap-2 mb-4">
7381
{props.pack.tags.map(tag => (
7482
<Badge key={tag} variant="secondary">
7583
{tag}
7684
</Badge>
7785
))}
7886
</div>
87+
7988
<div class="text-sm">
8089
<p>
8190
<strong>Widgets:</strong> {props.pack.widgetConfigs.length}

packages/settings-ui/src/user-packs/WidgetPacksPage.tsx

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,6 @@ export function WidgetPacksPage() {
6767
{pack => (
6868
<WidgetPackCard
6969
pack={pack}
70-
isLocal={false}
7170
onDelete={userPacks.deletePack}
7271
/>
7372
)}
@@ -79,7 +78,6 @@ export function WidgetPacksPage() {
7978
{pack => (
8079
<WidgetPackCard
8180
pack={pack}
82-
isLocal={true}
8381
onDelete={userPacks.deletePack}
8482
/>
8583
)}

0 commit comments

Comments
 (0)