Skip to content

Commit

Permalink
Merge pull request #74 from ckipp01/archive
Browse files Browse the repository at this point in the history
feat: add in an archive directory for deleted contexts
  • Loading branch information
ckipp01 committed Oct 26, 2023
2 parents d0aa53f + 03c6099 commit e3bd2ee
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
1 change: 1 addition & 0 deletions skan/src/Config.scala
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ object Config:
private val configDir = projectDirs.configDir
private lazy val defaultDataDir = os.Path(dataDir) / "contexts"
val configFile = os.Path(configDir) / "config.json"
val archiveDir = os.Path(dataDir) / "archive"

private def fromJson(json: String) =
upickle.default.read[Config](json)
Expand Down
15 changes: 12 additions & 3 deletions skan/src/ContextState.scala
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package skan

import java.time.Instant

/** The top level state of the application containing all of the various
* contexts. For most operations that have to do with the selected board this
* just acts as a facilators and calls the correct operation on the the correct
Expand Down Expand Up @@ -109,8 +111,8 @@ case class ContextState(

def addContext(name: String, boardOrder: Order): ContextState =
this.copy(
boards =
boards.updated(name, BoardState.fromItems(Vector.empty, boardOrder)),
boards = boards
.updated(name, BoardState.fromItems(Vector.empty, boardOrder)),
activeContext = name
)

Expand All @@ -123,7 +125,14 @@ case class ContextState(
* The new state
*/
def deleteContext(config: Config): ContextState =
os.remove(config.dataDir / s"${activeContext}.json")
val file = config.dataDir / s"${activeContext}.json"
if os.exists(file) then
os.move(
from = config.dataDir / s"${activeContext}.json",
to =
Config.archiveDir / s"${Instant.now().toString()}-${activeContext}.json",
createFolders = true
)
val newBoards = boards.removed(activeContext)
if newBoards.isEmpty then ContextState.fromConfig(config)
else
Expand Down

0 comments on commit e3bd2ee

Please sign in to comment.