journal edit
This commit is contained in:
parent
be29a138fc
commit
aaaa42cbd6
|
|
@ -5,20 +5,22 @@
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
entry: HistoryEntry;
|
entry: HistoryEntry;
|
||||||
onedit?: (id: string, text: string) => void;
|
onedit?: (id: string, text: string, date: string) => void;
|
||||||
}
|
}
|
||||||
let { entry, onedit }: Props = $props();
|
let { entry, onedit }: Props = $props();
|
||||||
|
|
||||||
let editing = $state(false);
|
let editing = $state(false);
|
||||||
let editText = $state('');
|
let editText = $state('');
|
||||||
|
let editDate = $state('');
|
||||||
|
|
||||||
function startEdit() {
|
function startEdit() {
|
||||||
editText = entry.text;
|
editText = entry.text;
|
||||||
|
editDate = entry.date;
|
||||||
editing = true;
|
editing = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
function saveEdit() {
|
function saveEdit() {
|
||||||
onedit?.(entry.id, editText);
|
onedit?.(entry.id, editText, editDate);
|
||||||
editing = false;
|
editing = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -50,9 +52,17 @@
|
||||||
onsave={saveEdit}
|
onsave={saveEdit}
|
||||||
minHeight="100px"
|
minHeight="100px"
|
||||||
/>
|
/>
|
||||||
<div class="flex justify-end gap-1 mt-1">
|
<div class="flex items-center gap-2 mt-1 flex-wrap">
|
||||||
<button class="rounded bg-[#444] px-3 py-1 text-sm text-[#ccc] hover:bg-[#555]" onclick={cancelEdit}>Abbrechen</button>
|
<input
|
||||||
<button class="rounded bg-success px-3 py-1 text-sm font-bold text-white" onclick={saveEdit}>Speichern</button>
|
type="date"
|
||||||
|
class="rounded border border-[#444] bg-bg px-2 py-1 text-sm text-white"
|
||||||
|
bind:value={editDate}
|
||||||
|
title="Datum des Eintrags"
|
||||||
|
/>
|
||||||
|
<div class="ml-auto flex gap-1">
|
||||||
|
<button class="rounded bg-[#444] px-3 py-1 text-sm text-[#ccc] hover:bg-[#555]" onclick={cancelEdit}>Abbrechen</button>
|
||||||
|
<button class="rounded bg-success px-3 py-1 text-sm font-bold text-white" onclick={saveEdit}>Speichern</button>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
{:else}
|
{:else}
|
||||||
|
|
|
||||||
|
|
@ -129,13 +129,15 @@
|
||||||
let editTitle = $state('');
|
let editTitle = $state('');
|
||||||
let editBody = $state('');
|
let editBody = $state('');
|
||||||
let editIsPrivate = $state(false);
|
let editIsPrivate = $state(false);
|
||||||
|
let editDate = $state('');
|
||||||
|
|
||||||
function startEdit(entry: { id: string; text: string; isPrivate?: boolean }) {
|
function startEdit(entry: { id: string; text: string; date: string; isPrivate?: boolean }) {
|
||||||
const lines = entry.text.split('\n');
|
const lines = entry.text.split('\n');
|
||||||
editingId = entry.id;
|
editingId = entry.id;
|
||||||
editTitle = lines[0].replace(/^#{1,6}\s+/, '');
|
editTitle = lines[0].replace(/^#{1,6}\s+/, '');
|
||||||
editBody = lines.slice(1).join('\n').trim();
|
editBody = lines.slice(1).join('\n').trim();
|
||||||
editIsPrivate = !!entry.isPrivate;
|
editIsPrivate = !!entry.isPrivate;
|
||||||
|
editDate = entry.date;
|
||||||
}
|
}
|
||||||
|
|
||||||
function cancelEdit() {
|
function cancelEdit() {
|
||||||
|
|
@ -145,7 +147,7 @@
|
||||||
async function saveEdit() {
|
async function saveEdit() {
|
||||||
if (!editingId || !editTitle.trim()) return;
|
if (!editingId || !editTitle.trim()) return;
|
||||||
const text = editBody.trim() ? `${editTitle.trim()}\n${editBody.trim()}` : editTitle.trim();
|
const text = editBody.trim() ? `${editTitle.trim()}\n${editBody.trim()}` : editTitle.trim();
|
||||||
await updateHistoryEntry(editingId, text, editIsPrivate);
|
await updateHistoryEntry(editingId, text, editIsPrivate, editDate || undefined);
|
||||||
editingId = null;
|
editingId = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -332,6 +334,12 @@
|
||||||
class="rounded bg-[#444] px-3 py-1 text-sm text-white hover:bg-[#555]"
|
class="rounded bg-[#444] px-3 py-1 text-sm text-white hover:bg-[#555]"
|
||||||
onclick={cancelEdit}
|
onclick={cancelEdit}
|
||||||
>Abbrechen</button>
|
>Abbrechen</button>
|
||||||
|
<input
|
||||||
|
type="date"
|
||||||
|
class="rounded border border-[#444] bg-bg px-2 py-1 text-sm text-white"
|
||||||
|
bind:value={editDate}
|
||||||
|
title="Datum des Eintrags"
|
||||||
|
/>
|
||||||
<div class="ml-auto flex gap-1 rounded-full bg-[#333] p-0.5">
|
<div class="ml-auto flex gap-1 rounded-full bg-[#333] p-0.5">
|
||||||
<button
|
<button
|
||||||
class="rounded-full px-2.5 py-1 text-xs font-bold transition-all {!editIsPrivate ? 'bg-accent text-white shadow' : 'text-[#aaa] hover:text-white'}"
|
class="rounded-full px-2.5 py-1 text-xs font-bold transition-all {!editIsPrivate ? 'bg-accent text-white shadow' : 'text-[#aaa] hover:text-white'}"
|
||||||
|
|
|
||||||
|
|
@ -114,8 +114,8 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function handleEditHistory(id: string, text: string) {
|
function handleEditHistory(id: string, text: string, date: string) {
|
||||||
updateHistoryEntry(id, text);
|
updateHistoryEntry(id, text, undefined, date);
|
||||||
}
|
}
|
||||||
|
|
||||||
function startTitleEdit() {
|
function startTitleEdit() {
|
||||||
|
|
|
||||||
|
|
@ -283,11 +283,12 @@ export async function convertToTopic(entryId: string, contextId: string): Promis
|
||||||
return topic;
|
return topic;
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function updateHistoryEntry(id: string, text: string, isPrivate?: boolean): Promise<void> {
|
export async function updateHistoryEntry(id: string, text: string, isPrivate?: boolean, date?: string): Promise<void> {
|
||||||
const entry = await db.historyEntries.get(id);
|
const entry = await db.historyEntries.get(id);
|
||||||
if (entry) {
|
if (entry) {
|
||||||
const patch: Record<string, unknown> = { text, updatedAt: now(), version: entry.version + 1 };
|
const patch: Record<string, unknown> = { text, updatedAt: now(), version: entry.version + 1 };
|
||||||
if (isPrivate !== undefined) patch.isPrivate = isPrivate;
|
if (isPrivate !== undefined) patch.isPrivate = isPrivate;
|
||||||
|
if (date !== undefined) patch.date = date;
|
||||||
await db.historyEntries.update(id, patch);
|
await db.historyEntries.update(id, patch);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue