Commit 5252332f authored by Fabien Maniere's avatar Fabien Maniere

adding a function to open url in new window

parent a5010ff3
...@@ -174,7 +174,7 @@ docListCpt = here.component "main" cpt where ...@@ -174,7 +174,7 @@ docListCpt = here.component "main" cpt where
, state , state
} }
{ goToURL } <- useLinkHandler { goToURL, goToURLInNewTab } <- useLinkHandler
-- | Effects -- | Effects
-- | -- |
...@@ -261,8 +261,8 @@ docListCpt = here.component "main" cpt where ...@@ -261,8 +261,8 @@ docListCpt = here.component "main" cpt where
H.ul { className: "flex-row list-group justify-content-space-between align-items-center mb-1" } H.ul { className: "flex-row list-group justify-content-space-between align-items-center mb-1" }
[ H.li {} [ andOrButton { state: buttonState } ] [ H.li {} [ andOrButton { state: buttonState } ]
, H.li {} [ H.p { className: "text-bold" } [ H.text "No related documents" ] ] , H.li {} [ H.p { className: "text-bold" } [ H.text "No related documents" ] ]
, H.li {} [ B.iconButton { name: "search", title: "Search the web", callback: \_ -> webSearch (A.fromFoldable selectedNgramsTerms') goToURL } ] , H.li {} [ B.iconButton { name: "search", title: "Search the web", callback: \_ -> webSearch (A.fromFoldable selectedNgramsTerms') goToURLInNewTab } ]
, H.li {} [ B.iconButton { name: "wikipedia-w", title: "Search Wikipedia", callback: \_ -> wikipediaSearch (A.fromFoldable selectedNgramsTerms') goToURL } ] , H.li {} [ B.iconButton { name: "wikipedia-w", title: "Search Wikipedia", callback: \_ -> wikipediaSearch (A.fromFoldable selectedNgramsTerms') goToURLInNewTab } ]
] ]
, B.caveat , B.caveat
{} {}
...@@ -278,8 +278,8 @@ docListCpt = here.component "main" cpt where ...@@ -278,8 +278,8 @@ docListCpt = here.component "main" cpt where
H.ul { className: "flex-row list-group justify-content-space-between align-items-center mb-1" } H.ul { className: "flex-row list-group justify-content-space-between align-items-center mb-1" }
[ H.li {} [ andOrButton { state: buttonState } ] [ H.li {} [ andOrButton { state: buttonState } ]
, H.li {} [ H.p { className: "text-bold" } [ H.text $ show (Seq.length results) <> " related documents" ] ] , H.li {} [ H.p { className: "text-bold" } [ H.text $ show (Seq.length results) <> " related documents" ] ]
, H.li {} [ B.iconButton { name: "search", title: "Search the web", callback: \_ -> webSearch (A.fromFoldable selectedNgramsTerms') goToURL } ] , H.li {} [ B.iconButton { name: "search", title: "Search the web", callback: \_ -> webSearch (A.fromFoldable selectedNgramsTerms') goToURLInNewTab } ]
, H.li {} [ B.iconButton { name: "wikipedia-w", title: "Search Wikipedia", callback: \_ -> wikipediaSearch (A.fromFoldable selectedNgramsTerms') goToURL } ] , H.li {} [ B.iconButton { name: "wikipedia-w", title: "Search Wikipedia", callback: \_ -> wikipediaSearch (A.fromFoldable selectedNgramsTerms') goToURLInNewTab } ]
] ]
, H.ul , H.ul
{ className: intercalate " " { className: intercalate " "
......
...@@ -164,7 +164,7 @@ docListCpt = here.component "main" cpt where ...@@ -164,7 +164,7 @@ docListCpt = here.component "main" cpt where
, path: path' , path: path'
} }
{ goToURL } <- useLinkHandler { goToURL, goToURLInNewTab } <- useLinkHandler
-- | Effects -- | Effects
-- | -- |
...@@ -248,8 +248,8 @@ docListCpt = here.component "main" cpt where ...@@ -248,8 +248,8 @@ docListCpt = here.component "main" cpt where
H.ul { className: "flex-row list-group justify-content-space-between align-items-center mb-1" } H.ul { className: "flex-row list-group justify-content-space-between align-items-center mb-1" }
[ H.li {} [ andOrButton { state: buttonState } ] [ H.li {} [ andOrButton { state: buttonState } ]
, H.li {} [ H.p { className: "text-bold" } [ H.text "No related documents" ] ] , H.li {} [ H.p { className: "text-bold" } [ H.text "No related documents" ] ]
, H.li {} [ B.iconButton { name: "search", title: "Search the web", callback: \_ -> webSearch q' goToURL} ] , H.li {} [ B.iconButton { name: "search", title: "Search the web", callback: \_ -> webSearch q' goToURLInNewTab} ]
, H.li {} [ B.iconButton { name: "wikipedia-w", title: "Search Wikipedia", callback: \_ -> wikipediaSearch q' goToURL} ] , H.li {} [ B.iconButton { name: "wikipedia-w", title: "Search Wikipedia", callback: \_ -> wikipediaSearch q' goToURLInNewTab} ]
] ]
, B.caveat , B.caveat
{} {}
...@@ -264,8 +264,8 @@ docListCpt = here.component "main" cpt where ...@@ -264,8 +264,8 @@ docListCpt = here.component "main" cpt where
H.ul { className: "flex-row list-group justify-content-space-between align-items-center mb-1" } H.ul { className: "flex-row list-group justify-content-space-between align-items-center mb-1" }
[ H.li {} [ andOrButton { state: buttonState } ] [ H.li {} [ andOrButton { state: buttonState } ]
, H.li {} [ H.p { className: "text-bold" } [ H.text $ show (Seq.length results) <> " related documents" ] ] , H.li {} [ H.p { className: "text-bold" } [ H.text $ show (Seq.length results) <> " related documents" ] ]
, H.li {} [ B.iconButton { name: "search", title: "Search the web", callback: \_ -> webSearch q' goToURL} ] , H.li {} [ B.iconButton { name: "search", title: "Search the web", callback: \_ -> webSearch q' goToURLInNewTab} ]
, H.li {} [ B.iconButton { name: "wikipedia-w", title: "Search Wikipedia", callback: \_ -> wikipediaSearch q' goToURL} ] , H.li {} [ B.iconButton { name: "wikipedia-w", title: "Search Wikipedia", callback: \_ -> wikipediaSearch q' goToURLInNewTab} ]
] ]
, ,
H.ul H.ul
......
module Gargantext.Hooks.LinkHandler module Gargantext.Hooks.LinkHandler
( Methods, useLinkHandler ( Methods, useLinkHandler
, goToRoute, goToURL, goToPreviousPage , goToRoute, goToPreviousPage, goToURL, goToURLInNewTab
) where ) where
import Gargantext.Prelude import Gargantext.Prelude
...@@ -18,12 +18,13 @@ import Type.Proxy (Proxy(..)) ...@@ -18,12 +18,13 @@ import Type.Proxy (Proxy(..))
import Web.HTML (window) import Web.HTML (window)
import Web.HTML.History (back) import Web.HTML.History (back)
import Web.HTML.Location (assign, setHref) import Web.HTML.Location (assign, setHref)
import Web.HTML.Window (history, location) import Web.HTML.Window (history, location, open)
type Methods = type Methods =
( goToRoute :: AppRoute -> Effect Unit ( goToRoute :: AppRoute -> Effect Unit
, goToPreviousPage :: Unit -> Effect Unit , goToPreviousPage :: Unit -> Effect Unit
, goToURL :: String -> Effect Unit , goToURL :: String -> Effect Unit
, goToURLInNewTab :: String -> Effect Unit
) )
useLinkHandler :: R.Hooks (Record Methods) useLinkHandler :: R.Hooks (Record Methods)
...@@ -41,6 +42,7 @@ useLinkHandler = do ...@@ -41,6 +42,7 @@ useLinkHandler = do
tile tile
, goToPreviousPage : const goToPreviousPage , goToPreviousPage : const goToPreviousPage
, goToURL : goToURL , goToURL : goToURL
, goToURLInNewTab : goToURLInNewTab
} }
-- (?) Also exporting implementation methods, as it can be useful in an -- (?) Also exporting implementation methods, as it can be useful in an
...@@ -55,6 +57,12 @@ goToPreviousPage = window >>= history >>= back ...@@ -55,6 +57,12 @@ goToPreviousPage = window >>= history >>= back
goToURL :: String -> Effect Unit goToURL :: String -> Effect Unit
goToURL url = window >>= location >>= setHref url goToURL url = window >>= location >>= setHref url
goToURLInNewTab :: String -> Effect Unit
goToURLInNewTab url = do
_ <- window >>= open url "_blank" ""
-- _ <- window >>= \win -> win.open url "_blank" window
pure unit
-------------------------------------- --------------------------------------
changeTileRoute :: changeTileRoute ::
......
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