svitak/app/Types.hs
2026-02-12 11:17:36 +00:00

79 lines
1.6 KiB
Haskell

{-# LANGUAGE GeneralizedNewtypeDeriving #-}
module Types
( EpubEnv(..),
ChapterView(..),
Chapter(..),
AppState(..),
UserAction(..),
EpubAction,
NavItem(..),
ChapterIndex(..),
InternalPath(..),
EpubType(..),
)
where
import qualified Data.Text as T
import Codec.Archive.Zip (Archive)
import qualified Codec.Epub.Data.Metadata as DMeta
import qualified Codec.Epub.Data.Manifest as DMan
import Control.Concurrent.Async (Async)
import Control.Monad.Reader (ReaderT)
import Data.String (IsString)
newtype ChapterIndex = ChapterIndex Int
deriving (Show, Eq, Ord, Num)
newtype InternalPath = InternalPath FilePath
deriving (Show, Eq)
newtype EpubType = EpubType T.Text
deriving (Show,Eq, IsString)
data EpubEnv = EpubEnv
{ archive :: Archive,
opfXml :: String,
baseDir :: FilePath,
bookPath :: FilePath,
eMetadata :: DMeta.Metadata,
eManifest :: DMan.Manifest
}
data ChapterView = ChapterView
{ viewTitle :: T.Text,
viewHtml :: T.Text,
viewIdx :: ChapterIndex
}
data Chapter = Chapter
{ chapterTitle :: T.Text,
chapterTags :: T.Text,
chapterIdx :: ChapterIndex
}
data AppState = AppState
{ cEnv :: EpubEnv,
cIdx :: ChapterIndex,
zoomlvl :: Double,
cSpine :: [(InternalPath, T.Text)],
bTitle :: T.Text,
cAllChapters :: [Chapter],
activeTask :: Maybe (Async ()),
taskVersion :: Integer
}
type EpubAction a = ReaderT EpubEnv IO a
data UserAction
= NextChapter
| PrevChapter
| ZoomIn
| ZoomOut
| LoadSpecific ChapterIndex
data NavItem = NavItem
{ navLabel :: T.Text,
navPath :: InternalPath,
navTypes :: [EpubType]
} deriving (Show)