From cc2cb26edd995c2153c3334f2959ec3d9878fc85 Mon Sep 17 00:00:00 2001 From: Michael Zhang Date: Sun, 11 Jun 2023 23:08:34 -0500 Subject: [PATCH] test gh action --- .github/workflows/tauri.yml | 0 src-tauri/src/srs.rs | 10 ++++++- src-tauri/src/utils.rs | 2 +- src-tauri/tauri.conf.json | 2 +- src/components/DashboardReviewStats.tsx | 35 ++++++++++++++++--------- src/components/KanjiList.tsx | 1 - src/panes/KanjiPane.tsx | 8 +++++- src/panes/SrsReviewPane.tsx | 6 ----- 8 files changed, 41 insertions(+), 23 deletions(-) create mode 100644 .github/workflows/tauri.yml diff --git a/.github/workflows/tauri.yml b/.github/workflows/tauri.yml new file mode 100644 index 0000000..e69de29 diff --git a/src-tauri/src/srs.rs b/src-tauri/src/srs.rs index 25bd89f..b213a13 100644 --- a/src-tauri/src/srs.rs +++ b/src-tauri/src/srs.rs @@ -21,6 +21,7 @@ pub struct SrsStats { /// Used to calculate average success num_success: u32, num_failure: u32, + next_review: Option, } #[tauri::command] @@ -31,7 +32,8 @@ pub async fn get_srs_stats(db: State<'_, SrsDb>) -> Result { SELECT COUNT(*) AS total_items, SUM(SuccessCount) AS num_success, - SUM(FailureCount) AS num_failure + SUM(FailureCount) AS num_failure, + MIN(NextAnswerDate) AS next_review FROM SrsEntrySet "#, ) @@ -63,6 +65,11 @@ pub async fn get_srs_stats(db: State<'_, SrsDb>) -> Result { .await .map_err(|err| err.to_string())?; + let next_review = row + .try_get::("next_review") + .ok() + .map(|n| n / TICK_MULTIPLIER); + Ok(SrsStats { reviews_available: row2[0].get("reviews"), reviews_today: row2[1].get("reviews"), @@ -70,6 +77,7 @@ pub async fn get_srs_stats(db: State<'_, SrsDb>) -> Result { total_reviews: 0, num_success: row.try_get("num_success").unwrap_or(0), num_failure: row.try_get("num_failure").unwrap_or(0), + next_review, }) } diff --git a/src-tauri/src/utils.rs b/src-tauri/src/utils.rs index 47151a9..149cdb1 100644 --- a/src-tauri/src/utils.rs +++ b/src-tauri/src/utils.rs @@ -12,7 +12,7 @@ use sqlx::{ pub const TICK_MULTIPLIER: i64 = 1_000_000_000; -#[derive(Clone, Copy)] +#[derive(Debug, Clone, Copy)] pub struct Ticks(pub i64); #[derive(Debug, Clone, Copy, Serialize, Deserialize)] diff --git a/src-tauri/tauri.conf.json b/src-tauri/tauri.conf.json index 225c22b..393ae21 100644 --- a/src-tauri/tauri.conf.json +++ b/src-tauri/tauri.conf.json @@ -45,7 +45,7 @@ "fullscreen": false, "resizable": true, "title": "houhou", - "width": 800, + "width": 1024, "height": 600 } ] diff --git a/src/components/DashboardReviewStats.tsx b/src/components/DashboardReviewStats.tsx index 135135a..1a314d9 100644 --- a/src/components/DashboardReviewStats.tsx +++ b/src/components/DashboardReviewStats.tsx @@ -5,6 +5,7 @@ import useSWR from "swr"; import { invoke } from "@tauri-apps/api/tauri"; import { Link } from "react-router-dom"; import ConditionalWrapper from "./utils/ConditionalWrapper"; +import ReactTimeago from "react-timeago"; interface SrsStats { reviews_available: number; @@ -12,6 +13,7 @@ interface SrsStats { reviews_today: number; total_items: number; total_reviews: number; + next_review: number; /// Used to calculate average success num_success: number; @@ -43,6 +45,9 @@ export default function DashboardReviewStats() { const canReview = srsStats.reviews_available == 0; + const nextReviewDate = new Date(srsStats.next_review * 1_000); + const nextReview = ; + const generateStat = (stat: Stat) => { return ( @@ -55,16 +60,27 @@ export default function DashboardReviewStats() { }; return ( - - - - reviews available - {srsStats.reviews_available} - + + {generateStat({ label: "total items", value: srsStats.total_items })} + {generateStat({ label: "reviews today", value: srsStats.reviews_today })} + {generateStat({ label: "reviews available", value: srsStats.reviews_available })} + {generateStat({ label: "average success", value: averageSuccessStr })} + {generateStat({ label: "next review", value: nextReview })} + {children}} + wrapper={(children) => ( + + {children} + + )} elseWrapper={(children) => {children}} > - - {generateStat({ label: "reviews available", value: srsStats.reviews_available })} - {generateStat({ label: "reviews today", value: srsStats.reviews_today })} - {generateStat({ label: "total items", value: srsStats.total_items })} - {generateStat({ label: "average success", value: averageSuccessStr })} ); } diff --git a/src/components/KanjiList.tsx b/src/components/KanjiList.tsx index 79bfb79..39f5849 100644 --- a/src/components/KanjiList.tsx +++ b/src/components/KanjiList.tsx @@ -57,7 +57,6 @@ export function KanjiList({ const renderKanjiItem = (kanji: Kanji, active: boolean) => { const className = classNames(styles["kanji-link"], active && styles["kanji-link-active"]); - if (kanji.srs_info) console.log("kanji", kanji); return ( diff --git a/src/panes/KanjiPane.tsx b/src/panes/KanjiPane.tsx index 0cbd81d..033749b 100644 --- a/src/panes/KanjiPane.tsx +++ b/src/panes/KanjiPane.tsx @@ -16,7 +16,13 @@ export interface GetKanjiResult { export function Component() { const { selectedKanji } = useParams(); - const { data: baseData, error, isLoading } = useSWR("get_kanji", invoke); + const { + data: baseData, + error, + isLoading, + } = useSWR("get_kanji", () => + invoke("get_kanji", { options: { include_srs_info: true } }), + ); const [totalCount, setTotalCount] = useState(0); const [kanjiList, setKanjiList] = useState([]); diff --git a/src/panes/SrsReviewPane.tsx b/src/panes/SrsReviewPane.tsx index 649b108..75d08d4 100644 --- a/src/panes/SrsReviewPane.tsx +++ b/src/panes/SrsReviewPane.tsx @@ -119,8 +119,6 @@ export function Component() { // Figure out if we need to update the backend if (allQuestionsAnswered(nextItem.parent)) { - console.log("SHIET"); - const group = nextItem.parent; const newLevel = groupUpdatedLevel(group); @@ -132,7 +130,6 @@ export function Component() { }; const result = await invoke("update_srs_item", params); - console.log("result", result); } // If it's wrong this time @@ -193,9 +190,6 @@ export function Component() { return ( <> -

{JSON.stringify(completedQueue.map((x) => x.challenge))}

-

{JSON.stringify(reviewQueue.map((x) => x.challenge))}

- {startingSize && (