Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: add graceful fallback alternatives for img and link in toolkitpage #70

Merged
merged 3 commits into from
Dec 11, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 20 additions & 12 deletions src/app/toolkit/components/SortableItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ interface SortableItemProps {
const isValidUrl = (url: string | undefined): boolean => {
if (!url) return false;
try {
new URL(url);
new URL(url, window.location.href);
return true;
} catch {
return false;
Expand Down Expand Up @@ -65,17 +65,20 @@ export default function SortableItem({
</div>

{/* Second Row: Image, Link, and Delete Button */}
<div className="flex items-center justify-between mt-2 w-full">
{/* Display the image */}
{isValidUrl(item.imageUrl) ? (
<img
src={item.imageUrl}
alt={item.name}
className="h-10 w-10 object-cover rounded"
/>
) : (
<span className="text-gray-400">No Image</span>
)}
<div className="flex items-center justify-between mt-2 w-full">
{/* Display the image or reserve space */}
{isValidUrl(item.imageUrl) ? (
<img
src={item.imageUrl}
alt={item.name}
className="h-10 w-10 object-cover rounded"
/>
) : (
<div className="h-10 w-10"></div> // Reserve space when no image
)}

{/* Display the link or reserve space */}
{isValidUrl(item.infoUrl) ? (
<a
href={item.infoUrl}
target="_blank"
Expand All @@ -84,6 +87,11 @@ export default function SortableItem({
>
Go to resource
</a>
) : (
<div className="w-24"></div> // Reserve space for the link (adjust width as needed)
)}

{/* Delete button */}
<button
onClick={(e) => {
e.stopPropagation();
Expand Down
Loading