diff --git a/src-tauri/src/db/mod.rs b/src-tauri/src/db/mod.rs index 4adbe9c2..13b0b34c 100644 --- a/src-tauri/src/db/mod.rs +++ b/src-tauri/src/db/mod.rs @@ -667,6 +667,8 @@ pub struct GameQuery { pub player1: Option, pub player2: Option, pub tournament_id: Option, + pub start_date: Option, + pub end_date: Option, pub range1: Option<(i32, i32)>, pub range2: Option<(i32, i32)>, pub sides: Option, @@ -720,6 +722,16 @@ pub async fn get_games( count_query = count_query.filter(games::result.eq(outcome)); } + if let Some(start_date) = query.start_date { + sql_query = sql_query.filter(games::date.ge(start_date.clone())); + count_query = count_query.filter(games::date.ge(start_date)); + } + + if let Some(end_date) = query.end_date { + sql_query = sql_query.filter(games::date.le(end_date.clone())); + count_query = count_query.filter(games::date.le(end_date)); + } + if let Some(tournament_id) = query.tournament_id { sql_query = sql_query.filter(games::event_id.eq(tournament_id)); count_query = count_query.filter(games::event_id.eq(tournament_id)); diff --git a/src-tauri/src/db/search.rs b/src-tauri/src/db/search.rs index e83cbd4b..8118fc47 100644 --- a/src-tauri/src/db/search.rs +++ b/src-tauri/src/db/search.rs @@ -241,6 +241,7 @@ pub async fn search_position( games::id, games::white_id, games::black_id, + games::date, games::result, games::moves, games::fen, @@ -265,6 +266,7 @@ pub async fn search_position( id, white_id, black_id, + date, result, game, fen, @@ -294,6 +296,14 @@ pub async fn search_position( .unwrap(); } + if let Some(start_date) = &query.start_date { + if let Some(date) = date { + if date < start_date { + return; + } + } + } + if let Some(white) = query.player1 { if white != *white_id { return; @@ -396,6 +406,7 @@ pub async fn is_position_in_db( games::id, games::white_id, games::black_id, + games::date, games::result, games::moves, games::fen, @@ -413,6 +424,7 @@ pub async fn is_position_in_db( _id, _white_id, _black_id, + _date, _result, game, fen, diff --git a/src-tauri/src/main.rs b/src-tauri/src/main.rs index 344e64f7..a8b708d5 100644 --- a/src-tauri/src/main.rs +++ b/src-tauri/src/main.rs @@ -63,6 +63,7 @@ pub type GameData = ( i32, i32, Option, + Option, Vec, Option, i32, diff --git a/src/components/databases/GameTable.tsx b/src/components/databases/GameTable.tsx index 50d946ee..2e4879d9 100644 --- a/src/components/databases/GameTable.tsx +++ b/src/components/databases/GameTable.tsx @@ -6,7 +6,6 @@ import { type Outcome, query_games, } from "@/utils/db"; -import { invoke } from "@/utils/invoke"; import { createTab } from "@/utils/tabs"; import { ActionIcon, @@ -22,8 +21,10 @@ import { Text, useMantineTheme, } from "@mantine/core"; +import { DateInput } from "@mantine/dates"; import { useHotkeys, useToggle } from "@mantine/hooks"; import { IconDotsVertical, IconEye, IconTrash } from "@tabler/icons-react"; +import dayjs from "dayjs"; import { useAtom, useSetAtom } from "jotai"; import { DataTable } from "mantine-datatable"; import { useState } from "react"; @@ -182,6 +183,30 @@ function GameTable({ database }: { database: DatabaseInfo }) { { label: "Draw", value: "1/2-1/2" }, ]} /> + + + setQuery({ + ...query, start_date: dayjs(value).format( + "YYYY.MM.DD" + ) + }) + } + /> + + setQuery({ + ...query, end_date: dayjs(value).format( + "YYYY.MM.DD" + ) + }) + } + /> + diff --git a/src/utils/db.ts b/src/utils/db.ts index ce61a843..2623224a 100644 --- a/src/utils/db.ts +++ b/src/utils/db.ts @@ -60,6 +60,8 @@ export interface GameQuery extends Query { rangePlayer2?: [number, number]; speed?: Speed; outcome?: Outcome; + start_date?: string; + end_date?: string; } export interface Game { @@ -110,6 +112,8 @@ export async function query_games( sides: query.sides, speed: query.speed, outcome: query.outcome, + start_date: query.start_date, + end_date: query.end_date, }, }); }