mirror of
https://codeberg.org/PLG-Development/PLG-MuDiCS
synced 2026-07-06 00:47:09 +00:00
refactor(control): create new constantly updated list of selected_online_display_ids
This commit is contained in:
@@ -31,7 +31,7 @@
|
||||
import RefreshPlay from '../svgs/RefreshPlay.svelte';
|
||||
import { get_file_size_display_string, get_file_type } from '$lib/ts/utils';
|
||||
import { open_file } from '$lib/ts/api_handler';
|
||||
import { get_display_by_id, run_on_all_selected_displays } from '$lib/ts/stores/displays';
|
||||
import { get_display_by_id, run_on_all_selected_displays, selected_online_display_ids } from '$lib/ts/stores/displays';
|
||||
import { get_thumbnail_url } from '$lib/ts/stores/thumbnails';
|
||||
import { liveQuery, type Observable } from 'dexie';
|
||||
import { db } from '$lib/ts/database';
|
||||
@@ -45,8 +45,9 @@
|
||||
| Observable<{ missing: string[]; colliding: string[] }>
|
||||
| undefined = $state();
|
||||
$effect(() => {
|
||||
const s = $selected_file_ids;
|
||||
missing_colliding_displays_ids = liveQuery(() => get_missing_colliding_display_ids(file, s));
|
||||
const f = file;
|
||||
const s = $selected_online_display_ids;
|
||||
missing_colliding_displays_ids = liveQuery(() => get_missing_colliding_display_ids(f, s));
|
||||
});
|
||||
|
||||
let file_size: Observable<number> | undefined = $state();
|
||||
@@ -215,7 +216,7 @@
|
||||
if (is_folder(file)) {
|
||||
const folder_elements = await get_folder_elements(
|
||||
file.path + file.name + '/',
|
||||
$selected_display_ids
|
||||
$selected_online_display_ids
|
||||
);
|
||||
let out: number = 0;
|
||||
for (const el of folder_elements) {
|
||||
|
||||
@@ -22,8 +22,13 @@ export const online_displays_sub = liveQuery(() =>
|
||||
db.displays.where('status').equals('app_online').toArray()
|
||||
).subscribe((value) => {
|
||||
online_displays.set(value);
|
||||
const current_online_display_ids = value.map((d) => d.id);
|
||||
selected_online_display_ids.set(get(selected_display_ids).filter((id) => current_online_display_ids.includes(id)));
|
||||
console.log(get(selected_online_display_ids))
|
||||
});
|
||||
|
||||
export const selected_online_display_ids: Writable<string[]> = writable<string[]>([]);
|
||||
|
||||
export const local_displays: Writable<DisplayIdGroup[]> = writable<DisplayIdGroup[]>([]);
|
||||
|
||||
export async function is_display_name_taken(name: string): Promise<boolean> {
|
||||
@@ -269,15 +274,6 @@ export function set_new_display_order(display_id_group_id: string, new_data: Dis
|
||||
});
|
||||
}
|
||||
|
||||
export function no_active_display_selected(
|
||||
selected_display_ids: string[],
|
||||
online_displays: Display[]
|
||||
) {
|
||||
const online_and_selected_displays = online_displays.filter((d) =>
|
||||
selected_display_ids.includes(d.id)
|
||||
);
|
||||
return online_and_selected_displays.length === 0;
|
||||
}
|
||||
|
||||
if (dev) {
|
||||
setTimeout(add_testing_displays, 0);
|
||||
|
||||
@@ -7,7 +7,7 @@ import {
|
||||
type Inode,
|
||||
type TreeElement
|
||||
} from '../types';
|
||||
import { get_display_by_id } from './displays';
|
||||
import { get_display_by_id, selected_online_display_ids } from './displays';
|
||||
import { is_selected, select, selected_display_ids, selected_file_ids } from './select';
|
||||
import { create_path, get_file_data, get_file_tree_data } from '../api_handler';
|
||||
import { deactivate_old_thumbnail_urls, generate_thumbnail } from './thumbnails';
|
||||
@@ -94,7 +94,7 @@ export async function update_current_folder_on_selected_displays() {
|
||||
});
|
||||
const current_path = get(current_file_path);
|
||||
|
||||
for (const display of await db.displays.where('id').anyOf(get(selected_display_ids)).toArray()) {
|
||||
for (const display of await db.displays.where('id').anyOf(get(selected_online_display_ids)).toArray()) {
|
||||
await update_folder_elements_recursively(display, current_path);
|
||||
}
|
||||
}
|
||||
@@ -371,7 +371,7 @@ export async function get_file_by_id(
|
||||
export async function run_for_selected_files_on_selected_displays(
|
||||
action: (ip: string, file_names: string[]) => Promise<void>
|
||||
): Promise<void> {
|
||||
for (const display_id of get(selected_display_ids)) {
|
||||
for (const display_id of get(selected_online_display_ids)) {
|
||||
const file_key_strings_on_display: string[] = (
|
||||
await db.files_on_display.where('display_id').equals(display_id).toArray()
|
||||
).map((e) => e.file_primary_key);
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { writable, type Writable } from 'svelte/store';
|
||||
import { get, writable, type Writable } from 'svelte/store';
|
||||
import { online_displays, selected_online_display_ids } from './displays';
|
||||
|
||||
export const selected_file_ids: Writable<string[]> = writable<string[]>([]); // JSON.stringify([string, string, number, string])
|
||||
export const selected_display_ids: Writable<string[]> = writable<string[]>([]);
|
||||
@@ -19,6 +20,12 @@ export function select(
|
||||
}
|
||||
return all_ids;
|
||||
});
|
||||
|
||||
if (selected_ids === selected_display_ids) {
|
||||
const current_online_display_ids = get(online_displays).map((d) => d.id);
|
||||
selected_online_display_ids.set(get(selected_display_ids).filter((id) => current_online_display_ids.includes(id)));
|
||||
console.log(get(selected_online_display_ids))
|
||||
}
|
||||
}
|
||||
|
||||
export function is_selected(id: string, selected_ids: string[]): boolean {
|
||||
|
||||
Reference in New Issue
Block a user