module State where
import Control.Monad.State
import Twitter.Client (Tweet)
data Mode = NormalMode | InsertMode | CommandMode
data AppState = AppState { tweets :: [Tweet]
, active_tweet :: Int
, scroll :: Int
, geom :: (Int, Int)
, mode :: Mode
, auth :: String
}
getActiveTweet :: State AppState Int
getActiveTweet = get >>= return . active_tweet
setActiveTweet x = modifyActiveTweet (const x)
modifyActiveTweet f = do st <- get
tweets <- getTweets
let at' = f (active_tweet st)
newAt = max 0 (min at' $ length tweets - 1)
put $ st {active_tweet = newAt}
getTweets :: State AppState [Tweet]
getTweets = get >>= return . tweets
getAuth :: State AppState String
getAuth = get >>= return . auth
setMode x = modifyMode (const x)
modifyMode f = do st <- get
put $ st {mode = f (mode st)}