diff --git a/src-tauri/src/db/mod.rs b/src-tauri/src/db/mod.rs index f6f2fc2d..73b05784 100644 --- a/src-tauri/src/db/mod.rs +++ b/src-tauri/src/db/mod.rs @@ -707,6 +707,8 @@ pub struct GameQueryJs { pub outcome: Option, #[specta(optional)] pub position: Option, + #[specta(optional)] + pub wanted_result: Option, } impl GameQueryJs { diff --git a/src-tauri/src/db/search.rs b/src-tauri/src/db/search.rs index a8ae5419..54673429 100644 --- a/src-tauri/src/db/search.rs +++ b/src-tauri/src/db/search.rs @@ -303,12 +303,37 @@ pub async fn search_position( } } - if let Some(black) = query.player2 { - if black != *black_id { - return; + if let Some(black) = query.player2 { + if black != *black_id { + return; + } + } + + // "any" | "whitewon" | "draw" | "blackwon" + if let Some(result) = result { + if let Some(wanted_result) = &query.wanted_result { + match wanted_result.as_str() { + "whitewon" => { + if result != "1-0" { + return + } + } + "blackwon" => { + if result != "0-1" { + return + } + } + "draw" => { + if result != "1/2-1/2" { + return + } + } + &_ => {} + } } } + if let Some(position_query) = &query.position { let position_query = convert_position_query(position_query.clone()).expect("Invalid position query"); diff --git a/src/bindings/generated.ts b/src/bindings/generated.ts index 4c8f1bfb..2a59945b 100644 --- a/src/bindings/generated.ts +++ b/src/bindings/generated.ts @@ -386,7 +386,7 @@ export type EngineOptions = { fen: string; moves: string[]; extraOptions: Engine export type Event = { id: number; name: string | null } export type FidePlayer = { fideid: number; name: string; country: string; sex: string; title: string | null; w_title: string | null; o_title: string | null; foa_title: string | null; rating: number | null; games: number | null; k: number | null; rapid_rating: number | null; rapid_games: number | null; rapid_k: number | null; blitz_rating: number | null; blitz_games: number | null; blitz_k: number | null; birthday: number | null; flag: string | null } export type FileMetadata = { last_modified: number } -export type GameQueryJs = { options?: QueryOptions | null; player1?: number | null; player2?: number | null; tournament_id?: number | null; start_date?: string | null; end_date?: string | null; range1?: [number, number] | null; range2?: [number, number] | null; sides?: Sides | null; outcome?: string | null; position?: PositionQueryJs | null } +export type GameQueryJs = { options?: QueryOptions | null; player1?: number | null; player2?: number | null; tournament_id?: number | null; start_date?: string | null; end_date?: string | null; range1?: [number, number] | null; range2?: [number, number] | null; sides?: Sides | null; outcome?: string | null; position?: PositionQueryJs | null; wanted_result?: string | null } export type GameSort = "id" | "date" | "whiteElo" | "blackElo" | "ply_count" export type GoMode = { t: "PlayersTime"; c: PlayersTime } | { t: "Depth"; c: number } | { t: "Time"; c: number } | { t: "Nodes"; c: number } | { t: "Infinite" } export type MonthData = { count: number; avg_elo: number } diff --git a/src/components/panels/database/DatabasePanel.tsx b/src/components/panels/database/DatabasePanel.tsx index 87686a10..daf7bb6f 100644 --- a/src/components/panels/database/DatabasePanel.tsx +++ b/src/components/panels/database/DatabasePanel.tsx @@ -56,6 +56,7 @@ export type LocalOptions = { color: "white" | "black"; start_date?: string; end_date?: string; + result: "any" | "whitewon" | "draw" | "blackwon", }; function sortOpenings(openings: Opening[]) { diff --git a/src/components/panels/database/options/LocalOptionsPanel.tsx b/src/components/panels/database/options/LocalOptionsPanel.tsx index bf63aae1..c9a1d01d 100644 --- a/src/components/panels/database/options/LocalOptionsPanel.tsx +++ b/src/components/panels/database/options/LocalOptionsPanel.tsx @@ -9,6 +9,7 @@ import { SegmentedControl, Stack, Text, + NativeSelect } from "@mantine/core"; import { DateInput } from "@mantine/dates"; import { parseSquare } from "chessops"; @@ -57,6 +58,21 @@ function LocalOptionsPanel({ boardFen }: { boardFen: string }) { } /> + + Result: + + setOptions({ ...options, result: v.currentTarget.value as "any" | "whitewon" | "draw" | "blackwon" }) + } + /> + fen: "", player: null, color: "white", + result: "any", }), ); export const currentLocalOptionsAtom = tabValue(localOptionsFamily); diff --git a/src/utils/db.ts b/src/utils/db.ts index 08832317..2fa7194e 100644 --- a/src/utils/db.ts +++ b/src/utils/db.ts @@ -191,6 +191,7 @@ export async function searchPosition(options: LocalOptions, tab: string) { }, start_date: options.start_date, end_date: options.end_date, + wanted_result: options.result }, tab, ); diff --git a/src/utils/repertoire.ts b/src/utils/repertoire.ts index 64c432c4..b59d1bcd 100644 --- a/src/utils/repertoire.ts +++ b/src/utils/repertoire.ts @@ -74,6 +74,7 @@ export async function openingReport({ fen: item.node.fen, color: "white", player: null, + result: "any" }, "opening", );