diff --git a/src/lib/ae_core/ae_comp__hosted_files_download_button.svelte b/src/lib/ae_core/ae_comp__hosted_files_download_button.svelte index ae86d26e..dee37beb 100644 --- a/src/lib/ae_core/ae_comp__hosted_files_download_button.svelte +++ b/src/lib/ae_core/ae_comp__hosted_files_download_button.svelte @@ -108,7 +108,7 @@ $effect(() => { }); }} - title={`Download this file:\n${filename ?? hosted_file_obj.filename}\n[API] SHA256: ${hosted_file_obj?.hash_sha256.slice(0, 10)}...\nHosted ID: ${hosted_file_obj.hosted_file_id_random}\n Linked to: ${linked_to_type} ID: ${linked_to_id}`} + title={`Download this file:\n${filename ?? hosted_file_obj?.filename}\n[API] SHA256: ${hosted_file_obj?.hash_sha256?.slice(0, 10)}...\nHosted ID: ${hosted_file_obj?.hosted_file_id_random}\n Linked to: ${linked_to_type} ID: ${linked_to_id}`} > {#await ae_promises[hosted_file_obj.hosted_file_id_random]} diff --git a/src/lib/ae_core/ae_comp__hosted_files_upload.svelte b/src/lib/ae_core/ae_comp__hosted_files_upload.svelte index c0658026..0690b3c1 100644 --- a/src/lib/ae_core/ae_comp__hosted_files_upload.svelte +++ b/src/lib/ae_core/ae_comp__hosted_files_upload.svelte @@ -166,12 +166,20 @@ async function handle_input_upload_files( hosted_file_obj_li.push(hosted_file_obj); let hosted_file_data: key_val = {}; + hosted_file_data['id'] = hosted_file_id; + hosted_file_data['hosted_file_id'] = hosted_file_id; hosted_file_data['hosted_file_id_random'] = hosted_file_id; hosted_file_data['for_type'] = link_to_type; + hosted_file_data['for_id'] = link_to_id; hosted_file_data['for_id_random'] = link_to_id; + hosted_file_data['hash_sha256'] = hosted_file_obj.hash_sha256; hosted_file_data['filename'] = hosted_file_obj.filename; hosted_file_data['extension'] = hosted_file_obj.extension; + hosted_file_data['content_type'] = hosted_file_obj.content_type; + hosted_file_data['size'] = hosted_file_obj.size; hosted_file_data['enable'] = true; + hosted_file_data['created_on'] = hosted_file_obj.created_on; + hosted_file_data['updated_on'] = hosted_file_obj.updated_on; console.log(hosted_file_data); hosted_file_obj_kv[hosted_file_id] = hosted_file_data; diff --git a/src/lib/element_manage_hosted_file_li_all.svelte b/src/lib/element_manage_hosted_file_li_all.svelte index 47dd13a1..cc2f9a68 100644 --- a/src/lib/element_manage_hosted_file_li_all.svelte +++ b/src/lib/element_manage_hosted_file_li_all.svelte @@ -69,7 +69,8 @@ let lq__hosted_file_obj_li = $derived(liveQuery(async () => { results = await db_core.file .where(dq__where_val) .equals(dq__where_eq_val) - .sortBy('created_on'); + .sortBy('created_on') + ; } else if (file_type == 'video') { // Handle video/mp4, video/mov, video/webm. If the content type is prefixed with "video/", then it is a video file. let extension = 'mp4'; diff --git a/src/routes/journals/ae_comp__journal_entry_obj_file_li.svelte b/src/routes/journals/ae_comp__journal_entry_obj_file_li.svelte index 9195a6f5..63e06996 100644 --- a/src/routes/journals/ae_comp__journal_entry_obj_file_li.svelte +++ b/src/routes/journals/ae_comp__journal_entry_obj_file_li.svelte @@ -10,6 +10,7 @@ import { journals_func } from '$lib/ae_journals/ae_journals_functions'; import Comp_hosted_files_upload from '$lib/ae_core/ae_comp__hosted_files_upload.svelte'; import Element_manage_hosted_file_li_wrap from '$lib/element_manage_hosted_file_li_all.svelte'; + import { keymap } from '@codemirror/view'; interface Props { @@ -29,8 +30,8 @@ let { let ae_promises: key_val = $state({}); let hosted_file_kv: key_val = $state($lq__journal_entry_obj?.data_json?.hosted_file_kv ?? {}); // WARNING: This does no seem to set soon enough. Added an effect to set it as a backup. // let hosted_file_li: [string, any][] = $state([]); -let hosted_file_obj_li: any[] = $state($lq__journal_entry_obj?.data_json?.hosted_file_obj_li ?? []); -let hosted_file_id_li: string[] = $state([]); +let slct_hosted_file_obj_li: any[] = $state($lq__journal_entry_obj?.data_json?.slct_hosted_file_obj_li ?? []); +let slct_hosted_file_id_li: string[] = $state([]); let upload_complete: boolean = $state(false); let slct_hosted_file_kv: key_val = $state({}); @@ -41,7 +42,7 @@ let rem_hosted_file_id: string|null = $state(null); async function update_journal_entry() { // hosted_file_kv = lq__journal_entry_obj.data_json.hosted_file_kv; - // hosted_file_obj_li = [... $lq__journal_entry_obj?.data_json?.hosted_file_obj_li]; + // slct_hosted_file_obj_li = [... $lq__journal_entry_obj?.data_json?.slct_hosted_file_obj_li]; // hosted_file_kv = { // ...$lq__journal_entry_obj?.data_json?.hosted_file_kv, // }; @@ -54,7 +55,7 @@ async function update_journal_entry() { // hosted_file_kv: { // ...slct_hosted_file_kv, // }, - // hosted_file_obj_li: hosted_file_obj_li + // slct_hosted_file_obj_li: slct_hosted_file_obj_li }; console.log('data_kv', data_kv); @@ -89,7 +90,11 @@ $effect(() => { hosted_file_kv = $lq__journal_entry_obj?.data_json?.hosted_file_kv; } + // This is for the Select file option if ($lq__journal_entry_obj && slct_hosted_file_id && slct_hosted_file_obj) { + if (log_lvl) { + console.log(`slct_hosted_file_id=${slct_hosted_file_id}`, slct_hosted_file_obj); + } hosted_file_kv = { ...hosted_file_kv, [slct_hosted_file_id]: slct_hosted_file_obj @@ -99,16 +104,44 @@ $effect(() => { update_journal_entry(); - // slct_hosted_file_obj = $lq__journal_entry_obj?.data_json?.hosted_file_obj_li?.find((obj: any) => obj.hosted_file_id == slct_hosted_file_id); + // slct_hosted_file_obj = $lq__journal_entry_obj?.data_json?.slct_hosted_file_obj_li?.find((obj: any) => obj.hosted_file_id == slct_hosted_file_id); // console.log('slct_hosted_file_obj', slct_hosted_file_obj); } + // This is for the Upload file option + if ($lq__journal_entry_obj && slct_hosted_file_id_li && slct_hosted_file_id_li.length && upload_complete) { + if (log_lvl) { + console.log(`slct_hosted_file_id=${slct_hosted_file_id}`, slct_hosted_file_obj); + } + + hosted_file_kv = { + ...hosted_file_kv, + // ...keymap + // ...slct_hosted_file_kv + ...Object.fromEntries(slct_hosted_file_id_li.map(id => [id, slct_hosted_file_kv[id]])) + }; + slct_hosted_file_id = null; + slct_hosted_file_obj = null; + slct_hosted_file_id_li = []; + + upload_complete = false; + + update_journal_entry(); + + // slct_hosted_file_obj = $lq__journal_entry_obj?.data_json?.slct_hosted_file_obj_li?.find((obj: any) => obj.hosted_file_id == slct_hosted_file_id); + // console.log('slct_hosted_file_obj', slct_hosted_file_obj); + } + + + if ($lq__journal_entry_obj && rem_hosted_file_id) { - console.log('rem_hosted_file_id', rem_hosted_file_id); + if (log_lvl) { + console.log(`rem_hosted_file_id=${rem_hosted_file_id}`); + } delete hosted_file_kv[rem_hosted_file_id]; rem_hosted_file_id = null; - update_journal_entry(); + update_journal_entry(); // Should we use await here? } }); @@ -154,8 +187,9 @@ $effect(() => { class_li="border border-gray-300 rounded-md p-2 bg-gray-100 hover:bg-gray-200" link_to_type={link_to_type} link_to_id={link_to_id} - bind:hosted_file_id_li={hosted_file_id_li} - bind:hosted_file_obj_li={hosted_file_obj_li} + bind:hosted_file_id_li={slct_hosted_file_id_li} + bind:hosted_file_obj_li={slct_hosted_file_obj_li} + bind:hosted_file_obj_kv={slct_hosted_file_kv} bind:upload_complete={upload_complete} log_lvl={log_lvl} > @@ -236,10 +270,10 @@ $effect(() => {