Add favorites feature - toggle, list, and pre-fill on add
This commit is contained in:
@@ -36,6 +36,16 @@ export default function EntryDetail() {
|
||||
window.location.href = returnDate ? '/?date=' + returnDate : '/';
|
||||
}
|
||||
|
||||
async function toggleFavorite() {
|
||||
try {
|
||||
const res = await fetch('/api/entries/' + id + '/favorite', { method: 'POST' });
|
||||
const data = await res.json();
|
||||
setEntry({ ...entry, favorite: data.favorite });
|
||||
} catch (err) {
|
||||
console.error(err);
|
||||
}
|
||||
}
|
||||
|
||||
const bgCard = darkMode ? 'bg-gray-800' : 'bg-white';
|
||||
const textMain = darkMode ? 'text-white' : 'text-gray-900';
|
||||
const textMuted = darkMode ? 'text-gray-400' : 'text-gray-500';
|
||||
@@ -49,7 +59,17 @@ export default function EntryDetail() {
|
||||
<Layout>
|
||||
<Link to={returnUrl} className="text-emerald-500 mb-4 block">← Back</Link>
|
||||
|
||||
<h1 className={"text-2xl font-bold mb-2 " + textMain}>{entry.name}</h1>
|
||||
<div className="flex items-center gap-2">
|
||||
<h1 className={"text-2xl font-bold mb-2 flex-1 " + textMain}>{entry.name}</h1>
|
||||
<button
|
||||
onClick={toggleFavorite}
|
||||
className="text-3xl"
|
||||
title={entry.favorite ? "Remove from favorites" : "Add to favorites"}
|
||||
>
|
||||
{entry.favorite ? '⭐' : '☆'}
|
||||
</button>
|
||||
</div>
|
||||
|
||||
{entry.description && <p className={textMuted + " mb-4"}>{entry.description}</p>}
|
||||
|
||||
{entry.image_url && (
|
||||
@@ -89,9 +109,11 @@ export default function EntryDetail() {
|
||||
</div>
|
||||
)}
|
||||
|
||||
<button onClick={handleDelete} className="w-full bg-red-500 hover:bg-red-600 text-white py-3 rounded-xl font-semibold">
|
||||
Delete Entry
|
||||
</button>
|
||||
<div className="flex gap-2">
|
||||
<button onClick={handleDelete} className="flex-1 bg-red-500 hover:bg-red-600 text-white py-3 rounded-xl font-semibold">
|
||||
Delete Entry
|
||||
</button>
|
||||
</div>
|
||||
</Layout>
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user