Saving my changes. Cleaning up the comments.

This commit is contained in:
Scott Idem
2026-01-08 17:37:40 -05:00
parent f35a1a10d0
commit 3d98233c84
3 changed files with 371 additions and 103 deletions

View File

@@ -0,0 +1,142 @@
<script lang="ts">
/**
* JournalEntry_SettingsMenu.svelte
* Extracted 2026-01-08 to modularize the Journal Entry Header.
* Manages Category, Priority, Sort, and Deletion.
*/
import {
Plus, Minus, ArrowDown10, Flag, FlagOff,
Eye, EyeOff, ShieldCheck, ShieldMinus,
Clock, X, Trash2
} from '@lucide/svelte';
import { ae_loc, ae_api } from '$lib/stores/ae_stores';
import { journals_slct } from '$lib/ae_journals/ae_journals_stores';
import { journals_func } from '$lib/ae_journals/ae_journals_functions';
import { goto } from '$app/navigation';
import type { ae_JournalEntry, ae_Journal } from '$lib/types/ae_types';
interface Props {
entry: ae_JournalEntry;
journal: ae_Journal;
tmp_entry_obj: any; // Bindable
onSave: () => void;
log_lvl?: number;
}
let { entry, journal, tmp_entry_obj = $bindable(), onSave, log_lvl = 0 }: Props = $props();
async function delete_entry() {
if (confirm(`Are you sure you want to delete this journal entry?`)) {
let delete_method = 'disable';
if ($ae_loc.administrator_access && $ae_loc.edit_mode) {
delete_method = 'delete';
}
try {
await journals_func.delete_ae_obj_id__journal_entry({
api_cfg: $ae_api,
journal_entry_id: entry.journal_entry_id,
method: delete_method,
log_lvl
});
alert('Journal entry deleted successfully!');
goto(`/journals/${$journals_slct.journal_id}`);
} catch (error) {
console.error('Error deleting journal entry:', error);
alert('Failed to delete journal entry.');
}
}
}
</script>
<div class="space-y-4">
<!-- Category -->
<div class="flex flex-row items-center justify-evenly gap-2 w-full">
<span class="text-sm text-gray-500 hidden sm:inline"> Category: </span>
<select
class="select select-sm preset-tonal-primary w-full"
bind:value={tmp_entry_obj.category_code}
onchange={onSave}
title="Select a category"
>
<option value="">Select Category</option>
{#each journal?.cfg_json.category_li ?? [] as category}
<option value={category.code}>{category.name}</option>
{/each}
</select>
</div>
<!-- Priority Toggle -->
<button
type="button"
onclick={() => {
tmp_entry_obj.priority = !entry.priority;
onSave();
}}
class="btn w-full mb-2 preset-tonal-tertiary transition hover:preset-filled-tertiary-500"
>
{#if entry.priority}
<Flag size="1.25em" class="text-success-500 mr-2" />
{:else}
<FlagOff size="1.25em" class="opacity-50 mr-2" />
{/if}
<span>Priority Status</span>
</button>
<!-- Sort Order -->
<div class="w-full flex flex-row items-center justify-center border border-surface-500/30 rounded-lg p-1 bg-surface-500/5">
<button
type="button"
onclick={() => {
tmp_entry_obj.sort = (entry.sort ?? 0) + 1;
onSave();
}}
class="btn-icon btn-icon-sm preset-tonal-surface hover:preset-filled-secondary-500"
>
<Plus size="1em" />
</button>
<span class="mx-4 font-bold text-base min-w-[1.5em] text-center">
{tmp_entry_obj.sort ?? entry.sort ?? 0}
</span>
<button
type="button"
onclick={() => {
tmp_entry_obj.sort = Math.max(0, (entry.sort ?? 0) - 1);
onSave();
}}
class="btn-icon btn-icon-sm preset-tonal-surface hover:preset-filled-secondary-500"
>
<Minus size="1em" />
</button>
</div>
<div class="divider"></div>
<!-- Archive On -->
<div class="flex flex-row items-center justify-between gap-2 border border-surface-500/20 rounded p-1">
<input
type="datetime-local"
bind:value={tmp_entry_obj.archive_on}
onchange={onSave}
class="input input-sm border-none bg-transparent"
/>
{#if entry.archive_on}
<button onclick={() => { tmp_entry_obj.archive_on = null; onSave(); }} class="text-error-500">
<X size="1.2em" />
</button>
{:else}
<button onclick={() => { tmp_entry_obj.archive_on = new Date().toISOString().slice(0, 16); onSave(); }} class="text-primary-500">
<Clock size="1.2em" />
</button>
{/if}
</div>
<!-- Danger Zone: Delete -->
<button
type="button"
onclick={delete_entry}
class="btn variant-filled-error w-full mt-4"
>
<Trash2 size="1.25em" class="mr-2" />
Delete Entry
</button>
</div>