Making the loading a bit more efficient and cleaner
This commit is contained in:
@@ -33,7 +33,7 @@ type key_val = {
|
||||
|
||||
// *** BEGIN *** Longer-term app data. This should be stored to local storage.
|
||||
export let ae_app_local_data_struct: key_val = {
|
||||
'ver': '0.0.7',
|
||||
'ver': '2024-02-22_17',
|
||||
'name': 'Aether App Template',
|
||||
'theme': 'light',
|
||||
|
||||
@@ -87,7 +87,7 @@ export let ae_loc: Writable<key_val> = localStorageStore('ae_loc', ae_app_local_
|
||||
|
||||
// *** BEGIN *** Temporary app data. This should be stored to session storage.
|
||||
export let ae_app_session_data_struct: key_val = {
|
||||
'ver': '0.0.2',
|
||||
'ver': '2024-02-22_17',
|
||||
// 'name': 'Aether App Template',
|
||||
// 'theme': 'light',
|
||||
'account_id': ae_account_id,
|
||||
@@ -99,7 +99,7 @@ export let ae_sess = writable(ae_app_session_data_struct);
|
||||
|
||||
// *** BEGIN *** Temporary API data. This should be stored to session storage.
|
||||
export let ae_api_data_struct: key_val = {
|
||||
'ver': '0.0.2',
|
||||
'ver': '2024-02-22_17',
|
||||
'base_url': api_base_url,
|
||||
'base_url_bak': api_base_url_bak,
|
||||
'api_secret_key': api_secret_key, // 'YOUR_API_SECRET_KEY',
|
||||
|
||||
@@ -494,6 +494,7 @@ export let post_object = async function post_object({api_cfg=null, endpoint='',
|
||||
// Updated 2023-12-01
|
||||
export let get_ae_obj_id_crud = async function get_ae_obj_id_crud({
|
||||
api_cfg,
|
||||
no_account_id=false,
|
||||
obj_type,
|
||||
obj_id,
|
||||
use_alt_table=false,
|
||||
@@ -576,6 +577,8 @@ export let get_ae_obj_id_crud = async function get_ae_obj_id_crud({
|
||||
endpoint = `/crud/post/comment/${obj_id}`;
|
||||
} else if (obj_type == 'site') {
|
||||
endpoint = `/crud/site/${obj_id}`;
|
||||
} else if (obj_type == 'site_domain') {
|
||||
endpoint = `/crud/site/domain/${obj_id}`;
|
||||
} else if (obj_type == 'sponsorship_cfg') {
|
||||
endpoint = `/crud/sponsorship/cfg/${obj_id}`;
|
||||
} else if (obj_type == 'sponsorship') {
|
||||
@@ -597,6 +600,10 @@ export let get_ae_obj_id_crud = async function get_ae_obj_id_crud({
|
||||
console.log('Params:', params);
|
||||
}
|
||||
|
||||
if (no_account_id) {
|
||||
headers['x_no_account_id_token'] = 'Nothing to See Here'; // get_object() will fix the underscores to dashes
|
||||
}
|
||||
|
||||
let object_obj_get_promise = await get_object({
|
||||
api_cfg: api_cfg,
|
||||
endpoint: endpoint,
|
||||
|
||||
@@ -59,6 +59,9 @@ console.log($ae_loc, $ae_sess, $ae_api);
|
||||
|
||||
import Element_access_type from '$lib/element_access_type.svelte';
|
||||
|
||||
export let data;
|
||||
console.log(`Svelte +Layout page data:`, data);
|
||||
|
||||
// const ae_loc_test_store: Writable<string> = localStorageStore('ae_loc_test', {'test': 'This is a test'});
|
||||
// // Subscribe to the store
|
||||
// ae_loc_test_store.subscribe(() => {});
|
||||
@@ -76,9 +79,9 @@ import Element_access_type from '$lib/element_access_type.svelte';
|
||||
// $ae_loc_test_store
|
||||
|
||||
let data_store_obj_get_promises: key_val = {};
|
||||
let get_ds_hub_page_access_code_li_json_promise = handle_get_data_store_obj_w_code({code: 'hub__page__access_code_li_json', data_type: 'json', trigger: 'set_access_code_li'});
|
||||
let get_ds_hub_site_header_promise = handle_get_data_store_obj_w_code({code: 'hub_site_header'});
|
||||
let get_ds_hub_site_footer_promise = handle_get_data_store_obj_w_code({code: 'hub_site_footer'});
|
||||
// let get_ds_hub_page_access_code_li_json_promise = handle_get_data_store_obj_w_code({code: 'hub__page__access_code_li_json', data_type: 'json', trigger: 'set_access_code_li'});
|
||||
// let get_ds_hub_site_header_promise = handle_get_data_store_obj_w_code({code: 'hub_site_header'});
|
||||
// let get_ds_hub_site_footer_promise = handle_get_data_store_obj_w_code({code: 'hub_site_footer'});
|
||||
|
||||
|
||||
async function handle_get_data_store_obj_w_code({ code=null, data_type='text', trigger=null }) {
|
||||
@@ -127,7 +130,7 @@ async function handle_get_data_store_obj_w_code({ code=null, data_type='text', t
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
$slct_trigger = 'set_access_code_li';
|
||||
$: if ($slct_trigger == 'set_access_code_li' && $ae_loc.hub.ds['hub__page__access_code_li_json']) {
|
||||
console.log(`$ae_loc.hub.ds['hub__page__access_code_li_json'] = `, $ae_loc.hub.ds['hub__page__access_code_li_json']);
|
||||
$slct_trigger = null; // Reset the trigger to prevent loops
|
||||
@@ -136,6 +139,55 @@ $: if ($slct_trigger == 'set_access_code_li' && $ae_loc.hub.ds['hub__page__acces
|
||||
$ae_loc = $ae_loc; // Trigger Svelte just in case
|
||||
console.log($ae_loc);
|
||||
}
|
||||
|
||||
|
||||
// let ae_site_domain_obj_get_promise;
|
||||
// $slct_trigger = 'lookup_fqdn';
|
||||
// $: if ($slct_trigger == 'lookup_fqdn' && data.url.host) {
|
||||
// $slct_trigger = null; // Reset the trigger to prevent loops
|
||||
// // $ae_loc.url_host = data.url.host; // Use this to look up? sub.example.com:123
|
||||
// $ae_loc.fqdn = data.url.host; // Use this to look up? sub.example.com:123
|
||||
// // $ae_loc.url_hostname = data.url.hostname; // sub.example.com
|
||||
// // $ae_loc.url_origin = data.url.origin; // Use this to look up? https://sub.example.com:123
|
||||
// // $ae_loc.site_domain = data.url.origin;
|
||||
// console.log(`$ae_loc = `, $ae_loc);
|
||||
|
||||
// handle_load_ae_obj_id__site_domain({fqdn: $ae_loc.fqdn, try_cache: false});
|
||||
// }
|
||||
|
||||
|
||||
// async function handle_load_ae_obj_id__site_domain({fqdn, try_cache=false}) {
|
||||
// console.log(`*** handle_load_ae_obj_id__site_domain() *** fqdn=${fqdn}`);
|
||||
|
||||
// let params = {};
|
||||
|
||||
// // $ae_loc.hub.site_domain_id_qry_status = 'loading';
|
||||
// ae_site_domain_obj_get_promise = api.get_ae_obj_id_crud({
|
||||
// api_cfg: $ae_api,
|
||||
// no_account_id: true,
|
||||
// obj_type: 'site_domain',
|
||||
// obj_id: fqdn, // NOTE: This is the FQDN, not normally the ID.
|
||||
// use_alt_table: true, // NOTE: This will use the table_name_alt value instead of the table_name value in the API config.
|
||||
// use_alt_base: true, // NOTE: This will use the base_name_alt value instead of the base_name value in the API config.
|
||||
// params: params,
|
||||
// log_lvl: 2
|
||||
// })
|
||||
// .then(function (site_domain_obj_get_result) {
|
||||
// if (site_domain_obj_get_result) {
|
||||
// $slct.site_domain_obj = site_domain_obj_get_result;
|
||||
// console.log(`site_domain object:`, $slct.site_domain_obj);
|
||||
|
||||
// $ae_loc.account_id = $slct.site_domain_obj.account_id_random;
|
||||
// $ae_loc.site_id = $slct.site_domain_obj.site_id_random;
|
||||
// $ae_loc.site_domain_id = $slct.site_domain_obj.site_domain_id_random;
|
||||
// }
|
||||
// })
|
||||
// .catch(function (error) {
|
||||
// console.log('No results returned or failed.', error);
|
||||
// });
|
||||
|
||||
// return ae_site_domain_obj_get_promise;
|
||||
// }
|
||||
</script>
|
||||
|
||||
|
||||
|
||||
@@ -1,3 +1,152 @@
|
||||
/** @type {import('./$types').LayoutLoad} */
|
||||
|
||||
|
||||
import { api } from '$lib/api';
|
||||
import { ae_loc, ae_sess, ae_api, slct, slct_trigger } from '$lib/ae_stores';
|
||||
import { get } from 'svelte/store';
|
||||
|
||||
|
||||
async function handle_load_ae_obj_id__site_domain({fqdn, try_cache=false}) {
|
||||
console.log(`*** handle_load_ae_obj_id__site_domain() *** fqdn=${fqdn}`);
|
||||
|
||||
let params = {};
|
||||
|
||||
// ae_loc.hub.site_domain_id_qry_status = 'loading';
|
||||
let ae_site_domain_obj_get_promise = api.get_ae_obj_id_crud({
|
||||
api_cfg: get(ae_api),
|
||||
no_account_id: true,
|
||||
obj_type: 'site_domain',
|
||||
obj_id: fqdn, // NOTE: This is the FQDN, not normally the ID.
|
||||
use_alt_table: true, // NOTE: This will use the table_name_alt value instead of the table_name value in the API config.
|
||||
use_alt_base: true, // NOTE: This will use the base_name_alt value instead of the base_name value in the API config.
|
||||
params: params,
|
||||
log_lvl: 2
|
||||
})
|
||||
.then(function (site_domain_obj_get_result) {
|
||||
if (site_domain_obj_get_result) {
|
||||
// slct.site_domain_obj = site_domain_obj_get_result;
|
||||
// console.log(`site_domain object:`, get(slct).site_domain_obj);
|
||||
|
||||
// ae_loc.account_id = $slct.site_domain_obj.account_id_random;
|
||||
// ae_loc.site_id = $slct.site_domain_obj.site_id_random;
|
||||
// ae_loc.site_domain_id = $slct.site_domain_obj.site_domain_id_random;
|
||||
return site_domain_obj_get_result;
|
||||
} else {
|
||||
console.log('No results returned.');
|
||||
return null;
|
||||
}
|
||||
})
|
||||
.catch(function (error) {
|
||||
console.log('No results returned or failed.', error);
|
||||
});
|
||||
|
||||
return ae_site_domain_obj_get_promise;
|
||||
}
|
||||
|
||||
let data_store_obj_get_promises: key_val = {};
|
||||
async function handle_get_data_store_obj_w_code({ code=null, data_type='text' }) {
|
||||
console.log(`*** handle_get_data_store_obj_w_code() *** code=${code}`);
|
||||
|
||||
if (!code) {
|
||||
console.log('No code provided.');
|
||||
return;
|
||||
}
|
||||
|
||||
let data_store_obj_get_promise = api.get_data_store_obj_w_code({
|
||||
api_cfg: get(ae_api),
|
||||
data_store_code: code,
|
||||
data_type: data_type,
|
||||
log_lvl: 0
|
||||
})
|
||||
.then(function (get_data_store_result) {
|
||||
let return_this = null;
|
||||
if (get_data_store_result) {
|
||||
|
||||
if (data_type == 'text') {
|
||||
// console.log(get_data_store_result.text);
|
||||
return_this = get_data_store_result.text;
|
||||
} else if (data_type == 'json') {
|
||||
// console.log(get_data_store_result.json);
|
||||
return_this = get_data_store_result.json;
|
||||
}
|
||||
|
||||
} else {
|
||||
console.log('No results returned.');
|
||||
return_this = null;
|
||||
}
|
||||
return return_this;
|
||||
})
|
||||
.catch(function (error) {
|
||||
console.log('No results returned or failed.', error);
|
||||
});
|
||||
|
||||
return data_store_obj_get_promise;
|
||||
}
|
||||
|
||||
|
||||
export function load({ params, url }) { // route
|
||||
console.log(`Svelte root layout.ts data = params:`, params);
|
||||
// console.log(`Svelte root layout.ts data = route:`, route);
|
||||
console.log(`Svelte root layout.ts data = url:`, url);
|
||||
|
||||
let site_domain_results = null;
|
||||
let access_code_li_json = null;
|
||||
let ae_core = null;
|
||||
|
||||
if (url.host) {
|
||||
// ae_loc.url_host = data.url.host; // Use this to look up? sub.example.com:123
|
||||
// ae_loc.fqdn = url.host; // Use this to look up? sub.example.com:123
|
||||
// ae_loc.url_hostname = data.url.hostname; // sub.example.com
|
||||
// ae_loc.url_origin = data.url.origin; // Use this to look up? https://sub.example.com:123
|
||||
// ae_loc.site_domain = data.url.origin;
|
||||
// console.log(`ae_loc = `, ae_loc);
|
||||
|
||||
site_domain_results = handle_load_ae_obj_id__site_domain({fqdn: url.host, try_cache: false});
|
||||
|
||||
if (site_domain_results) {
|
||||
console.log(`site_domain_results = `, site_domain_results);
|
||||
|
||||
ae_core = {
|
||||
'account_id': site_domain_results.account_id_random,
|
||||
'site_id': site_domain_results.site_id_random,
|
||||
'site_domain_id': site_domain_results.site_domain_id_random,
|
||||
'enable': site_domain_results.enable,
|
||||
'style_href': site_domain_results.style_href,
|
||||
'google_tracking_id': site_domain_results.google_tracking_id,
|
||||
}
|
||||
}
|
||||
|
||||
access_code_li_json = handle_get_data_store_obj_w_code({code: 'hub__page__access_code_li_json', data_type: 'json'});
|
||||
|
||||
if (access_code_li_json) {
|
||||
console.log(`access_code_li_json = `, access_code_li_json);
|
||||
|
||||
ae_core = {
|
||||
...ae_core,
|
||||
'access_code_li': access_code_li_json,
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// ae_core = {
|
||||
// 'account_id': site_domain_results.account_id_random
|
||||
// }
|
||||
|
||||
let data_struct = {
|
||||
params: params,
|
||||
sections: [
|
||||
{ slug: 'new', title: 'New Test' },
|
||||
{ slug: 'manage', title: 'Manage Test' },
|
||||
{ slug: 'test', title: 'Test Test' },
|
||||
],
|
||||
url: url,
|
||||
ae_core: ae_core,
|
||||
|
||||
};
|
||||
return data_struct;
|
||||
}
|
||||
|
||||
// export const ssr = false;
|
||||
// export const prerender = true;
|
||||
// export const prerender = true
|
||||
|
||||
Reference in New Issue
Block a user