feat: add dropdown for favorite items

This commit is contained in:
Sonny
2024-07-22 12:10:47 +02:00
parent 2c499a7789
commit 442a1003bb
12 changed files with 174 additions and 94 deletions

22
inertia/lib/favorite.ts Normal file
View File

@@ -0,0 +1,22 @@
import { route } from '@izzyjs/route/client';
import { makeRequest } from '~/lib/request';
import { Link } from '~/types/app';
export const onFavorite = (
linkId: Link['id'],
isFavorite: boolean,
cb: () => void
) => {
const { url, method } = route('link.toggle-favorite', {
params: { id: linkId.toString() },
});
makeRequest({
url,
method,
body: {
favorite: isFavorite,
},
})
.then(() => cb())
.catch(console.error);
};