diff options
| author | Maksymilian Jopek <maks@jopek.eu> | 2022-12-12 23:00:12 +0100 |
|---|---|---|
| committer | Maksymilian Jopek <maks@jopek.eu> | 2022-12-12 23:00:12 +0100 |
| commit | 9f4618c5ef618521ce1ab680d82ed9cc941d10d8 (patch) | |
| tree | dc29e3257783370075b17438d9c23b2d1e129d7e /src/lib/Saving.ts | |
| parent | b9f683fa36320fcdc08716c8303691e5cf7ce5cd (diff) | |
| download | digit-single-9f4618c5ef618521ce1ab680d82ed9cc941d10d8.tar.gz digit-single-9f4618c5ef618521ce1ab680d82ed9cc941d10d8.tar.zst digit-single-9f4618c5ef618521ce1ab680d82ed9cc941d10d8.zip | |
Added saving and loading
Fix same value for each column
Add showing errors
Diffstat (limited to 'src/lib/Saving.ts')
| -rw-r--r-- | src/lib/Saving.ts | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/src/lib/Saving.ts b/src/lib/Saving.ts new file mode 100644 index 0000000..0d71057 --- /dev/null +++ b/src/lib/Saving.ts @@ -0,0 +1,25 @@ +import type { Grid } from "./Sudoku"; + +export function save(grid: Grid) { + const a = document.createElement("a"); + const fileParts = [JSON.stringify(grid)]; + const blob = new Blob(fileParts, { type: 'application/json' }); // the blob + a.href = URL.createObjectURL(blob); + a.download = "sudoku-save.json"; + a.click(); +} +export function readGridFromFile(f: File): Promise<string[][] | null> { + return new Promise(res => { + let reader = new FileReader(); + reader.onload = e => { + try { + //@ts-expect-error + const json = JSON.parse(e.target.result); + res(json) + } catch (error) { + res(null) + } + }; + reader.readAsText(f); + }) +} |
