Skip to content

Commit

Permalink
all: fix regression about setting item date
Browse files Browse the repository at this point in the history
This commit updates a regression was not allowing to set correctly the modified field on edit.
This was also preventing to edit an item using the GUI.

Fixes #10
  • Loading branch information
lucor committed Feb 18, 2022
1 parent 8eb5be5 commit 487c432
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 2 deletions.
3 changes: 3 additions & 0 deletions internal/cli/cmd_edit.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package cli
import (
"fmt"
"os"
"time"

"lucor.dev/paw/internal/paw"
)
Expand Down Expand Up @@ -88,6 +89,8 @@ func (cmd *EditCmd) Run(s paw.Storage) error {
return fmt.Errorf("unsupported item type: %q", cmd.itemType)
}

item.GetMetadata().Modified = time.Now()

err = s.StoreItem(vault, item)
if err != nil {
return err
Expand Down
2 changes: 1 addition & 1 deletion internal/cli/cmd_show.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,8 @@ func (cmd *ShowCmd) Run(s paw.Storage) error {
fmt.Printf("Note: %s\n", v.Value)
}

fmt.Printf("Created: %s\n", item.GetMetadata().Created.Format(time.RFC1123))
fmt.Printf("Modified: %s\n", item.GetMetadata().Modified.Format(time.RFC1123))
fmt.Printf("Created: %s\n", item.GetMetadata().Created.Format(time.RFC1123))

if pclip != nil {
ctx, cancel := context.WithTimeout(context.Background(), clipboardWriteTimeout)
Expand Down
4 changes: 4 additions & 0 deletions internal/paw/item_metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ func (m *Metadata) GetMetadata() *Metadata {
return m
}

func (m *Metadata) IsEmpty() bool {
return m.Name == ""
}

func (m *Metadata) String() string {
return m.Name
}
Expand Down
5 changes: 4 additions & 1 deletion internal/ui/vault_view.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"strings"
"sync"
"sync/atomic"
"time"

"fyne.io/fyne/v2"
"fyne.io/fyne/v2/canvas"
Expand Down Expand Up @@ -326,8 +327,10 @@ func (vw *vaultView) editItemView(ctx context.Context, fyneItem FyneItem) fyne.C

var reloadItems bool
var isNew bool
if metadata.Created == metadata.Modified {
if item.GetMetadata().IsEmpty() {
isNew = true
} else {
metadata.Modified = time.Now()
}

if isNew && vw.vault.HasItem(editItem) {
Expand Down

0 comments on commit 487c432

Please sign in to comment.