test gh action

This commit is contained in:
Michael Zhang 2023-06-11 23:08:34 -05:00
parent 561cb49fbf
commit cc2cb26edd
8 changed files with 41 additions and 23 deletions

0
.github/workflows/tauri.yml vendored Normal file
View file

View file

@ -21,6 +21,7 @@ pub struct SrsStats {
/// Used to calculate average success /// Used to calculate average success
num_success: u32, num_success: u32,
num_failure: u32, num_failure: u32,
next_review: Option<i64>,
} }
#[tauri::command] #[tauri::command]
@ -31,7 +32,8 @@ pub async fn get_srs_stats(db: State<'_, SrsDb>) -> Result<SrsStats, String> {
SELECT SELECT
COUNT(*) AS total_items, COUNT(*) AS total_items,
SUM(SuccessCount) AS num_success, SUM(SuccessCount) AS num_success,
SUM(FailureCount) AS num_failure SUM(FailureCount) AS num_failure,
MIN(NextAnswerDate) AS next_review
FROM SrsEntrySet FROM SrsEntrySet
"#, "#,
) )
@ -63,6 +65,11 @@ pub async fn get_srs_stats(db: State<'_, SrsDb>) -> Result<SrsStats, String> {
.await .await
.map_err(|err| err.to_string())?; .map_err(|err| err.to_string())?;
let next_review = row
.try_get::<i64, _>("next_review")
.ok()
.map(|n| n / TICK_MULTIPLIER);
Ok(SrsStats { Ok(SrsStats {
reviews_available: row2[0].get("reviews"), reviews_available: row2[0].get("reviews"),
reviews_today: row2[1].get("reviews"), reviews_today: row2[1].get("reviews"),
@ -70,6 +77,7 @@ pub async fn get_srs_stats(db: State<'_, SrsDb>) -> Result<SrsStats, String> {
total_reviews: 0, total_reviews: 0,
num_success: row.try_get("num_success").unwrap_or(0), num_success: row.try_get("num_success").unwrap_or(0),
num_failure: row.try_get("num_failure").unwrap_or(0), num_failure: row.try_get("num_failure").unwrap_or(0),
next_review,
}) })
} }

View file

@ -12,7 +12,7 @@ use sqlx::{
pub const TICK_MULTIPLIER: i64 = 1_000_000_000; pub const TICK_MULTIPLIER: i64 = 1_000_000_000;
#[derive(Clone, Copy)] #[derive(Debug, Clone, Copy)]
pub struct Ticks(pub i64); pub struct Ticks(pub i64);
#[derive(Debug, Clone, Copy, Serialize, Deserialize)] #[derive(Debug, Clone, Copy, Serialize, Deserialize)]

View file

@ -45,7 +45,7 @@
"fullscreen": false, "fullscreen": false,
"resizable": true, "resizable": true,
"title": "houhou", "title": "houhou",
"width": 800, "width": 1024,
"height": 600 "height": 600
} }
] ]

View file

@ -5,6 +5,7 @@ import useSWR from "swr";
import { invoke } from "@tauri-apps/api/tauri"; import { invoke } from "@tauri-apps/api/tauri";
import { Link } from "react-router-dom"; import { Link } from "react-router-dom";
import ConditionalWrapper from "./utils/ConditionalWrapper"; import ConditionalWrapper from "./utils/ConditionalWrapper";
import ReactTimeago from "react-timeago";
interface SrsStats { interface SrsStats {
reviews_available: number; reviews_available: number;
@ -12,6 +13,7 @@ interface SrsStats {
reviews_today: number; reviews_today: number;
total_items: number; total_items: number;
total_reviews: number; total_reviews: number;
next_review: number;
/// Used to calculate average success /// Used to calculate average success
num_success: number; num_success: number;
@ -43,6 +45,9 @@ export default function DashboardReviewStats() {
const canReview = srsStats.reviews_available == 0; const canReview = srsStats.reviews_available == 0;
const nextReviewDate = new Date(srsStats.next_review * 1_000);
const nextReview = <ReactTimeago date={nextReviewDate} />;
const generateStat = (stat: Stat) => { const generateStat = (stat: Stat) => {
return ( return (
<GridItem> <GridItem>
@ -55,16 +60,27 @@ export default function DashboardReviewStats() {
}; };
return ( return (
<Grid templateColumns="2fr 1fr 1fr" templateRows="1fr 1fr" gap={4}> <Grid templateColumns="repeat(3, 1fr)" templateRows="1fr 1fr" gap={4}>
<GridItem rowSpan={2} className={styles["reviews-available"]}> {generateStat({ label: "total items", value: srsStats.total_items })}
<Stat> {generateStat({ label: "reviews today", value: srsStats.reviews_today })}
<StatLabel>reviews available</StatLabel> {generateStat({ label: "reviews available", value: srsStats.reviews_available })}
<StatNumber>{srsStats.reviews_available}</StatNumber> {generateStat({ label: "average success", value: averageSuccessStr })}
</Stat> {generateStat({ label: "next review", value: nextReview })}
<GridItem>
<ConditionalWrapper <ConditionalWrapper
condition={canReview} condition={canReview}
wrapper={(children) => <Tooltip label="Add items to start reviewing">{children}</Tooltip>} wrapper={(children) => (
<Tooltip
label={
srsStats.total_items == 0
? "Add items to start reviewing"
: "Wait for the next review!"
}
>
{children}
</Tooltip>
)}
elseWrapper={(children) => <Link to="/srs/review">{children}</Link>} elseWrapper={(children) => <Link to="/srs/review">{children}</Link>}
> >
<Button isDisabled={canReview} colorScheme="blue"> <Button isDisabled={canReview} colorScheme="blue">
@ -72,11 +88,6 @@ export default function DashboardReviewStats() {
</Button> </Button>
</ConditionalWrapper> </ConditionalWrapper>
</GridItem> </GridItem>
{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 })}
</Grid> </Grid>
); );
} }

View file

@ -57,7 +57,6 @@ export function KanjiList({
const renderKanjiItem = (kanji: Kanji, active: boolean) => { const renderKanjiItem = (kanji: Kanji, active: boolean) => {
const className = classNames(styles["kanji-link"], active && styles["kanji-link-active"]); const className = classNames(styles["kanji-link"], active && styles["kanji-link-active"]);
if (kanji.srs_info) console.log("kanji", kanji);
return ( return (
<Link key={kanji.character} className={className} to={`/kanji/${kanji.character}`}> <Link key={kanji.character} className={className} to={`/kanji/${kanji.character}`}>

View file

@ -16,7 +16,13 @@ export interface GetKanjiResult {
export function Component() { export function Component() {
const { selectedKanji } = useParams(); const { selectedKanji } = useParams();
const { data: baseData, error, isLoading } = useSWR("get_kanji", invoke<GetKanjiResult>); const {
data: baseData,
error,
isLoading,
} = useSWR("get_kanji", () =>
invoke<GetKanjiResult>("get_kanji", { options: { include_srs_info: true } }),
);
const [totalCount, setTotalCount] = useState(0); const [totalCount, setTotalCount] = useState(0);
const [kanjiList, setKanjiList] = useState<Kanji[]>([]); const [kanjiList, setKanjiList] = useState<Kanji[]>([]);

View file

@ -119,8 +119,6 @@ export function Component() {
// Figure out if we need to update the backend // Figure out if we need to update the backend
if (allQuestionsAnswered(nextItem.parent)) { if (allQuestionsAnswered(nextItem.parent)) {
console.log("SHIET");
const group = nextItem.parent; const group = nextItem.parent;
const newLevel = groupUpdatedLevel(group); const newLevel = groupUpdatedLevel(group);
@ -132,7 +130,6 @@ export function Component() {
}; };
const result = await invoke("update_srs_item", params); const result = await invoke("update_srs_item", params);
console.log("result", result);
} }
// If it's wrong this time // If it's wrong this time
@ -193,9 +190,6 @@ export function Component() {
return ( return (
<> <>
<p>{JSON.stringify(completedQueue.map((x) => x.challenge))}</p>
<p>{JSON.stringify(reviewQueue.map((x) => x.challenge))}</p>
{startingSize && ( {startingSize && (
<Progress <Progress
colorScheme="linkedin" colorScheme="linkedin"