Skip to content

Commit

Permalink
Feature/initiate-model
Browse files Browse the repository at this point in the history
initiate model and add constant key mapping and help section
  • Loading branch information
MohamTahaB committed Feb 16, 2024
1 parent 06c06c5 commit 2d59099
Showing 1 changed file with 36 additions and 3 deletions.
39 changes: 36 additions & 3 deletions jotter/model/model.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package model

import (
"toolbox/jotter/storage"

"github.com/charmbracelet/bubbles/list"
"github.com/charmbracelet/bubbles/textarea"
"github.com/charmbracelet/bubbles/viewport"
Expand All @@ -16,8 +18,39 @@ const (
)

type Model struct {
State state
List list.Model
State state
List list.Model
FileEdit textarea.Model
ViewPort viewport.Model
}
}

// Initiates the app model.
func InitiateModel() (*Model, error) {
var m Model

// Initiate the storage.
JSONDir, _, err := storage.InitiateStorage()
if err != nil {
return nil, err
}

// Unmarshal the JSON file.
fileMap, err := storage.Unmarshal(JSONDir)
if err != nil {
return nil, err
}

// Build list items slice.
var filesSlice []list.Item
for _, file := range *fileMap {
filesSlice = append(filesSlice, file)
}

// Initiate the list and the file edit.
m.List = list.New(filesSlice, list.NewDefaultDelegate(), 0, 0)

m.List.Title = "Jotter"

return &m, nil

}

0 comments on commit 2d59099

Please sign in to comment.