Skip to content

Commit

Permalink
Merge pull request #7 from p-larson/mac-pagination
Browse files Browse the repository at this point in the history
Pagination
  • Loading branch information
p-larson committed Aug 22, 2023
2 parents 64e571f + 3c010d0 commit cdcb16d
Show file tree
Hide file tree
Showing 8 changed files with 211 additions and 177 deletions.
Binary file not shown.
4 changes: 2 additions & 2 deletions Bible/BibleApp.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ struct BibleApp: App {
DesktopReader()
})
#elseif os(iOS)
ReaderView(store: Store(initialState: Reader.State.init()) {
Reader()
MobileReaderView(store: Store(initialState: MobileReader.State.init()) {
MobileReader()
})
#else
fatalError("Unsupported OS")
Expand Down
21 changes: 21 additions & 0 deletions BibleCore/Sources/ReaderCore/DesktopReader/DesktopReaderView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,27 @@ public struct DesktopReaderView: View {
)
}
}
.overlay {
HStack {
Button {
viewStore.send(.page(.paginateChapter(forward: false)))
} label: {
Image(systemName: "arrow.left")
}
.keyboardShortcut(.leftArrow)
Spacer()
Button {
viewStore.send(.page(.paginateChapter(forward: true)))
} label: {
Image(systemName: "arrow.right")
}
.keyboardShortcut(.rightArrow)
}
.padding()
.buttonBorderShape(.roundedRectangle)
.buttonStyle(.borderedProminent)
.frame(maxHeight: .infinity, alignment: .bottom)
}
}
}
}
Expand Down
73 changes: 73 additions & 0 deletions BibleCore/Sources/ReaderCore/MobileReader/MobileReader.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
import BibleClient
import BibleCore
import CasePaths
import SwiftUI
import ComposableArchitecture
import DirectoryCore

public struct MobileReader: Reducer {
public init() {
// :)
}

public struct State: Equatable {
var page = Page.State()
var menuDirectory: MenuDirectory.State = MenuDirectory.State(
isDirectoryOpen: true,
books: []
)

@BindingState public var isDirectoryOpen: Bool = false

public init(
isDirectoryOpen: Bool = false
) {
self.isDirectoryOpen = isDirectoryOpen
}

var contentName: String? {
guard let book = page.book else {
return nil
}

guard let chapter = page.chapter else {
return book.name
}

return book.name + " " + chapter.id.description
}
}

public enum Action: BindableAction, Equatable {
case binding(_ action: BindingAction<State>)
case openDirectory
case page(Page.Action)
case menuDirectory(MenuDirectory.Action)
}

public var body: some Reducer<State, Action> {
BindingReducer()
Scope(state: \.menuDirectory, action: /Action.menuDirectory) {
MenuDirectory()
}
Scope(state: \.page, action: /Action.page) {
Page()
}
Reduce<State, Action> { state, action in
switch action {
case .openDirectory:
state.isDirectoryOpen = true
return .none
case .menuDirectory(.book(id: _, action: .select(let book, let chapter, let verses, let verse))):
state.isDirectoryOpen = false
return .send(.page(.open(book, chapter, verses, focused: verse, save: true)))
case .menuDirectory:
return .none
case .page:
return .none
case .binding(_):
return .none
}
}
}
}
109 changes: 109 additions & 0 deletions BibleCore/Sources/ReaderCore/MobileReader/MobileReaderView.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
import ComposableArchitecture
import DirectoryCore
import SwiftUI

public struct MobileReaderView: View {
let store: StoreOf<MobileReader>

public init(store: StoreOf<MobileReader>) {
self.store = store
}

func arrows(_ viewStore: ViewStoreOf<MobileReader>) -> some View {
HStack {
Button {
viewStore.send(.page(.paginateChapter(forward: false)))
} label: {
Image(systemName: "arrow.left")
}
Spacer()
Button {
viewStore.send(.page(.paginateChapter(forward: true)))
} label: {
Image(systemName: "arrow.right")
}
}
.shadow(radius: 8)
.buttonStyle(.borderedProminent)
.padding()
}

public var body: some View {
WithViewStore(store, observe: { $0 }) { viewStore in
VStack {
HStack {
Button {
viewStore.send(.openDirectory)
} label: {
if let book = viewStore.contentName {
Text(book)
} else {
ProgressView()
.progressViewStyle(.circular)
.controlSize(.mini)
}
}
.buttonStyle(.bordered)
Spacer()
}
.padding(.horizontal)
PageView(
store: store.scope(
state: \.page,
action: MobileReader.Action.page
)
)
}
.overlay(
HStack {
Button {
viewStore.send(.page(.paginateChapter(forward: false)))
} label: {
Image(systemName: "arrow.left")
}
Spacer()
Button {
viewStore.send(.page(.paginateChapter(forward: true)))
} label: {
Image(systemName: "arrow.right")
}
}
.shadow(radius: 8)
.buttonStyle(.borderedProminent)
.padding()
.frame(maxWidth: .infinity, maxHeight: .infinity, alignment: .bottom)
)
.popover(isPresented: viewStore.$isDirectoryOpen) {
NavigationStack {
MenuDirectoryView(
store: store.scope(
state: \.menuDirectory,
action: MobileReader.Action.menuDirectory
)
)
.navigationTitle("Books")
}
}
}
}
}

extension MobileReader.State {
static let mock = MobileReader.State(
isDirectoryOpen: false
)
}

struct BookReaderView_Previews: PreviewProvider {
static var previews: some View {
MobileReaderView(
store: Store(
initialState: .mock
) {
MobileReader()
}
)
.previewDisplayName("Mobile")
.previewDevice("iPhone 14")
}
}
169 changes: 0 additions & 169 deletions BibleCore/Sources/ReaderCore/Reader.swift

This file was deleted.

Loading

0 comments on commit cdcb16d

Please sign in to comment.