Skip to content

Commit

Permalink
v0.3.0: Simplify LinkDetail, use String as note content
Browse files Browse the repository at this point in the history
  • Loading branch information
rnons committed May 18, 2020
1 parent 03758cb commit ba6aa7a
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 64 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "fuji",
"version": "0.2.0",
"version": "0.3.0",
"private": true,
"repository": "https://github.com/nonbili/fuji",
"author": "Nonbili",
Expand Down
7 changes: 3 additions & 4 deletions src/Component/LinkPane.purs
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ handleAction = case _ of
OnAddTextNote -> do
state <- H.get
for_ state.detail \detail -> do
note <- liftEffect $ LinkDetail.newTextNote state.textNote
note <- liftEffect $ LinkDetail.newNote state.textNote
let
newDetail = detail
{ notes = Array.snoc detail.notes note
Expand All @@ -310,9 +310,8 @@ handleAction = case _ of
let
newDetail = detail
{ notes = fromMaybe detail.notes $
Array.modifyAt index (\note -> case note.content of
LinkDetail.NoteText _ -> note
{ content = LinkDetail.NoteText text }
Array.modifyAt index (\note -> note
{ content = text }
) detail.notes
}
H.modify_ $ _
Expand Down
83 changes: 41 additions & 42 deletions src/Component/Note.purs
Original file line number Diff line number Diff line change
Expand Up @@ -53,55 +53,54 @@ initialState note =
inputRef = H.RefLabel "textarea" :: H.RefLabel

render :: State -> HTML
render state@{ note } = case note.content of
LinkDetail.NoteText text ->
HH.div
[ class_ "border-b px-3 py-2"]
[ if state.editing
then
HH.div_
[ HH.textarea
[ class_ "Input resize-none"
, style "height: 80px"
, HP.value state.text
, HP.ref inputRef
, HE.onValueInput $ Just <<< OnTextInput
]
, HH.div
[ class_ "flex justify-between"]
[ HH.div_
[ HH.button
[ class_ "Btn-primary"
, HE.onClick $ Just <<< const OnClickSave
]
[ HH.text "Save"]
, HH.button
[ class_ "ml-2 Btn-normal"
, HE.onClick $ Just <<< const OnClickCancel
]
[ HH.text "Cancel"]
render state@{ note } =
HH.div
[ class_ "border-b px-3 py-2"]
[ if state.editing
then
HH.div_
[ HH.textarea
[ class_ "Input resize-none"
, style "height: 80px"
, HP.value state.text
, HP.ref inputRef
, HE.onValueInput $ Just <<< OnTextInput
]
, HH.div
[ class_ "flex justify-between"]
[ HH.div_
[ HH.button
[ class_ "Btn-primary"
, HE.onClick $ Just <<< const OnClickSave
]
[ HH.text "Save"]
, HH.button
[ class_ "Btn-danger"
, HE.onClick $ Just <<< const OnClickDelete
[ class_ "ml-2 Btn-normal"
, HE.onClick $ Just <<< const OnClickCancel
]
[ HH.text "Delete"]
[ HH.text "Cancel"]
]
]
else
HH.div
[ class_ "relative group break-all whitespace-pre-wrap"]
[ HH.text text
, HH.button
[ class_ "absolute top-0 right-0 hidden group-hover:block Btn-secondary"
, HE.onClick $ Just <<< const (OnClickEdit text)
[ class_ "Btn-danger"
, HE.onClick $ Just <<< const OnClickDelete
]
[ HH.text "Edit"]
[ HH.text "Delete"]
]
]
else
HH.div
[ class_ "relative group break-all whitespace-pre-wrap"]
[ HH.text note.content
, HH.button
[ class_ "absolute top-0 right-0 hidden group-hover:block Btn-secondary"
, HE.onClick $ Just <<< const (OnClickEdit note.content)
]
, HH.div
[ class_ "text-xs text-gray-600 mt-1 text-right"]
[ HH.text $ LinkDetail.formatNoteId note.id ]
]
[ HH.text "Edit"]
]
, HH.div
[ class_ "text-xs text-gray-600 mt-1 text-right"]
[ HH.text $ LinkDetail.formatNoteId note.id ]
]

component :: H.Component HH.HTML Query Props Message Aff
component = H.mkComponent
Expand Down
22 changes: 5 additions & 17 deletions src/Model/LinkDetail.purs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@ module Model.LinkDetail
( LinkDetail
, Note
, NoteId
, NoteContent(..)
, formatNoteId
, newTextNote
, newNote
, load
, save
, delete
Expand Down Expand Up @@ -43,32 +42,21 @@ derive newtype instance decodeJsonNoteId :: DecodeJson NoteId

type Note =
{ id :: NoteId
, content :: NoteContent
, content :: String
}

data NoteContent
= NoteText String

derive instance genericNoteContent :: Generic NoteContent _

instance encodeJsonNoteContent :: EncodeJson NoteContent where
encodeJson = genericEncodeJson

instance decodeJsonNoteContent :: DecodeJson NoteContent where
decodeJson = genericDecodeJson

newNoteId :: Effect NoteId
newNoteId = NoteId <$> Timestamp.newTimestamp

formatNoteId :: NoteId -> String
formatNoteId (NoteId ts) = Timestamp.formatTimestamp ts

newTextNote :: String -> Effect Note
newTextNote text = do
newNote :: String -> Effect Note
newNote content = do
id <- newNoteId
pure
{ id
, content: NoteText text
, content
}

getFileName :: LinkId -> FileName
Expand Down

0 comments on commit ba6aa7a

Please sign in to comment.