Skip to content

Commit

Permalink
fix #16 - create template if there no saved config
Browse files Browse the repository at this point in the history
  • Loading branch information
g.maksutenko committed Nov 15, 2021
1 parent b8b75c2 commit b481d9f
Showing 1 changed file with 30 additions and 2 deletions.
32 changes: 30 additions & 2 deletions src/Load.nim
Original file line number Diff line number Diff line change
@@ -1,6 +1,26 @@
import json, os

const SAVE_DIR_NAME = ".config" / "Dela" / "state.json"
const SAVE_DIR_NAME = ".config" / "Dela"
const SAVE_FILE_NAME = "state.json"
const FULL_PATH = SAVE_DIR_NAME / SAVE_FILE_NAME
const DEFAULT_CONTENT = """
[
{
"Main": [
{
"TODO": [
{
"name": "Todo example",
"time": 0,
"note": "",
"done": false
}
]
}
]
}
]
"""

type PageSave* = object
pageName*: string
Expand All @@ -16,7 +36,15 @@ type TaskSave* = object
note*: string
done*: bool

proc readSaveFromFS*(): JsonNode = (getHomeDir() / SAVE_DIR_NAME).readFile.parseJson

proc readSaveFromFS*(): JsonNode =
let path = (getHomeDir() / FULL_PATH)
if not fileExists(path):
createDir(getHomeDir() / SAVE_DIR_NAME)
echo "try to write to: ", path
writeFile(path, DEFAULT_CONTENT)

path.readFile.parseJson

func getPages*(x: JsonNode): seq[PageSave] =
assert x.kind == JArray
Expand Down

0 comments on commit b481d9f

Please sign in to comment.