feat: showing limits for list creation

This commit is contained in:
2025-08-30 11:17:24 +01:00
parent 8b54d502f2
commit 48579267b5
2 changed files with 15 additions and 2 deletions

View File

@ -229,6 +229,12 @@ export const postCode = async (
return parse(codeValidator, res); return parse(codeValidator, res);
}; };
export class ReachedListLimit extends Error {
constructor() {
super();
}
}
export const createList = async ( export const createList = async (
title: string, title: string,
description: string, description: string,
@ -241,5 +247,8 @@ export const createList = async (
request.headers.set("Content-Type", "application/json"); request.headers.set("Content-Type", "application/json");
await fetch(request); const res = await fetch(request);
if (!res.ok && res.status == 429) {
throw new ReachedListLimit();
}
}; };

View File

@ -3,7 +3,8 @@ import { useSearchImageContext } from "@contexts/SearchImageContext";
import { ListCard } from "@components/list-card"; import { ListCard } from "@components/list-card";
import { Button } from "@kobalte/core/button"; import { Button } from "@kobalte/core/button";
import { Dialog } from "@kobalte/core/dialog"; import { Dialog } from "@kobalte/core/dialog";
import { createList } from "../../network"; import { createList, ReachedListLimit } from "../../network";
import { createToast } from "../../utils/show-toast";
export const Categories: Component = () => { export const Categories: Component = () => {
const { lists, onRefetchImages } = useSearchImageContext(); const { lists, onRefetchImages } = useSearchImageContext();
@ -27,6 +28,9 @@ export const Categories: Component = () => {
onRefetchImages(); // Refresh the lists onRefetchImages(); // Refresh the lists
} catch (error) { } catch (error) {
console.error("Failed to create list:", error); console.error("Failed to create list:", error);
if (error instanceof ReachedListLimit) {
createToast("Reached limit!", "You've reached your limit for new lists");
}
} finally { } finally {
setIsCreating(false); setIsCreating(false);
} }