Update api and change filter to not be a tagged enum

Signed-off-by: trivernis <trivernis@protonmail.com>
pull/4/head
trivernis 3 years ago
parent 984240a507
commit 1dc17f0aef

@ -1491,8 +1491,8 @@ checksum = "a3e378b66a060d48947b590737b30a1be76706c8dd7b8ba0f2fe3989c68a853f"
[[package]] [[package]]
name = "mediarepo-api" name = "mediarepo-api"
version = "0.13.0" version = "0.14.0"
source = "git+https://github.com/Trivernis/mediarepo-api.git?rev=d64787c36e6cf68567db1c480860cd95b7c20e3f#d64787c36e6cf68567db1c480860cd95b7c20e3f" source = "git+https://github.com/Trivernis/mediarepo-api.git?rev=14f2675f5fe1a11ea3302a623d040e77dcc78080#14f2675f5fe1a11ea3302a623d040e77dcc78080"
dependencies = [ dependencies = [
"async-trait", "async-trait",
"bromine", "bromine",

@ -25,7 +25,7 @@ features = [ "env-filter" ]
[dependencies.mediarepo-api] [dependencies.mediarepo-api]
git = "https://github.com/Trivernis/mediarepo-api.git" git = "https://github.com/Trivernis/mediarepo-api.git"
rev = "d64787c36e6cf68567db1c480860cd95b7c20e3f" rev = "14f2675f5fe1a11ea3302a623d040e77dcc78080"
features = [ "tauri-plugin" ] features = [ "tauri-plugin" ]
[features] [features]

@ -1,4 +1,5 @@
import {TagQuery} from "./TagQuery"; import {TagQuery} from "./TagQuery";
import {createRustEnum, RustEnum} from "./rust-types";
export interface FilterExpression { export interface FilterExpression {
filter_type: "OrExpression" | "Query"; filter_type: "OrExpression" | "Query";
@ -13,6 +14,8 @@ export interface FilterExpression {
clone(): FilterExpression; clone(): FilterExpression;
queryList(): TagQuery[]; queryList(): TagQuery[];
toBackendType(): RustEnum<TagQuery | TagQuery[]>;
} }
export class OrFilterExpression implements FilterExpression { export class OrFilterExpression implements FilterExpression {
@ -60,6 +63,10 @@ export class OrFilterExpression implements FilterExpression {
} }
this.filter = newEntries.reverse(); this.filter = newEntries.reverse();
} }
public toBackendType(): RustEnum<TagQuery | TagQuery[]> {
return createRustEnum(this.filter_type, this.filter);
}
} }
export class SingleFilterExpression implements FilterExpression { export class SingleFilterExpression implements FilterExpression {
@ -90,4 +97,8 @@ export class SingleFilterExpression implements FilterExpression {
public queryList(): TagQuery[] { public queryList(): TagQuery[] {
return [this.filter] return [this.filter]
} }
public toBackendType(): RustEnum<TagQuery | TagQuery[]> {
return createRustEnum(this.filter_type, this.filter);
}
} }

@ -0,0 +1,10 @@
export type RustEnum<VariantData> = {
[key: string]: VariantData
};
export function createRustEnum<VariantData>(variant: string, data: VariantData): RustEnum<VariantData> {
let enumInstance: RustEnum<VariantData> = {};
enumInstance[variant] = data;
return enumInstance;
}

@ -35,8 +35,9 @@ export class FileService {
public async findFiles(filters: FilterExpression[], sortBy: SortKey[]) { public async findFiles(filters: FilterExpression[], sortBy: SortKey[]) {
console.log(filters); console.log(filters);
let backendFilters = filters.map(f => f.toBackendType());
let files = await invoke<File[]>("plugin:mediarepo|find_files", let files = await invoke<File[]>("plugin:mediarepo|find_files",
{filters, sortBy: sortBy.map(k => k.toBackendType())}); {filters: backendFilters, sortBy: sortBy.map(k => k.toBackendType())});
this.displayedFiles.next(files); this.displayedFiles.next(files);
} }

Loading…
Cancel
Save