Skip to content

Commit 217a734

Browse files
committed
Add fallback logo handling for scripts in ScriptBrowser, ScriptItem, and CommandMenu components
1 parent bf429b7 commit 217a734

File tree

3 files changed

+64
-52
lines changed

3 files changed

+64
-52
lines changed

src/app/scripts/_components/ScriptBrowser.tsx

Lines changed: 56 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -115,59 +115,63 @@ const ScriptBrowser = ({
115115
}
116116
className="pt-0"
117117
>
118-
{category.expand.items
119-
.slice()
120-
.sort((a, b) => a.title.localeCompare(b.title))
121-
.map((script, index) => (
122-
<div key={index}>
123-
<Link
124-
href={{
125-
pathname: "/scripts",
126-
query: { id: script.title },
127-
}}
128-
prefetch={false}
129-
className={`flex cursor-pointer items-center justify-between gap-1 px-1 py-1 text-muted-foreground hover:rounded-lg hover:bg-accent/60 hover:dark:bg-accent/20 ${
130-
selectedScript === script.title
131-
? "rounded-lg bg-accent font-semibold dark:bg-accent/30 dark:text-white"
132-
: ""
133-
}`}
134-
onClick={() => handleSelected(script.title)}
135-
ref={(el) => {
136-
linkRefs.current[script.title] = el;
137-
}}
138-
>
139-
<Image
140-
src={script.logo}
141-
height={16}
142-
width={16}
143-
unoptimized
144-
alt={script.title}
145-
className="mr-1 w-4 h-4 rounded-full"
146-
/>
147-
<span className="flex items-center gap-2">
148-
{script.title}
149-
{script.isMostViewed && (
150-
<Star className="h-3 w-3 text-yellow-500"></Star>
151-
)}
152-
</span>
153-
<Badge
154-
className={classNames(
155-
"ml-auto w-[37.69px] justify-center text-center",
156-
{
157-
"text-primary/75": script.item_type === "VM",
158-
"text-yellow-500/75": script.item_type === "LXC",
159-
"border-none": script.item_type === "",
160-
hidden: !["VM", "LXC", ""].includes(
161-
script.item_type,
162-
),
163-
},
164-
)}
118+
{category.expand.items
119+
.slice()
120+
.sort((a, b) => a.title.localeCompare(b.title))
121+
.map((script, index) => (
122+
<div key={index}>
123+
<Link
124+
href={{
125+
pathname: "/scripts",
126+
query: { id: script.title },
127+
}}
128+
prefetch={false}
129+
className={`flex cursor-pointer items-center justify-between gap-1 px-1 py-1 text-muted-foreground hover:rounded-lg hover:bg-accent/60 hover:dark:bg-accent/20 ${
130+
selectedScript === script.title
131+
? "rounded-lg bg-accent font-semibold dark:bg-accent/30 dark:text-white"
132+
: ""
133+
}`}
134+
onClick={() => handleSelected(script.title)}
135+
ref={(el) => {
136+
linkRefs.current[script.title] = el;
137+
}}
165138
>
166-
{script.item_type}
167-
</Badge>
168-
</Link>
169-
</div>
170-
))}
139+
<Image
140+
src={script.logo}
141+
height={16}
142+
width={16}
143+
unoptimized
144+
onError={(e) =>
145+
((e.currentTarget as HTMLImageElement).src =
146+
"/logo.png")
147+
}
148+
alt={script.title}
149+
className="mr-1 w-4 h-4 rounded-full"
150+
/>
151+
<span className="flex items-center gap-2">
152+
{script.title}
153+
{script.isMostViewed && (
154+
<Star className="h-3 w-3 text-yellow-500"></Star>
155+
)}
156+
</span>
157+
<Badge
158+
className={classNames(
159+
"ml-auto w-[37.69px] justify-center text-center",
160+
{
161+
"text-primary/75": script.item_type === "VM",
162+
"text-yellow-500/75": script.item_type === "LXC",
163+
"border-none": script.item_type === "",
164+
hidden: !["VM", "LXC", ""].includes(
165+
script.item_type,
166+
),
167+
},
168+
)}
169+
>
170+
{script.item_type}
171+
</Badge>
172+
</Link>
173+
</div>
174+
))}
171175
</AccordionContent>
172176
</AccordionItem>
173177
))}

src/app/scripts/_components/ScriptItem.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,10 @@ function ScriptItem({
6666
className="h-32 w-32 rounded-lg bg-accent/60 object-contain p-3 shadow-md"
6767
src={item.logo}
6868
width={400}
69+
onError={(e) =>
70+
((e.currentTarget as HTMLImageElement).src =
71+
"/logo.png")
72+
}
6973
height={400}
7074
alt={item.title}
7175
unoptimized

src/components/CommandMenu.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,10 @@ export default function CommandMenu() {
106106
src={script.logo}
107107
unoptimized
108108
height={16}
109+
onError={(e) =>
110+
((e.currentTarget as HTMLImageElement).src =
111+
"/logo.png")
112+
}
109113
width={16}
110114
alt=""
111115
className="h-5 w-5"

0 commit comments

Comments
 (0)