mirror of
https://github.com/Sonny93/my-links.git
synced 2025-12-09 15:05:35 +00:00
23 lines
445 B
TypeScript
23 lines
445 B
TypeScript
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);
|
|
};
|