hyperbole-0.4.2: Interactive HTML apps using type-safe serverside Haskell
Safe HaskellNone
LanguageGHC2021

Web.Hyperbole.Effect.Session

Synopsis

Documentation

session :: forall a (es :: [Effect]). (Session a, DefaultParam a, FromParam a, Hyperbole :> es) => Eff es a Source #

Persist datatypes in browser cookies. If the session doesn't exist, the DefaultParam is used

data Preferences = Preferences
  { color :: AppColor
  }
  deriving (Generic, Show, Read, ToParam, FromParam, Session)

instance DefaultParam Preferences where
  defaultParam = Preferences White

page :: (Hyperbole :> es) => Eff es (Page '[Content])
page = do
  prefs <- session @Preferences
  pure $ el (bg prefs.color) "Custom Background"

lookupSession :: forall a (es :: [Effect]). (Session a, FromParam a, Hyperbole :> es) => Eff es (Maybe a) Source #

Return a session if it exists

saveSession :: forall a (es :: [Effect]). (Session a, ToParam a, Hyperbole :> es) => a -> Eff es () Source #

Persist datatypes in browser cookies

data Preferences = Preferences
  { color :: AppColor
  }
  deriving (Generic, Show, Read, ToParam, FromParam, Session)

instance DefaultParam Preferences where
  defaultParam = Preferences White

instance HyperView Content es where
  data Action Content
    = SetColor AppColor
    deriving (Show, Read, ViewAction)

  update (SetColor clr) = do
    let prefs = Preferences clr
    saveSession prefs
    pure $ el (bg prefs.color) "Custom Background"

modifySession :: forall a (es :: [Effect]). (Session a, DefaultParam a, ToParam a, FromParam a, Hyperbole :> es) => (a -> a) -> Eff es a Source #

modifySession_ :: forall a (es :: [Effect]). (Session a, DefaultParam a, ToParam a, FromParam a, Hyperbole :> es) => (a -> a) -> Eff es () Source #

deleteSession :: forall a (es :: [Effect]). (Session a, Hyperbole :> es) => Eff es () Source #

Remove a single Session from the browser cookies

parseSession :: forall a (es :: [Effect]). (FromParam a, Hyperbole :> es) => Param -> ParamValue -> Eff es a Source #

setCookie :: forall a (es :: [Effect]). (ToParam a, Hyperbole :> es) => Cookie -> Eff es () Source #

save a single datatype to a specific key in the session

modifyCookies :: forall (es :: [Effect]). Hyperbole :> es => (Cookies -> Cookies) -> Eff es () Source #

Modify the client cookies

sessionCookies :: forall (es :: [Effect]). Hyperbole :> es => Eff es Cookies Source #

Return all the cookies, both those sent in the request and others added by the page

clientSessionCookies :: forall (es :: [Effect]). Hyperbole :> es => Eff es Cookies Source #

Return the session from the Client cookies

requestSessionCookies :: forall (es :: [Effect]). Hyperbole :> es => Eff es Cookies Source #

Return the session from the Request cookies