style(journals): apply expanded 80-width formatting and snake_case
- Batch formatted all Journals module files using Prettier with printWidth: 80. - Refactored preventDefault to prevent_default across all Svelte components. - Standardized line breaks for imports and long attribute lists for better readability. - Ensured consistent snake_case naming for internal identifiers.
This commit is contained in:
@@ -1,7 +1,17 @@
|
||||
<script lang="ts">
|
||||
import { Modal } from 'flowbite-svelte';
|
||||
import { Upload, FileText, AlertCircle, Check, X, RefreshCw } from 'lucide-svelte';
|
||||
import { PARSERS, type AeJournalEntryInput } from '$lib/ae_journals/ae_journals_parsers';
|
||||
import {
|
||||
Upload,
|
||||
FileText,
|
||||
AlertCircle,
|
||||
Check,
|
||||
X,
|
||||
RefreshCw
|
||||
} from 'lucide-svelte';
|
||||
import {
|
||||
PARSERS,
|
||||
type AeJournalEntryInput
|
||||
} from '$lib/ae_journals/ae_journals_parsers';
|
||||
import { journals_func } from '$lib/ae_journals/ae_journals_functions';
|
||||
import { ae_api } from '$lib/stores/ae_stores';
|
||||
import { journals_slct } from '$lib/ae_journals/ae_journals_stores';
|
||||
@@ -12,7 +22,11 @@
|
||||
on_import_complete: () => void;
|
||||
}
|
||||
|
||||
let { open = $bindable(false), on_close, on_import_complete }: Props = $props();
|
||||
let {
|
||||
open = $bindable(false),
|
||||
on_close,
|
||||
on_import_complete
|
||||
}: Props = $props();
|
||||
|
||||
let files: FileList | null = $state(null);
|
||||
let selected_parser: keyof typeof PARSERS = $state('standard');
|
||||
@@ -30,28 +44,28 @@
|
||||
});
|
||||
|
||||
function handle_drag_enter(e: DragEvent) {
|
||||
e.preventDefault();
|
||||
e.prevent_default();
|
||||
e.stopPropagation();
|
||||
is_dragging = true;
|
||||
}
|
||||
|
||||
function handle_drag_leave(e: DragEvent) {
|
||||
e.preventDefault();
|
||||
e.prevent_default();
|
||||
e.stopPropagation();
|
||||
is_dragging = false;
|
||||
}
|
||||
|
||||
function handle_drag_over(e: DragEvent) {
|
||||
e.preventDefault();
|
||||
e.prevent_default();
|
||||
e.stopPropagation();
|
||||
is_dragging = true;
|
||||
}
|
||||
|
||||
function handle_drop(e: DragEvent) {
|
||||
e.preventDefault();
|
||||
e.prevent_default();
|
||||
e.stopPropagation();
|
||||
is_dragging = false;
|
||||
|
||||
|
||||
if (e.dataTransfer?.files && e.dataTransfer.files.length > 0) {
|
||||
files = e.dataTransfer.files;
|
||||
}
|
||||
@@ -61,9 +75,9 @@
|
||||
if (!files) return;
|
||||
is_parsing = true;
|
||||
parsed_entries = [];
|
||||
|
||||
|
||||
const parser = PARSERS[selected_parser];
|
||||
|
||||
|
||||
for (let i = 0; i < files.length; i++) {
|
||||
const file = files[i];
|
||||
try {
|
||||
@@ -84,7 +98,9 @@
|
||||
|
||||
const journal_id = $journals_slct.journal_id;
|
||||
if (!journal_id) {
|
||||
alert("No target journal selected. Please select a journal in the background first.");
|
||||
alert(
|
||||
'No target journal selected. Please select a journal in the background first.'
|
||||
);
|
||||
is_importing = false;
|
||||
return;
|
||||
}
|
||||
@@ -122,7 +138,9 @@
|
||||
}
|
||||
|
||||
is_importing = false;
|
||||
alert(`Import complete! ${success_count}/${parsed_entries.length} imported.`);
|
||||
alert(
|
||||
`Import complete! ${success_count}/${parsed_entries.length} imported.`
|
||||
);
|
||||
on_import_complete();
|
||||
open = false;
|
||||
}
|
||||
@@ -130,7 +148,7 @@
|
||||
|
||||
<Modal
|
||||
title="Import Journal Entries"
|
||||
bind:open={open}
|
||||
bind:open
|
||||
autoclose={false}
|
||||
size="xl"
|
||||
class="w-full"
|
||||
@@ -142,8 +160,12 @@
|
||||
<label class="label">
|
||||
<span>Parser Strategy</span>
|
||||
<select class="select" bind:value={selected_parser}>
|
||||
<option value="standard">Standard (1 File = 1 Entry)</option>
|
||||
<option value="personal_log">Personal Log (Split by Date)</option>
|
||||
<option value="standard"
|
||||
>Standard (1 File = 1 Entry)</option
|
||||
>
|
||||
<option value="personal_log"
|
||||
>Personal Log (Split by Date)</option
|
||||
>
|
||||
<option value="amazon_vine">Amazon Vine Reviews</option>
|
||||
</select>
|
||||
</label>
|
||||
@@ -152,50 +174,60 @@
|
||||
<div class="label mb-2">
|
||||
<span>Select Files</span>
|
||||
</div>
|
||||
|
||||
|
||||
<!-- Drop Zone -->
|
||||
<!-- svelte-ignore a11y_click_events_have_key_events -->
|
||||
<!-- svelte-ignore a11y_no_static_element_interactions -->
|
||||
<div
|
||||
<div
|
||||
class="
|
||||
border-2 border-dashed rounded-lg p-8 text-center cursor-pointer transition-all duration-200
|
||||
flex flex-col items-center justify-center gap-2
|
||||
{is_dragging ? 'border-primary-500 bg-primary-50 dark:bg-primary-900/20' : 'border-gray-300 dark:border-gray-600 hover:border-gray-400 dark:hover:border-gray-500'}
|
||||
{is_dragging
|
||||
? 'border-primary-500 bg-primary-50 dark:bg-primary-900/20'
|
||||
: 'border-gray-300 dark:border-gray-600 hover:border-gray-400 dark:hover:border-gray-500'}
|
||||
"
|
||||
ondragenter={handle_drag_enter}
|
||||
ondragleave={handle_drag_leave}
|
||||
ondragover={handle_drag_over}
|
||||
ondrop={handle_drop}
|
||||
onclick={() => document.getElementById('file_import_input')?.click()}
|
||||
onclick={() =>
|
||||
document.getElementById('file_import_input')?.click()}
|
||||
>
|
||||
<Upload class="h-10 w-10 text-gray-400" />
|
||||
<p class="text-sm text-gray-500">
|
||||
<span class="font-semibold text-primary-600 hover:text-primary-500">Click to upload</span>
|
||||
<span
|
||||
class="font-semibold text-primary-600 hover:text-primary-500"
|
||||
>Click to upload</span
|
||||
>
|
||||
or drag and drop
|
||||
</p>
|
||||
<p class="text-xs text-gray-400">Markdown (.md) or Text (.txt) files</p>
|
||||
|
||||
<input
|
||||
<p class="text-xs text-gray-400">
|
||||
Markdown (.md) or Text (.txt) files
|
||||
</p>
|
||||
|
||||
<input
|
||||
id="file_import_input"
|
||||
type="file"
|
||||
class="hidden"
|
||||
multiple
|
||||
type="file"
|
||||
class="hidden"
|
||||
multiple
|
||||
accept=".md,.txt"
|
||||
onchange={(e) => files = e.currentTarget.files}
|
||||
onchange={(e) => (files = e.currentTarget.files)}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Preview -->
|
||||
<div class="border rounded-lg p-2 bg-gray-50 dark:bg-gray-900 max-h-64 overflow-y-auto">
|
||||
<div
|
||||
class="border rounded-lg p-2 bg-gray-50 dark:bg-gray-900 max-h-64 overflow-y-auto"
|
||||
>
|
||||
<h4 class="font-bold mb-2 flex justify-between">
|
||||
<span>Preview ({parsed_entries.length} entries)</span>
|
||||
{#if is_parsing}
|
||||
<RefreshCw class="animate-spin" />
|
||||
{/if}
|
||||
</h4>
|
||||
|
||||
|
||||
{#if parsed_entries.length > 0}
|
||||
<table class="table table-compact w-full text-xs">
|
||||
<thead>
|
||||
@@ -208,23 +240,32 @@
|
||||
<tbody>
|
||||
{#each parsed_entries as entry}
|
||||
<tr>
|
||||
<td class="truncate max-w-[200px]" title={entry.name}>{entry.name}</td>
|
||||
<td>{entry.created_on?.substring(0,10)}</td>
|
||||
<td
|
||||
class="truncate max-w-[200px]"
|
||||
title={entry.name}>{entry.name}</td
|
||||
>
|
||||
<td>{entry.created_on?.substring(0, 10)}</td>
|
||||
<td>{entry.tags.join(', ')}</td>
|
||||
</tr>
|
||||
{/each}
|
||||
</tbody>
|
||||
</table>
|
||||
{:else if files && files.length > 0 && !is_parsing}
|
||||
<div class="text-center text-gray-500 py-4">No entries found in selected files.</div>
|
||||
<div class="text-center text-gray-500 py-4">
|
||||
No entries found in selected files.
|
||||
</div>
|
||||
{:else if !files}
|
||||
<div class="text-center text-gray-500 py-4">Select files to preview import.</div>
|
||||
<div class="text-center text-gray-500 py-4">
|
||||
Select files to preview import.
|
||||
</div>
|
||||
{/if}
|
||||
</div>
|
||||
|
||||
<!-- Import Log -->
|
||||
{#if import_log.length > 0}
|
||||
<div class="bg-black text-green-400 p-2 rounded text-xs font-mono max-h-32 overflow-y-auto">
|
||||
<div
|
||||
class="bg-black text-green-400 p-2 rounded text-xs font-mono max-h-32 overflow-y-auto"
|
||||
>
|
||||
{#each import_log as log}
|
||||
<div>{log}</div>
|
||||
{/each}
|
||||
@@ -232,9 +273,14 @@
|
||||
{/if}
|
||||
|
||||
<div class="modal-action">
|
||||
<button type="button" class="btn preset-tonal-secondary" onclick={on_close}>Cancel</button>
|
||||
<button type="button"
|
||||
class="btn preset-filled-primary"
|
||||
<button
|
||||
type="button"
|
||||
class="btn preset-tonal-secondary"
|
||||
onclick={on_close}>Cancel</button
|
||||
>
|
||||
<button
|
||||
type="button"
|
||||
class="btn preset-filled-primary"
|
||||
disabled={parsed_entries.length === 0 || is_importing}
|
||||
onclick={handle_import}
|
||||
>
|
||||
|
||||
Reference in New Issue
Block a user