diff --git a/src/Guide/Markdown.hs b/src/Guide/Markdown.hs index a2429ac..89a4606 100644 --- a/src/Guide/Markdown.hs +++ b/src/Guide/Markdown.hs @@ -35,7 +35,6 @@ module Guide.Markdown markdownNull, extractPreface, stringify, - listFromMarkdownList ) where @@ -368,7 +367,3 @@ instance SafeCopy MarkdownTree where -- | Is a piece of Markdown empty? markdownNull :: HasMdText a Text => a -> Bool markdownNull = T.null . view mdText - -listFromMarkdownList :: [MD.Node] -> [[MD.Node]] -listFromMarkdownList [MD.Node _ (MD.LIST _) items] = map (\(MD.Node _ MD.ITEM i) -> i) items -listFromMarkdownList _ = [] diff --git a/src/Guide/ServerStuff.hs b/src/Guide/ServerStuff.hs index f205187..3e503f2 100644 --- a/src/Guide/ServerStuff.hs +++ b/src/Guide/ServerStuff.hs @@ -304,6 +304,10 @@ invalidateCacheForEdit ed = do [CacheItemNotes itemId] Edit'SetItemEcosystem itemId _ _ -> [CacheItemEcosystem itemId] + Edit'SetItemEcosystemTabName itemId _ _ _ -> + [CacheItemEcosystem itemId] + Edit'SetItemEcosystemTabBlock itemId _ _ _ -> + [CacheItemEcosystem itemId] Edit'SetTraitContent itemId _ _ _ -> [CacheItemTraits itemId] Edit'DeleteCategory catId _ -> diff --git a/src/Guide/Types/Core.hs b/src/Guide/Types/Core.hs index 5519c29..9acd119 100644 --- a/src/Guide/Types/Core.hs +++ b/src/Guide/Types/Core.hs @@ -76,9 +76,6 @@ import Guide.Markdown import Guide.Utils import Guide.Types.Hue -import qualified CMark as MD - - ---------------------------------------------------------------------------- -- General notes on code ---------------------------------------------------------------------------- @@ -173,15 +170,10 @@ makeFields ''EcosystemTab deriveSafeCopySorted 0 'base ''EcosystemTab createEcosystemFromMDBlock :: MarkdownBlock -> [EcosystemTab] -createEcosystemFromMDBlock blck = map toEcosystem - $ listFromMarkdownList - $ blck^.mdMarkdown - where - toEcosystem :: [MD.Node] -> EcosystemTab - toEcosystem nodes = - EcosystemTab (unsafePerformIO randomShortUid) +createEcosystemFromMDBlock blck = + [ EcosystemTab (unsafePerformIO randomShortUid) "Tab" - (MarkdownBlock (stringify nodes) (renderMD nodes) nodes) + blck ] instance A.ToJSON EcosystemTab where toJSON = A.genericToJSON A.defaultOptions { diff --git a/src/Guide/Types/Edit.hs b/src/Guide/Types/Edit.hs index 6a0d69a..d0611e5 100644 --- a/src/Guide/Types/Edit.hs +++ b/src/Guide/Types/Edit.hs @@ -16,11 +16,7 @@ module Guide.Types.Edit ) where - import Imports - --- Containers -import qualified Data.Set as S -- Network import Data.IP -- acid-state @@ -29,8 +25,6 @@ import Data.SafeCopy.Migrate import Guide.Utils import Guide.Types.Core -import Guide.Markdown (MarkdownBlock (..)) - -- | Edits made by users. It should always be possible to undo an edit. data Edit @@ -145,7 +139,7 @@ data Edit deriveSafeCopySimple 8 'extension ''Edit -genVer ''Edit 6 [ +genVer ''Edit 7 [ -- Add Copy 'Edit'AddCategory, Copy 'Edit'AddItem, @@ -156,18 +150,7 @@ genVer ''Edit 6 [ Copy 'Edit'SetCategoryGroup, Copy 'Edit'SetCategoryNotes, Copy 'Edit'SetCategoryStatus, - Custom "Edit'SetCategoryProsConsEnabled" [ - ("editCategoryUid" , [t|Uid Category|]), - ("_editCategoryProsConsEnabled" , [t|Bool|]), - ("editCategoryNewProsConsEnabled" , [t|Bool|]) ], - Custom "Edit'SetCategoryEcosystemEnabled" [ - ("editCategoryUid" , [t|Uid Category|]), - ("_editCategoryEcosystemEnabled" , [t|Bool|]), - ("editCategoryNewEcosystemEnabled", [t|Bool|]) ], - Custom "Edit'SetCategoryNotesEnabled" [ - ("editCategoryUid" , [t|Uid Category|]), - ("_editCategoryNotesEnabled" , [t|Bool|]), - ("editCategoryNewNotesEnabled" , [t|Bool|]) ], + Copy 'Edit'ChangeCategoryEnabledSections, -- Change item properties Copy 'Edit'SetItemName, Copy 'Edit'SetItemLink, @@ -186,11 +169,11 @@ genVer ''Edit 6 [ Copy 'Edit'MoveItem, Copy 'Edit'MoveTrait ] -deriveSafeCopySimple 6 'base ''Edit_v6 +deriveSafeCopySimple 7 'base ''Edit_v7 instance Migrate Edit where - type MigrateFrom Edit = Edit_v6 - migrate = $(migrateVer ''Edit 6 [ + type MigrateFrom Edit = Edit_v7 + migrate = $(migrateVer ''Edit 7 [ CopyM 'Edit'AddCategory, CopyM 'Edit'AddItem, CopyM 'Edit'AddPro, @@ -200,24 +183,7 @@ instance Migrate Edit where CopyM 'Edit'SetCategoryGroup, CopyM 'Edit'SetCategoryNotes, CopyM 'Edit'SetCategoryStatus, - CustomM "Edit'SetCategoryProsConsEnabled" [|\x -> - if editCategoryNewProsConsEnabled_v6 x - then Edit'ChangeCategoryEnabledSections (editCategoryUid_v6 x) - (S.singleton ItemProsConsSection) mempty - else Edit'ChangeCategoryEnabledSections (editCategoryUid_v6 x) - mempty (S.singleton ItemProsConsSection) |], - CustomM "Edit'SetCategoryEcosystemEnabled" [|\x -> - if editCategoryNewEcosystemEnabled_v6 x - then Edit'ChangeCategoryEnabledSections (editCategoryUid_v6 x) - (S.singleton ItemEcosystemSection) mempty - else Edit'ChangeCategoryEnabledSections (editCategoryUid_v6 x) - mempty (S.singleton ItemEcosystemSection) |], - CustomM "Edit'SetCategoryNotesEnabled" [|\x -> - if editCategoryNewNotesEnabled_v6 x - then Edit'ChangeCategoryEnabledSections (editCategoryUid_v6 x) - (S.singleton ItemNotesSection) mempty - else Edit'ChangeCategoryEnabledSections (editCategoryUid_v6 x) - mempty (S.singleton ItemNotesSection) |], + CopyM 'Edit'ChangeCategoryEnabledSections, -- Change item properties CopyM 'Edit'SetItemName, CopyM 'Edit'SetItemLink, @@ -265,6 +231,10 @@ isVacuousEdit Edit'SetItemNotes{..} = editItemNotes == editItemNewNotes isVacuousEdit Edit'SetItemEcosystem{..} = editItemEcosystem == editItemNewEcosystem +isVacuousEdit Edit'SetItemEcosystemTabName{..} = + editItemEcosystemTabName == editItemNewEcosystemTabName +isVacuousEdit Edit'SetItemEcosystemTabBlock{..} = + editItemEcosystemTabBlock == editItemNewEcosystemTabBlock isVacuousEdit Edit'SetTraitContent{..} = editTraitContent == editTraitNewContent isVacuousEdit Edit'AddCategory{} = False diff --git a/src/Guide/Views.hs b/src/Guide/Views.hs index 3a854d3..0007e99 100644 --- a/src/Guide/Views.hs +++ b/src/Guide/Views.hs @@ -479,6 +479,14 @@ renderEdit globalState edit = do p_ $ (if T.null oldEcosystem then "added" else "changed") >> " ecosystem of item " >> printItem itemId renderDiff oldEcosystem newEcosystem + Edit'SetItemEcosystemTabName itemId tabId oldName newName -> do + p_ $ (if T.null oldName then "added" else "changed") >> + " ecosystem tab name of item " >> printItem itemId + renderDiff oldName newName + Edit'SetItemEcosystemTabBlock itemId tabId oldBlock newBlock -> do + p_ $ (if T.null oldBlock then "added" else "changed") >> + " ecosystem tab name of item " >> printItem itemId + renderDiff oldBlock newBlock -- Change trait properties Edit'SetTraitContent itemId _traitId oldContent newContent -> do @@ -766,7 +774,7 @@ renderSearchResult r = do span_ [class_ "item-link-addition"] "'s ecosystem" div_ [class_ "ecosystem notes-like"] $ do strong_ $ toHtml $ tab^.name - toHtml (tab^.block.mdText) + toHtml (tab^.block) {- Note [enabled sections] ~~~~~~~~~~~~~~~~~~~~~~~~~~ diff --git a/src/Guide/Views/Item.hs b/src/Guide/Views/Item.hs index 49aea03..73f27af 100644 --- a/src/Guide/Views/Item.hs +++ b/src/Guide/Views/Item.hs @@ -93,9 +93,8 @@ renderItemForFeed category item = do ul_ $ mapM_ (p_ . li_ . toHtml . view content) (item^.cons) when (ItemEcosystemSection `elem` category^.enabledSections) $ do forM_ (item^.ecosystemTabs) $ \tab -> do - unless (markdownNull (tab^.block)) $ do - h2_ $ toHtml (tab^.name) - toHtml (tab^.block.mdText) + h2_ $ toHtml (tab^.name) + toHtml (tab^.block) -- TODO: include .notes-like style here? otherwise the headers are too big unless (markdownNull (item^.notes)) $ do h2_ "Notes" @@ -204,7 +203,7 @@ renderItemEcosystemTab item tab = do JS.selectClass "editor"] div_ [class_ "notes-like"] $ do unless (markdownNull (tab^.block)) $ - toHtml (tab^.block.mdText) + toHtml (tab^.block) section "editing" [] $ do strong_ $ toHtml $ tab^.name