Router.purs 1.83 KB
Newer Older
1
module Gargantext.Router where
2

3
import Gargantext.Prelude
Abinaya Sudhir's avatar
Abinaya Sudhir committed
4

5 6 7
import Control.Alt ((<|>))
import Data.Int (floor)
import Data.Maybe (Maybe(..))
Sudhir Kumar's avatar
Sudhir Kumar committed
8 9 10 11 12 13
import Effect (Effect)
import Effect.Class (liftEffect)
import Routing.Match (Match, lit, num)
import Web.HTML (window)
import Web.HTML.Window (localStorage)
import Web.Storage.Storage (getItem)
14 15 16 17

data Routes
  = Home
  | Login
Abinaya Sudhir's avatar
Abinaya Sudhir committed
18
  | SearchView
19 20 21
  | Folder             Int
    | Corpus           Int
      | AddCorpus
22
      | Document  Int
23
      | PGraphExplorer Int
24 25 26
      | Dashboard
    | Annuaire         Int
      | UserPage       Int
27
      | ContactPage       Int
28

29 30 31 32 33 34 35
routing :: Match Routes
routing =
      Login            <$   route "login"
  <|> SearchView       <$   route "search"
  <|> AddCorpus        <$   route "addCorpus"
  <|> Folder           <$> (route "folder"   *> int)
  <|> Corpus           <$> (route "corpus"   *> int)
36
    <|> Document     <$> (route "document" *> int)
37
    <|> Dashboard      <$   route "dashboard"
38
    <|> PGraphExplorer <$>   (route "graph" *> int )
39 40
  <|> Annuaire         <$> (route "annuaire" *> int)
    <|> UserPage       <$> (route "user"     *> int)
41
    <|> ContactPage       <$> (route "contact"     *> int)
42 43 44 45 46 47 48
  <|> Home             <$   lit ""
  
 where
    route str      = lit "" *> lit str
  
    int :: Match Int
    int = floor <$> num
49

50
instance showRoutes :: Show Routes where
Alexandre Delanoë's avatar
Alexandre Delanoë committed
51 52
  show Login            = "Login"
  show AddCorpus        = "AddCorpus"
53
  show SearchView       = "Search"
54
  show (UserPage i)     = "User"   <> show i
55
  show (ContactPage i)     = "Contact"   <> show i
56
  show (Document i)     = "Document"
57
  show (Corpus i)       = "Corpus" <> show i
58 59
  show (Annuaire i)     = "Annuaire" <> show i
  show (Folder   i)     = "Folder"   <> show i
60
  show Dashboard        = "Dashboard"
61
  show (PGraphExplorer i)   = "graphExplorer" <> show i
Alexandre Delanoë's avatar
Alexandre Delanoë committed
62
  show Home             = "Home"