journal edit
This commit is contained in:
parent
be29a138fc
commit
aaaa42cbd6
|
|
@ -5,20 +5,22 @@
|
|||
|
||||
interface Props {
|
||||
entry: HistoryEntry;
|
||||
onedit?: (id: string, text: string) => void;
|
||||
onedit?: (id: string, text: string, date: string) => void;
|
||||
}
|
||||
let { entry, onedit }: Props = $props();
|
||||
|
||||
let editing = $state(false);
|
||||
let editText = $state('');
|
||||
let editDate = $state('');
|
||||
|
||||
function startEdit() {
|
||||
editText = entry.text;
|
||||
editDate = entry.date;
|
||||
editing = true;
|
||||
}
|
||||
|
||||
function saveEdit() {
|
||||
onedit?.(entry.id, editText);
|
||||
onedit?.(entry.id, editText, editDate);
|
||||
editing = false;
|
||||
}
|
||||
|
||||
|
|
@ -50,11 +52,19 @@
|
|||
onsave={saveEdit}
|
||||
minHeight="100px"
|
||||
/>
|
||||
<div class="flex justify-end gap-1 mt-1">
|
||||
<div class="flex items-center gap-2 mt-1 flex-wrap">
|
||||
<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">
|
||||
<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>
|
||||
{:else}
|
||||
<RenderedMarkdown text={entry.text} />
|
||||
{/if}
|
||||
|
|
|
|||
|
|
@ -129,13 +129,15 @@
|
|||
let editTitle = $state('');
|
||||
let editBody = $state('');
|
||||
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');
|
||||
editingId = entry.id;
|
||||
editTitle = lines[0].replace(/^#{1,6}\s+/, '');
|
||||
editBody = lines.slice(1).join('\n').trim();
|
||||
editIsPrivate = !!entry.isPrivate;
|
||||
editDate = entry.date;
|
||||
}
|
||||
|
||||
function cancelEdit() {
|
||||
|
|
@ -145,7 +147,7 @@
|
|||
async function saveEdit() {
|
||||
if (!editingId || !editTitle.trim()) return;
|
||||
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;
|
||||
}
|
||||
|
||||
|
|
@ -332,6 +334,12 @@
|
|||
class="rounded bg-[#444] px-3 py-1 text-sm text-white hover:bg-[#555]"
|
||||
onclick={cancelEdit}
|
||||
>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">
|
||||
<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'}"
|
||||
|
|
|
|||
|
|
@ -114,8 +114,8 @@
|
|||
}
|
||||
}
|
||||
|
||||
function handleEditHistory(id: string, text: string) {
|
||||
updateHistoryEntry(id, text);
|
||||
function handleEditHistory(id: string, text: string, date: string) {
|
||||
updateHistoryEntry(id, text, undefined, date);
|
||||
}
|
||||
|
||||
function startTitleEdit() {
|
||||
|
|
|
|||
|
|
@ -283,11 +283,12 @@ export async function convertToTopic(entryId: string, contextId: string): Promis
|
|||
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);
|
||||
if (entry) {
|
||||
const patch: Record<string, unknown> = { text, updatedAt: now(), version: entry.version + 1 };
|
||||
if (isPrivate !== undefined) patch.isPrivate = isPrivate;
|
||||
if (date !== undefined) patch.date = date;
|
||||
await db.historyEntries.update(id, patch);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue