[list selection] implement list selection draft

parent 40d51410
...@@ -18,6 +18,7 @@ import Gargantext.Components.Forest.Tree.Node.Action (Action(..), Props) ...@@ -18,6 +18,7 @@ import Gargantext.Components.Forest.Tree.Node.Action (Action(..), Props)
import Gargantext.Components.Forest.Tree.Node.Action.Upload.Types (FileType(..), UploadFileBlob(..), readUFBAsText) import Gargantext.Components.Forest.Tree.Node.Action.Upload.Types (FileType(..), UploadFileBlob(..), readUFBAsText)
import Gargantext.Components.Forest.Tree.Node.Tools (fragmentPT, formChoiceSafe, panel) import Gargantext.Components.Forest.Tree.Node.Tools (fragmentPT, formChoiceSafe, panel)
import Gargantext.Components.Lang (Lang(..)) import Gargantext.Components.Lang (Lang(..))
import Gargantext.Components.ListSelection as ListSelection
import Gargantext.Config.REST (RESTError) import Gargantext.Config.REST (RESTError)
import Gargantext.Routes as GR import Gargantext.Routes as GR
import Gargantext.Sessions (Session, postWwwUrlencoded) import Gargantext.Sessions (Session, postWwwUrlencoded)
...@@ -72,8 +73,7 @@ data DroppedFile = ...@@ -72,8 +73,7 @@ data DroppedFile =
, lang :: Lang , lang :: Lang
} }
derive instance Generic DroppedFile _ derive instance Generic DroppedFile _
instance Eq DroppedFile where instance Eq DroppedFile where eq = genericEq
eq = genericEq
type FileHash = String type FileHash = String
...@@ -93,6 +93,7 @@ uploadFileViewCpt = here.component "uploadFileView" cpt ...@@ -93,6 +93,7 @@ uploadFileViewCpt = here.component "uploadFileView" cpt
mFile <- T.useBox (Nothing :: Maybe UploadFile) mFile <- T.useBox (Nothing :: Maybe UploadFile)
fileType <- T.useBox CSV fileType <- T.useBox CSV
lang <- T.useBox EN lang <- T.useBox EN
selection <- T.useBox ListSelection.MyListsFirst
let setFileType' val = T.write_ val fileType let setFileType' val = T.write_ val fileType
let setLang' val = T.write_ val lang let setLang' val = T.write_ val lang
...@@ -125,6 +126,10 @@ uploadFileViewCpt = here.component "uploadFileView" cpt ...@@ -125,6 +126,10 @@ uploadFileViewCpt = here.component "uploadFileView" cpt
show show
] ]
] ]
, R2.row
[ H.div { className: "col-6 flex-space-around" }
[ ListSelection.selection { selection } [] ]
]
] ]
let footer = H.div {} [ uploadButton { dispatch let footer = H.div {} [ uploadButton { dispatch
......
...@@ -201,7 +201,6 @@ type CheckboxProps = ...@@ -201,7 +201,6 @@ type CheckboxProps =
checkbox :: R2.Leaf CheckboxProps checkbox :: R2.Leaf CheckboxProps
checkbox props = R.createElement checkboxCpt props [] checkbox props = R.createElement checkboxCpt props []
checkboxCpt :: R.Component CheckboxProps checkboxCpt :: R.Component CheckboxProps
checkboxCpt = here.component "checkbox" cpt checkboxCpt = here.component "checkbox" cpt
where where
......
module Gargantext.Components.ListSelection where
import Gargantext.Prelude
import Data.Array as A
import Data.Eq.Generic (genericEq)
import Data.Generic.Rep (class Generic)
import Data.Maybe (Maybe(..))
import Gargantext.Components.Forest.Tree.Node.Tools (formChoiceSafe)
import Gargantext.Types (ListId)
import Gargantext.Utils.Reactix as R2
import Reactix as R
import Reactix.DOM.HTML as H
import Toestand as T
here :: R2.Here
here = R2.here "Gargantext.Components.ListSelection"
data Selection = MyListsFirst | OtherListsFirst | SelectedLists (Array ListId)
derive instance Generic Selection _
instance Show Selection where
show MyListsFirst = "My lists first"
show OtherListsFirst = "Other lists first"
show (SelectedLists _) = "Selected lists"
instance Eq Selection where eq = genericEq
instance Read Selection where
read "My lists first" = Just MyListsFirst
read "Other lists first" = Just OtherListsFirst
read "Selected lists" = Just $ SelectedLists []
read _ = Nothing
type Props =
( selection :: T.Box Selection )
selection :: R2.Component Props
selection = R.createElement selectionCpt
selectionCpt :: R.Component Props
selectionCpt = here.component "selection" cpt where
cpt { selection } _ = do
pure $ H.div {}
[ formChoiceSafe [ MyListsFirst
, OtherListsFirst
, SelectedLists [] ] MyListsFirst setSelection show
, selectedIds { selection } []
]
where
setSelection val = T.write_ val selection
selectedIds :: R2.Component Props
selectedIds = R.createElement selectedIdsCpt
selectedIdsCpt :: R.Component Props
selectedIdsCpt = here.component "selectedIds" cpt where
cpt { selection } _ = do
selection' <- T.useLive T.unequal selection
pure $ case selection' of
SelectedLists ids -> H.div {} [ idsSelector { ids, selection } [] ]
_ -> H.div {} []
type IdsSelectorProps =
( ids :: Array ListId
, selection :: T.Box Selection )
idsSelector :: R2.Component IdsSelectorProps
idsSelector = R.createElement idsSelectorCpt
idsSelectorCpt :: R.Component IdsSelectorProps
idsSelectorCpt = here.component "idsSelector" cpt where
cpt { ids, selection } _ = do
R.useEffect' $ do
here.log2 "[idsSelector] ids" ids
pure $ H.div {} $ map checkbox [1, 2, 3, 4]
where
checkbox val = H.div {}
[ H.input { className: "form-check-input"
, on: { click }
, type: "checkbox"
, value: A.elem val ids }
, H.label {} [ H.text $ show val ]
]
where
click _ = do
let f (SelectedLists lst) =
if A.elem val ids
then SelectedLists (A.delete val lst)
else SelectedLists (A.cons val lst)
f x = x
T.modify_ f selection
...@@ -9,9 +9,13 @@ import Data.Maybe (Maybe(..)) ...@@ -9,9 +9,13 @@ import Data.Maybe (Maybe(..))
import Effect (Effect) import Effect (Effect)
import Gargantext.Components.App.Data (Boxes) import Gargantext.Components.App.Data (Boxes)
import Gargantext.Routes (Tile) import Gargantext.Routes (Tile)
import Gargantext.Utils.Reactix as R2
import Reactix as R import Reactix as R
import Reactix.DOM.HTML as H import Reactix.DOM.HTML as H
here :: R2.Here
here = R2.here "Gargantext.Components.Tile"
type Props = type Props =
( boxes :: Boxes ( boxes :: Boxes
, tile :: Record Tile , tile :: Record Tile
...@@ -19,11 +23,10 @@ type Props = ...@@ -19,11 +23,10 @@ type Props =
, closeCallback :: Unit -> Effect Unit , closeCallback :: Unit -> Effect Unit
) )
tileBlock :: Record Props -> Array R.Element -> R.Element tileBlock :: R2.Component Props
tileBlock = R.createElement tileBlockCpt tileBlock = R.createElement tileBlockCpt
tileBlockCpt :: R.Component Props tileBlockCpt :: R.Component Props
tileBlockCpt = R.hooksComponent "tileBlock" cpt where tileBlockCpt = here.component "tileBlock" cpt where
cpt props@{ closeCallback } children = do cpt props@{ closeCallback } children = do
-- Render -- Render
......
...@@ -13,10 +13,14 @@ import Gargantext.Components.App.Data (Boxes) ...@@ -13,10 +13,14 @@ import Gargantext.Components.App.Data (Boxes)
import Gargantext.Hooks.LinkHandler (useLinkHandler) import Gargantext.Hooks.LinkHandler (useLinkHandler)
import Gargantext.Routes (AppRoute, Tile) import Gargantext.Routes (AppRoute, Tile)
import Gargantext.Utils.Popover as Popover import Gargantext.Utils.Popover as Popover
import Gargantext.Utils.Reactix as R2
import Reactix as R import Reactix as R
import Reactix.DOM.HTML as H import Reactix.DOM.HTML as H
import Toestand as T import Toestand as T
here :: R2.Here
here = R2.here "Gargantext.Components.TileMenu"
type Props = type Props =
( boxes :: Boxes ( boxes :: Boxes
, currentTile :: Maybe (Unit -> Effect AppRoute) , currentTile :: Maybe (Unit -> Effect AppRoute)
...@@ -24,11 +28,10 @@ type Props = ...@@ -24,11 +28,10 @@ type Props =
, yTile :: Maybe (Unit -> Effect AppRoute) , yTile :: Maybe (Unit -> Effect AppRoute)
) )
tileMenu :: Record Props -> Array (R.Element) -> R.Element tileMenu :: R2.Component Props
tileMenu = R.createElement tileMenuCpt tileMenu = R.createElement tileMenuCpt
tileMenuCpt :: R.Component Props tileMenuCpt :: R.Component Props
tileMenuCpt = R.hooksComponent "tileMenu" cpt where tileMenuCpt = here.component "tileMenu" cpt where
cpt props@{ boxes } children = do cpt props@{ boxes } children = do
-- Hooks -- Hooks
{ goToRoute } <- useLinkHandler { goToRoute } <- useLinkHandler
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment