feat: categories and option search
This commit is contained in:
@ -2,7 +2,7 @@ import { Ref, computed, ref, watchEffect } from 'vue';
|
||||
import { defineStore } from 'pinia';
|
||||
import { listen } from '@tauri-apps/api/event';
|
||||
import * as path from '@tauri-apps/api/path';
|
||||
import { invoke } from './invoke';
|
||||
import { invoke, invoke_nopopup } from './invoke';
|
||||
import { Dirs, Game, Package, Profile, ProfileMeta } from './types';
|
||||
import { changePrimaryColor, pkgKey } from './util';
|
||||
|
||||
@ -12,6 +12,17 @@ type InstallStatus = {
|
||||
|
||||
export const useGeneralStore = defineStore('general', () => {
|
||||
const dirs: Ref<Dirs | null> = ref(null);
|
||||
const cfgCategories = ref(new Set<string>());
|
||||
const _cfgSearchTerm = ref('');
|
||||
const cfgSearchTerm = computed({
|
||||
set(value: string) {
|
||||
cfgCategories.value.clear();
|
||||
_cfgSearchTerm.value = value;
|
||||
},
|
||||
get() {
|
||||
return _cfgSearchTerm.value;
|
||||
},
|
||||
});
|
||||
|
||||
const configDir = computed(() => {
|
||||
if (dirs.value === null) {
|
||||
@ -32,13 +43,35 @@ export const useGeneralStore = defineStore('general', () => {
|
||||
return dirs.value.cache_dir;
|
||||
});
|
||||
|
||||
return { dirs, configDir, dataDir, cacheDir };
|
||||
return {
|
||||
dirs,
|
||||
_cfgSearchTerm,
|
||||
cfgSearchTerm,
|
||||
cfgCategories,
|
||||
configDir,
|
||||
dataDir,
|
||||
cacheDir,
|
||||
};
|
||||
});
|
||||
|
||||
export const usePkgStore = defineStore('pkg', {
|
||||
state: (): { pkg: { [key: string]: Package } } => {
|
||||
state: (): {
|
||||
pkg: { [key: string]: Package };
|
||||
offline: boolean;
|
||||
showDeprecated: boolean;
|
||||
showNSFW: boolean;
|
||||
availableCategories: Set<string>;
|
||||
includeCategories: string[];
|
||||
excludeCategories: string[];
|
||||
} => {
|
||||
return {
|
||||
pkg: {},
|
||||
offline: false,
|
||||
showDeprecated: false,
|
||||
showNSFW: false,
|
||||
availableCategories: new Set(),
|
||||
includeCategories: [],
|
||||
excludeCategories: [],
|
||||
};
|
||||
},
|
||||
getters: {
|
||||
@ -48,7 +81,21 @@ export const usePkgStore = defineStore('pkg', {
|
||||
all: (state) => Object.values(state),
|
||||
allLocal: (state) =>
|
||||
Object.values(state.pkg).filter((p) => p.loc?.kind === 'Mod'),
|
||||
allRemote: (state) => Object.values(state.pkg).filter((p) => p.rmt),
|
||||
allRemote: (state) =>
|
||||
Object.values(state.pkg).filter(
|
||||
(p) =>
|
||||
p.rmt !== null &&
|
||||
(state.showDeprecated || !p.rmt.deprecated) &&
|
||||
(state.showNSFW || !p.rmt.nsfw) &&
|
||||
(state.includeCategories.length === 0 ||
|
||||
p.rmt.categories.some((c) =>
|
||||
state.includeCategories.includes(c)
|
||||
)) &&
|
||||
(state.excludeCategories.length === 0 ||
|
||||
p.rmt.categories.every(
|
||||
(c) => !state.excludeCategories.includes(c)
|
||||
))
|
||||
),
|
||||
hooks: (state) =>
|
||||
Object.values(state.pkg).filter((p) => p.loc?.kind === 'Hook'),
|
||||
ios: (state) =>
|
||||
@ -74,6 +121,7 @@ export const usePkgStore = defineStore('pkg', {
|
||||
const data = (await invoke('get_all_packages')) as {
|
||||
[key: string]: Package;
|
||||
};
|
||||
this.availableCategories.clear();
|
||||
|
||||
for (const [k, v] of Object.entries(data)) {
|
||||
this.reloadWith(k, v);
|
||||
@ -97,10 +145,26 @@ export const usePkgStore = defineStore('pkg', {
|
||||
this.pkg[key].rmt = null;
|
||||
}
|
||||
Object.assign(this.pkg[key], pkg);
|
||||
|
||||
if (pkg.rmt !== null) {
|
||||
pkg.rmt.categories.forEach((c) =>
|
||||
this.availableCategories.add(c)
|
||||
);
|
||||
}
|
||||
},
|
||||
|
||||
async fetch() {
|
||||
await invoke('fetch_listings');
|
||||
async fetch(nopopup: boolean) {
|
||||
try {
|
||||
if (nopopup) {
|
||||
await invoke_nopopup('fetch_listings');
|
||||
} else {
|
||||
await invoke('fetch_listings');
|
||||
}
|
||||
this.offline = false;
|
||||
} catch (e) {
|
||||
this.offline = true;
|
||||
return;
|
||||
}
|
||||
await this.reloadAll();
|
||||
},
|
||||
},
|
||||
|
Reference in New Issue
Block a user