Skip to content

Commit

Permalink
Merge pull request #10 from abadi199/mobile-support
Browse files Browse the repository at this point in the history
Add mobile support for comic reader.
  • Loading branch information
abadi199 authored Apr 11, 2019
2 parents 63bbe5c + a4acc29 commit 3825677
Show file tree
Hide file tree
Showing 8 changed files with 358 additions and 161 deletions.
5 changes: 5 additions & 0 deletions src/client/Entity/Image.elm
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
module Entity.Image exposing
( Image(..)
, ReloadableImage
, fromBase64
, fromBytes
, get
Expand All @@ -15,6 +16,10 @@ import ReloadableData exposing (ReloadableWebData)
import ReloadableData.Http


type alias ReloadableImage =
ReloadableWebData () Image


type Image
= Image String
| Empty
Expand Down
2 changes: 1 addition & 1 deletion src/client/Main.elm
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ pageUpdate msg model =
|> Return.mapBoth (PageMsg << PublicationMsg) (updatePage model Publication)

( ReadMsg pageMsg, Read pageModel ) ->
ReadPage.update model.key pageMsg pageModel
ReadPage.update model.key model.viewport pageMsg pageModel
|> Return.mapBoth (PageMsg << ReadMsg) (updatePage model Read)

( PublicationEditMsg pageMsg, PublicationEdit pageModel ) ->
Expand Down
33 changes: 19 additions & 14 deletions src/client/Page/Read.elm
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,12 @@ view viewport model =
publication
comicModel
, slider = Comic.slider comicModel
, reader = Comic.reader publication comicModel
, reader =
Comic.reader
{ viewport = viewport
, publication = publication
, model = comicModel
}
, previous = Comic.previous
, next = Comic.next
}
Expand Down Expand Up @@ -241,14 +246,14 @@ layout tagger { header, slider, reader, previous, next } =
-- UPDATE


update : Nav.Key -> Msg -> Model -> ( Model, Cmd Msg )
update key msg model =
update : Nav.Key -> Viewport -> Msg -> Model -> ( Model, Cmd Msg )
update key viewport msg model =
case msg of
NoOp ->
( model, Cmd.none )

GetDataCompleted data ->
updateCompletedData data model
updateCompletedData viewport data model

LinkClicked url ->
( model, Nav.pushUrl key url )
Expand All @@ -268,7 +273,7 @@ update key msg model =
model.publication
|> ReloadableData.toMaybe
|> Maybe.andThen toComic
|> Maybe.map (updateComic key comicMsg model)
|> Maybe.map (updateComic key viewport comicMsg model)
|> Maybe.withDefault ( model, Cmd.none )


Expand All @@ -283,11 +288,11 @@ updateEpub key epubMsg model ( publication, epubModel ) =
)


updateComic : Nav.Key -> Comic.Msg -> Model -> ( Publication.Data, Comic.Model ) -> ( Model, Cmd Msg )
updateComic key comicMsg model ( publication, comicModel ) =
updateComic : Nav.Key -> Viewport -> Comic.Msg -> Model -> ( Publication.Data, Comic.Model ) -> ( Model, Cmd Msg )
updateComic key viewport comicMsg model ( publication, comicModel ) =
let
( updatedComicModel, comicCmd ) =
Comic.update key comicMsg comicModel publication
Comic.update key viewport comicMsg comicModel publication
in
( { model
| publication =
Expand All @@ -298,8 +303,8 @@ updateComic key comicMsg model ( publication, comicModel ) =
)


updateCompletedData : ReloadableWebData Int Publication.Data -> Model -> ( Model, Cmd Msg )
updateCompletedData data model =
updateCompletedData : Viewport -> ReloadableWebData Int Publication.Data -> Model -> ( Model, Cmd Msg )
updateCompletedData viewport data model =
let
publicationId =
ReloadableData.toInitial data
Expand All @@ -314,14 +319,14 @@ updateCompletedData data model =
Just MediaFormat.CBR ->
data
|> ReloadableData.mapErr HttpError
|> ReloadableData.map (\publication -> Comic.init publication |> Tuple.mapFirst (Comic publication))
|> ReloadableData.map (\publication -> Comic.init viewport publication |> Tuple.mapFirst (Comic publication))
|> extract
|> Tuple.mapSecond (Maybe.withDefault Cmd.none >> Cmd.map ComicMsg)

Just MediaFormat.CBZ ->
data
|> ReloadableData.mapErr HttpError
|> ReloadableData.map (\publication -> Comic.init publication |> Tuple.mapFirst (Comic publication))
|> ReloadableData.map (\publication -> Comic.init viewport publication |> Tuple.mapFirst (Comic publication))
|> extract
|> Tuple.mapSecond (Maybe.withDefault Cmd.none >> Cmd.map ComicMsg)

Expand All @@ -334,13 +339,13 @@ updateCompletedData data model =
Just MediaFormat.NoMediaFormat ->
data
|> ReloadableData.mapErr HttpError
|> ReloadableData.andThen (\publication -> Failure (SimpleError "Unknown media format") publicationId)
|> ReloadableData.andThen (\_ -> Failure (SimpleError "Unknown media format") publicationId)
|> (\a -> ( a, Cmd.none ))

Nothing ->
data
|> ReloadableData.mapErr HttpError
|> ReloadableData.andThen (\publication -> Failure (SimpleError "Unknown media format") publicationId)
|> ReloadableData.andThen (\_ -> Failure (SimpleError "Unknown media format") publicationId)
|> (\a -> ( a, Cmd.none ))
in
( { model | publication = publicationType }
Expand Down
41 changes: 0 additions & 41 deletions src/client/Reader.elm

This file was deleted.

Loading

0 comments on commit 3825677

Please sign in to comment.