diff --git a/ng-app/src/lib/Login.svelte b/ng-app/src/lib/Login.svelte index 8bdf5ed..cee8837 100644 --- a/ng-app/src/lib/Login.svelte +++ b/ng-app/src/lib/Login.svelte @@ -22,7 +22,7 @@ import { PuzzlePiece, XCircle, - ArrowLeftCircle, + Backspace, ArrowPath, LockOpen, } from "svelte-heros-v2"; @@ -31,7 +31,6 @@ export let for_import = false; let tauri_platform = import.meta.env.TAURI_PLATFORM; - let mobile = tauri_platform == "android" || tauri_platform == "ios"; const dispatch = createEventDispatcher(); @@ -87,8 +86,6 @@ let ordered = []; - let last_one = {}; - let shuffle_pin; let error; @@ -98,14 +95,9 @@ function order() { step = "order"; ordered = []; - last_one = {}; // In case, this is called by the cancel button, we need to reset the selection. selection.forEach((emoji) => (emoji.sel = undefined)); selection = selection; - - for (let i = 0; i < pazzle_length; i++) { - last_one[i] = true; - } } async function start_pin() { @@ -230,23 +222,16 @@ dispatch("cancel"); } - function to_previous_pazzle() { - pazzlePage = pazzlePage - 1; - } - async function on_pin_key(val) { pin_code = [...pin_code, val]; } - async function select_order(val, pos) { - delete last_one[pos]; - console.debug(last_one, val); - + async function select_order(val) { ordered.push(val); val.sel = ordered.length; selection = selection; if (ordered.length == pazzle_length - 1) { - let last = selection[Object.keys(last_one)[0]]; + let last = selection.find((emoji) => !emoji.sel); ordered.push(last); last.sel = ordered.length; selection = selection; @@ -254,9 +239,58 @@ await start_pin(); } } + + function go_back() { + if (step === "pazzle") { + // Go to previous pazzle or init page, if on first pazzle. + if (pazzlePage === 0) { + init(); + } else { + pazzlePage -= 1; + } + } else if (step === "order") { + if (ordered.length === 0) { + step = "pazzle"; + } else { + const last_selected = ordered.pop(); + last_selected.sel = null; + ordered = ordered; + selection = selection; + } + } else if (step === "pin") { + if (pin_code.length === 0) { + // Unselect the last two elements. + const to_unselect = ordered.slice(-2); + to_unselect.forEach((val) => { + val.sel = null; + }); + + ordered = ordered.slice(0, -2); + selection = selection; + step = "order"; + } else { + pin_code = pin_code.slice(0, pin_code.length - 1); + } + } + } + + let width: number; + let breakPoint: number = 361; + let mobile = false; + $: if (width >= breakPoint) { + mobile = false; + } else { + mobile = true; + } -
- - - Select your emoji of category: {emoji_cat[ - shuffle.category_indices[pazzlePage] - ]} -
- {#each [0, 1, 2, 3, 4] as row} -- Click your emojis in the correct order -
- {#each [0, 1, 2] as row} -+ + + Select your emoji of category: {emoji_cat[ + shuffle.category_indices[pazzlePage] + ]} +
+ {#each [0, 1, 2, 3, 4] as row} ++ Click your emojis in the correct order +
+ {#each [0, 1, 2] as row} ++ Enter your PIN code: + {#each pin_code as pin_key}*{/each} +
+ {#each [0, 1, 2] as row} +- Enter your PIN code -
- {#each [0, 1, 2] as row} -