diff --git a/package.json b/package.json index 5a85e06..52b117d 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "fuji", - "version": "0.2.0", + "version": "0.3.0", "private": true, "repository": "https://github.com/nonbili/fuji", "author": "Nonbili", diff --git a/src/Component/LinkPane.purs b/src/Component/LinkPane.purs index 49b63af..a75f0d9 100644 --- a/src/Component/LinkPane.purs +++ b/src/Component/LinkPane.purs @@ -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 @@ -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_ $ _ diff --git a/src/Component/Note.purs b/src/Component/Note.purs index 8f2c572..b682920 100644 --- a/src/Component/Note.purs +++ b/src/Component/Note.purs @@ -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 diff --git a/src/Model/LinkDetail.purs b/src/Model/LinkDetail.purs index d1555ed..b7a140e 100644 --- a/src/Model/LinkDetail.purs +++ b/src/Model/LinkDetail.purs @@ -2,9 +2,8 @@ module Model.LinkDetail ( LinkDetail , Note , NoteId - , NoteContent(..) , formatNoteId - , newTextNote + , newNote , load , save , delete @@ -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