Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit d07a328

Browse files
committed
Feat: Support list of strings as notes in JSON import
1 parent 5e27d6b commit d07a328

File tree

1 file changed

+21
-2
lines changed

1 file changed

+21
-2
lines changed

tasklite-core/source/ImportExport.hs

+21-2
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,17 @@ annotationToNote annot@Annotation {entry = entry, description = description} =
6868
}
6969

7070

71+
textToNote :: DateTime -> Text -> Note
72+
textToNote utc body =
73+
let
74+
Right ulidGenerated = (ulidFromInteger . abs . toInteger . hash) body
75+
ulidCombined = setDateTime ulidGenerated utc
76+
in
77+
Note { ulid = (T.toLower . show) ulidCombined
78+
, body = body
79+
}
80+
81+
7182
importUtcFormat :: TimeFormatString
7283
importUtcFormat = (toFormat ("YYYY-MM-DD H:MI:S" :: [Char]))
7384

@@ -228,12 +239,20 @@ instance FromJSON ImportTask where
228239
(T.pack . (timePrint importUtcFormat))
229240
(parseUtc =<< maybeRecurrence)
230241

231-
o_notes <- o .:? "notes" :: Parser (Maybe [Note])
242+
o_notes <- asum
243+
[ o .:? "notes" :: Parser (Maybe [Note])
244+
, do
245+
notesMb <- o .:? "notes" :: Parser (Maybe [Text])
246+
pure $ case notesMb of
247+
Just textNotes -> Just $ textNotes <&> textToNote createdUtc
248+
Nothing -> Just []
249+
]
232250
annotations <- o .:? "annotations" :: Parser (Maybe [Annotation])
251+
233252
let
234253
notes = case (o_notes, annotations) of
235254
(Nothing, Nothing) -> []
236-
(Nothing, Just values) -> values <$$> annotationToNote
255+
(Nothing, Just values) -> values <&> annotationToNote
237256
(Just theNotes , _) -> case parsedCreatedUtc of
238257
Just crUtc -> theNotes <&> (\theNote ->
239258
let

0 commit comments

Comments
 (0)