diff --git a/src-tauri/src/main.rs b/src-tauri/src/main.rs index c0ce1f4..593eb7a 100644 --- a/src-tauri/src/main.rs +++ b/src-tauri/src/main.rs @@ -16,7 +16,7 @@ use reqwest::Client; use tauri::Manager; use tokio::sync::mpsc; -struct CustomState (Option); +struct CustomState (Option, Option); #[tauri::command] async fn login(app: tauri::AppHandle, _window: tauri::Window, state: tauri::State<'_, Mutex>) -> Result { @@ -39,14 +39,14 @@ async fn login(app: tauri::AppHandle, _window: tauri::Window, state: tauri::Stat } #[tauri::command] -async fn load_altarik_manifest(state: tauri::State<'_, Mutex>>) -> Result { +async fn load_altarik_manifest(state: tauri::State<'_, Mutex>) -> Result { let reqwest_client = Client::new(); let altarik_manifest = AltarikManifest::get_altarik_manifest(&reqwest_client).await; match altarik_manifest { Ok(val) => { match state.lock() { Ok(mut global_manifest) => { - let _ = global_manifest.insert(val.clone()); + let _ = global_manifest.1.insert(val.clone()); Ok(val) }, Err(err) => { @@ -62,7 +62,7 @@ async fn load_altarik_manifest(state: tauri::State<'_, Mutex>) -> Result { +async fn download(game_version: String, app: tauri::AppHandle, state: tauri::State<'_, Mutex>) -> Result { if let Some(base_dir) = BaseDirs::new() { let data_folder = base_dir.data_dir().join(".altarik_test"); let root_path = data_folder.as_path(); @@ -80,7 +80,7 @@ async fn download(app: tauri::AppHandle, state: tauri::State<'_, Mutex, app: tauri: #[tokio::main] async fn main() { tauri::Builder::default() - .manage(Mutex::new(CustomState(None))) + .manage(Mutex::new(CustomState(None, None))) .invoke_handler(tauri::generate_handler![login, download, load_altarik_manifest]) .run(tauri::generate_context!()) .expect("error while running tauri application"); diff --git a/src/components/AltarikManifestComponent.tsx b/src/components/AltarikManifestComponent.tsx new file mode 100644 index 0000000..2fa03ea --- /dev/null +++ b/src/components/AltarikManifestComponent.tsx @@ -0,0 +1,18 @@ +import { AltarikManifest } from "../models/manifest/AltarikManifest"; +import ChapterList from "./ChapterList"; + +interface Props { + manifest: AltarikManifest | undefined, + selectedChapter: number, + onClickFunction: Function +} + +export default function AltarikManifestComponent({manifest, selectedChapter, onClickFunction} : Props) { + + return ( + <> + {manifest != undefined ? : <>} + + ) + +} \ No newline at end of file diff --git a/src/components/ChapterItem.tsx b/src/components/ChapterItem.tsx new file mode 100644 index 0000000..8a6b48a --- /dev/null +++ b/src/components/ChapterItem.tsx @@ -0,0 +1,16 @@ +import { title } from "process" +import { Chapter } from "../models/manifest/AltarikManifest" +import { MouseEventHandler } from "react" + +interface Props { + chapter: Chapter, + isSelected: boolean, + onClickFunction: MouseEventHandler +} + +export default function ChapterItem({ chapter, isSelected, onClickFunction } : Props) { + + return ( + + ) +} \ No newline at end of file diff --git a/src/components/ChapterList.tsx b/src/components/ChapterList.tsx new file mode 100644 index 0000000..b8d914b --- /dev/null +++ b/src/components/ChapterList.tsx @@ -0,0 +1,25 @@ +import { AltarikManifest, Chapter } from "../models/manifest/AltarikManifest" +import ChapterItem from "./ChapterItem" + + +interface Props { + chapters: Chapter[], + selectedChapter: number, + onClickFunction: Function +} + + +export default function ChapterList({ chapters, selectedChapter, onClickFunction }: Props) { + + + + return ( +
+ { + chapters.map((chapter, key) => ( + onClickFunction(key)}/> + )) + } +
+ ) +} \ No newline at end of file diff --git a/src/components/LoginPage.tsx b/src/components/LoginPage.tsx index a4b9115..c925bdb 100644 --- a/src/components/LoginPage.tsx +++ b/src/components/LoginPage.tsx @@ -1,5 +1,7 @@ import { useEffect, useState } from "react" import { invoke, event } from "@tauri-apps/api"; +import { AltarikManifest } from "../models/manifest/AltarikManifest"; +import AltarikManifestComponent from "./AltarikManifestComponent"; interface ProgressMessage { p_type: String, @@ -14,6 +16,8 @@ export default function LoginPage() { const [greetMessage, setGreetMessage] = useState(""); const [isLogged, setIsLogged] = useState(false); const [loginButtonDisabled, setLoginButtonDisabled] = useState(false); + const [altarikManifest, setAltarikManifest] = useState(); + const [selectedChapter, setSelectChapter] = useState(-1); useEffect(() => { event.listen('progress', (e) => { @@ -21,9 +25,20 @@ export default function LoginPage() { setGreetMessage("{type: " + v.p_type + ", current: " + v.current + ", total: " + v.total + "}"); // setGreetMessage(String(e.payload)); }); - }, []) + useEffect(() => { + if(isLogged) { + invoke('load_altarik_manifest', {}).then(val => { + setAltarikManifest(val as AltarikManifest) + }).catch(err => { + setGreetMessage("Cannot load altarik manifest: " + err) + }) + } else { + setAltarikManifest(undefined) + } + }, [isLogged]) + async function login () { if(!isLogged && !loginButtonDisabled) { setLoginButtonDisabled(true); @@ -39,16 +54,23 @@ export default function LoginPage() { async function download() { if(isLogged) { - invoke("download", {}).then(value => { - setGreetMessage(String(value)) - // this.greet_message = value - }).catch(err => { - console.log("An error occured") - setGreetMessage("Error: " + err) - }) + if(selectedChapter !== -1 && altarikManifest !== undefined) { + invoke("download", { gameVersion: altarikManifest?.chapters[selectedChapter].minecraftVersion }).then(value => { + setGreetMessage(String(value)) + }).catch(err => { + console.log("An error occured") + setGreetMessage("Error: " + err) + }) + } else { + setGreetMessage("Please select a chapter first") + } } } + async function select_chapter(key: number) { + setSelectChapter(key) + } + return ( <>

Welcome to Tauri!

@@ -60,6 +82,9 @@ export default function LoginPage() {

{ greetMessage }

+ +
+ ) diff --git a/src/models/manifest/AltarikManifest.tsx b/src/models/manifest/AltarikManifest.tsx new file mode 100644 index 0000000..7a107a7 --- /dev/null +++ b/src/models/manifest/AltarikManifest.tsx @@ -0,0 +1,9 @@ + +export interface AltarikManifest { + chapters: Chapter[] +} + +export interface Chapter { + title: String, + minecraftVersion: String, +} \ No newline at end of file diff --git a/src/styles.css b/src/styles.css index 07e4fb2..a809149 100644 --- a/src/styles.css +++ b/src/styles.css @@ -88,6 +88,10 @@ button { display: none; } +button.selected { + color: red; +} + @media (prefers-color-scheme: dark) { :root { color: #f6f6f6;