Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion frontend/src/ts/auth.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {

import Ape from "./ape";
import { waitForPresetsReady } from "./collections/presets";
import { waitForTagsReady } from "./collections/tags";
import { updateFromServer as updateConfigFromServer } from "./config/remote";
import * as DB from "./db";
import { authEvent } from "./events/auth";
Expand Down Expand Up @@ -66,8 +67,9 @@ async function getDataAndInit(): Promise<boolean> {
try {
console.log("getting account data");
const snapshot = await DB.initSnapshot();
//TODO: always load presets for now, remove when __nonReactive is removed from presets collection
//TODO: preload collections for now, remove when __nonReactive is removed from collections
await waitForPresetsReady();
await waitForTagsReady();

if (snapshot === false) {
throw new Error(
Expand Down
8 changes: 4 additions & 4 deletions frontend/src/ts/collections/results.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ import { isAuthenticated } from "../states/core";
import { getLastResult, setLastResult } from "../states/snapshot";
import {
getActiveTagsOnce,
getTagsOnce,
reconcileLocalTagPB,
saveLocalTagPB,
__nonReactive as tagsNonReactive,
} from "./tags";
import { applyIdWorkaround } from "./utils/misc";

Expand Down Expand Up @@ -215,9 +215,9 @@ const resultsCollection = createCollection(
queryKey: queryKeys.root(),
queryFn: async () => {
if (!isAuthenticated()) return [];
const knownTagIds = new Set(
tagsNonReactive.getTags().map((it) => it._id),
);
const tagIds = await getTagsOnce();

const knownTagIds = new Set([...tagIds.map((it) => it._id)]);
//const options = parseLoadSubsetOptions(ctx.meta?.loadSubsetOptions);

const response = await Ape.results.get({
Expand Down
11 changes: 11 additions & 0 deletions frontend/src/ts/collections/tags.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,13 @@ export async function getActiveTagsOnce() {
});
}

// oxlint-disable-next-line typescript/explicit-function-return-type
export async function getTagsOnce() {
return queryOnce((q) => {
return q.from({ tag: tagsCollection });
});
}

type ActionType = {
insertTag: {
name: string;
Expand Down Expand Up @@ -242,6 +249,10 @@ const actions = {

// --- Public API ---

export async function waitForTagsReady(): Promise<void> {
await tagsCollection.stateWhenReady();
}

export async function insertTag(
params: ActionType["insertTag"],
): Promise<void> {
Expand Down
Loading