Improvements on how posts are pulled in and sorted.

This commit is contained in:
Scott Idem
2025-07-18 18:15:18 -04:00
parent fd69610a3a
commit 0ac7bea046
5 changed files with 82 additions and 32 deletions

View File

@@ -74,10 +74,10 @@ let idaa_local_data_struct: key_val = {
qry__enabled: 'enabled', // all, disabled, enabled
qry__hidden: 'not_hidden', // all, hidden, not_hidden
qry__limit: 50,
qry__limit: 25,
qry__offset: 0,
qry__order_by: 'updated_on', // For the IDB index query
qry__order_by_li: {'priority': 'DESC', 'sort': 'DESC', 'updated_on': 'DESC', 'created_on': 'DESC', 'title': 'ASC'}, // For the SQL query
qry__order_by_li: {'updated_on': 'DESC', 'created_on': 'DESC'}, // For the SQL query
},

View File

@@ -140,6 +140,7 @@ export async function load_ae_obj_li__post(
api_cfg,
for_obj_type = 'account',
for_obj_id,
qry_archive_on = null,
inc_comment_li = false,
enabled = 'enabled',
hidden = 'not_hidden',
@@ -147,18 +148,21 @@ export async function load_ae_obj_li__post(
offset = 0,
order_by_li = {'priority': 'DESC', 'sort': 'DESC', 'updated_on': 'DESC', 'created_on': 'DESC', 'title': 'ASC'},
params = {},
params_json = null,
try_cache = true,
log_lvl = 0
}: {
api_cfg: any,
for_obj_type: string,
for_obj_id: string,
qry_archive_on?: boolean|null|string,
inc_comment_li?: boolean,
enabled?: string,
hidden?: string,
limit?: number,
offset?: number,
order_by_li?: key_val,
params_json?: null|key_val,
params?: key_val,
try_cache?: boolean,
log_lvl?: number
@@ -168,12 +172,48 @@ export async function load_ae_obj_li__post(
console.log(`*** load_ae_obj_li__post() *** for_obj_type=${for_obj_type} for_obj_id=${for_obj_id}`);
}
let params_json: key_val = {};
// There is probably a better way to handle this. I don't want to just start a new object if it is not passed. However, the qry_conference and qry_str are sort of a special case. -2024-10-01
if (!params_json) {
params_json = {};
}
params_json['qry'] = [];
if (qry_archive_on) {
// let qry_param =
// {
// type: "AND",
// field: "archive_on",
// operator: ">",
// value: qry_archive_on
// };
// params_json['qry'].push(qry_param);
}
// if (qry_archive_on) {
// if (!params_json['and_qry']) {
// params_json['and_qry'] = {};
// }
// params_json['and_qry']['archive_on'] = qry_archive_on;
// } else if (qry_archive_on === false) {
// if (!params_json['and_qry']) {
// params_json['and_qry'] = {};
// }
// if (log_lvl) {
// console.log('qry_archive_on is false!');
// }
// params_json['and_qry']['conference'] = qry_archive_on;
// }
if (log_lvl) {
console.log('params_json:', params_json);
}
ae_promises.load__post_obj_li = await api.get_ae_obj_li_for_obj_id_crud_v2({
api_cfg: api_cfg,
obj_type: 'post',

View File

@@ -36,7 +36,7 @@ export interface Post {
enable_comments?: null|boolean;
archive?: null|boolean;
archive_on?: Date;
archive_on?: null|Date;
linked_li_json?: null|string;
cfg_json?: null|key_val;

View File

@@ -42,13 +42,19 @@ if (!post_id) {
}
// Functions and Logic
// WARNING: For now the archive_on is hardcoded. It should be configurable.
let lq__post_obj_li = $derived(liveQuery(async () => {
let results = await db_posts.post
.where('account_id')
.equals($slct.account_id)
// .and((x) => (x.archive_on === null || x.archive_on > (new Date()).toISOString()))
.and((x) => (x.archive_on === null || x.archive_on > (new Date()).toISOString())) // null or future posts only
// .and((x) => (x.archive_on < (new Date()).toISOString())) // past posts only
// .and((x) => (x.archive_on > (new Date()).toISOString())) // future posts only
// .orderBy('updated_on')
// .toArray()
.reverse()
.limit($idaa_loc.bb.qry__limit)
.sortBy('tmp_sort_1');
// .sortBy('updated_on');
// .sortBy('updated_on, created_on');
@@ -58,30 +64,30 @@ let lq__post_obj_li = $derived(liveQuery(async () => {
return results;
}));
let lq__post_obj = $derived(liveQuery(async () => {
let results = await db_posts.post
.get($idaa_slct.post_id ?? ''); // null or undefined does not reset things like '' does
// let lq__post_obj = $derived(liveQuery(async () => {
// let results = await db_posts.post
// .get($idaa_slct.post_id ?? ''); // null or undefined does not reset things like '' does
return results;
}));
// return results;
// }));
let lq__post_comment_obj_li = $derived(liveQuery(async () => {
let results = await db_posts.comment
.where('post_id')
.equals($idaa_slct.post_id ?? '') // null or undefined does not reset things like '' does
.reverse()
.sortBy('updated_on');
// .sortBy('title');
// let lq__post_comment_obj_li = $derived(liveQuery(async () => {
// let results = await db_posts.comment
// .where('post_id')
// .equals($idaa_slct.post_id ?? '') // null or undefined does not reset things like '' does
// .reverse()
// .sortBy('updated_on');
// // .sortBy('title');
return results;
}));
// return results;
// }));
let lq__post_comment_obj = $derived(liveQuery(async () => {
let results = await db_posts.comment
.get($idaa_slct.post_comment_id ?? ''); // null or undefined does not reset things like '' does
// let lq__post_comment_obj = $derived(liveQuery(async () => {
// let results = await db_posts.comment
// .get($idaa_slct.post_comment_id ?? ''); // null or undefined does not reset things like '' does
return results;
}));
// return results;
// }));
$effect(() => {
@@ -110,6 +116,7 @@ $effect(() => {
api_cfg: $ae_api,
for_obj_type: 'account',
for_obj_id: $idaa_slct.account_id,
qry_archive_on: '2024-01-01', // (new Date()).toISOString(),
inc_comment_li: true,
enabled: $idaa_loc.bb.qry__enabled,
hidden: $idaa_loc.bb.qry__hidden,
@@ -128,12 +135,12 @@ if (browser) {
let message = {'post_id': $idaa_slct?.post_id ?? null};
window.parent.postMessage(message, "*");
add_activity_log(
{
action: 'idaa_bb_page',
action_with: 'browser',
}
);
// add_activity_log(
// {
// action: 'idaa_bb_page',
// action_with: 'browser',
// }
// );
}

View File

@@ -7,7 +7,7 @@ import { browser } from '$app/environment';
import { posts_func } from '$lib/ae_posts/ae_posts_functions';
export const load = (async ({ params, parent }) => { // route
let log_lvl: number = 0;
let log_lvl: number = 1;
let data = await parent();
data.log_lvl = log_lvl;
@@ -20,11 +20,14 @@ export const load = (async ({ params, parent }) => { // route
api_cfg: ae_acct.api,
for_obj_type: 'account',
for_obj_id: account_id,
// archive_on should be current datetime in ISO format
// Date().toISOString()
qry_archive_on: '2024-01-01', // (new Date()).toISOString(),
inc_comment_li: true,
enabled: 'enabled',
hidden: 'not_hidden',
limit: 29,
order_by_li: {'priority': 'DESC', 'sort': 'DESC', 'updated_on': 'DESC', 'created_on': 'DESC', 'title': 'ASC'},
limit: 19,
order_by_li: {'updated_on': 'DESC', 'created_on': 'DESC'},
try_cache: true,
log_lvl: log_lvl
});