Skip to content

Commit 00c8552

Browse files
author
Patrick Jackson
committed
[WIP] reading list working
1 parent 36d46f5 commit 00c8552

File tree

6 files changed

+18
-28
lines changed

6 files changed

+18
-28
lines changed

android/src/main/java/com/jackson/openlibrary/store/DetailsFragment.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,10 @@ class DetailsFragment : BaseLibraryViewFragment<DetailsView>(), CoroutineScope,
3131
.load(bookViewState.coverImageUrl)
3232
.into(imgBook)
3333
btnToRead.setOnClickListener {
34-
dispatch(Actions.AddToRead(bookViewState.book))
34+
dispatch(Actions.AddCurrentToRead())
3535
}
3636
btnCompleted.setOnClickListener {
37-
dispatch(Actions.AddToCompleted(bookViewState.book))
37+
dispatch(Actions.AddCurrentToCompleted())
3838
}
3939
}
4040
}

common/src/commonMain/kotlin/com/willowtreeapps/common/Actions.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ sealed class Actions {
1212

1313
data class BookSelected(val book: BookListItemViewState)
1414

15-
data class AddToCompleted(val book: Book)
16-
data class AddToRead(val book: Book)
15+
class AddCurrentToCompleted
16+
class AddCurrentToRead
1717

1818

1919
class LoadAllSettingsAction

common/src/commonMain/kotlin/com/willowtreeapps/common/NetworkThunks.kt

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@ class NetworkThunks(private val networkContext: CoroutineContext,
4646
fun fetchBooks(query: String): Thunk = { dispatch, getState, extraArgument ->
4747
Logger.d("Fetching Books and Feed")
4848
launch {
49-
Logger.d("INSIDE FetchBooks 1")
5049
dispatch(Actions.FetchingItemsStartedAction())
5150
val result = repo.search(query)
5251
if (result.isSuccessful) {
@@ -63,7 +62,6 @@ class NetworkThunks(private val networkContext: CoroutineContext,
6362
override fun dispatch(dispatch: Dispatcher, getState: GetState, extraArgument: Any?) {
6463
Logger.d("Fetching Books and Feed")
6564
launch {
66-
Logger.d("INSIDE FetchBooks 1")
6765
dispatch(Actions.FetchingItemsStartedAction())
6866
val result = repo.search(query)
6967
if (result.isSuccessful) {
@@ -86,22 +84,14 @@ fun createThunkMiddleware2(extraArgument: Any? = null): ThunkMiddleware =
8684
{ store ->
8785
{ next: Dispatcher ->
8886
{ action: Any ->
89-
Logger.d("INSIDE ThunkMiddleware 1: $action")
9087
if (action is Thunk2) {
91-
Logger.d("INSIDE ThunkMiddleware 2: ")
9288
try {
93-
Logger.d("dispatch thunk 1: ${store.dispatch}")
94-
Logger.d("dispatch thunk 2: ${store.getState}")
95-
Logger.d("dispatch thunk 3: ${extraArgument}")
96-
Logger.d("dispatch thunk 4: $action")
9789
action.dispatch(store.dispatch, store.getState, extraArgument)
9890
} catch (e: Exception) {
99-
Logger.d("INSIDE ThunkMiddleware 3: ${e.message}")
100-
throw IllegalArgumentException()
10191
Logger.d("Dispatching functions must use type Thunk: " + e.message)
92+
throw IllegalArgumentException()
10293
}
10394
} else {
104-
Logger.d("INSIDE ThunkMiddleware 4: ")
10595
next(action)
10696
}
10797
}
Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,22 @@
11
package com.willowtreeapps.common.middleware
22

33
import com.willowtreeapps.common.Actions
4+
import com.willowtreeapps.common.AppState
45
import com.willowtreeapps.common.repo.BookDatabaseRepo
56
import org.reduxkotlin.middleware
67

7-
class DatabaseMiddleware(val bookDatabaseRepo: BookDatabaseRepo) {
8+
class DatabaseMiddleware(private val bookDatabaseRepo: BookDatabaseRepo) {
89
val middleware = middleware { store, next, action ->
910
when (action) {
10-
is Actions.AddToCompleted ->
11-
bookDatabaseRepo.insertCompleted(action.book)
12-
is Actions.AddToRead ->
13-
bookDatabaseRepo.insertToRead(action.book)
11+
is Actions.AddCurrentToCompleted ->
12+
bookDatabaseRepo.insertCompleted((store.state as AppState).selectedBook!!)
13+
is Actions.AddCurrentToRead ->
14+
bookDatabaseRepo.insertToRead((store.state as AppState).selectedBook!!)
1415
is Actions.LoadToRead ->
1516
next(Actions.ToReadLoaded(bookDatabaseRepo.loadToRead()))
1617
is Actions.LoadCompleted ->
1718
next(Actions.CompletedLoaded(bookDatabaseRepo.loadCompleted()))
1819
}
1920
next(action)
2021
}
21-
}
22+
}

common/src/commonMain/kotlin/com/willowtreeapps/common/middleware/LoggingMiddleware.kt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import com.willowtreeapps.common.Logger
44
import org.reduxkotlin.*
55

66
val loggerMiddleware = middleware { store, next, action ->
7-
Logger.d("DISPATCH action: $action")
7+
Logger.d("********************************************")
8+
Logger.d("* DISPATCHED action: $action")
9+
Logger.d("********************************************")
810
next(action)
911
}

common/src/commonMain/kotlin/com/willowtreeapps/common/ui/PresenterFactory.kt

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ import org.reduxkotlin.*
99
import kotlin.coroutines.CoroutineContext
1010
import kotlin.reflect.KClass
1111

12-
interface LibraryView: ViewWithProvider<AppState>
13-
interface BaseLibraryView: View<AppState>
12+
interface LibraryView : ViewWithProvider<AppState>
13+
interface BaseLibraryView : View<AppState>
1414

1515
fun testMiddleware(store: Store): (Dispatcher) -> Dispatcher {
1616
return { next: Dispatcher ->
@@ -76,11 +76,8 @@ class PresenterFactory(private val libraryApp: LibraryApp,
7676
private fun hasAttachedViews() = subscribers.isNotEmpty()
7777

7878
private fun onStateChange() {
79-
Logger.d("PresenterFactory::onStateChanged!")
8079
launch {
81-
Logger.d("subscribers.size: ${subscribers.size}")
8280
subscribers.forEach {
83-
Logger.d("Subscriber: ${it.key} + ${it.value}")
8481
it.value()
8582
}
8683
}
@@ -106,7 +103,7 @@ interface PresenterProvider {
106103
fun presenter(): Presenter<View<AppState>> = throw NotImplementedError("Must implement this method to provide a presenterBuilder for ${this::class}")
107104
}
108105

109-
interface ViewWithProvider<S: Any>: View<S>, PresenterProvider
106+
interface ViewWithProvider<S : Any> : View<S>, PresenterProvider
110107

111108
//TODO handle config changes on android where view has been destroyed and must be recreated. Probably
112109
//can be treated as if a new state - wipe out the selector cache and treat as new view?

0 commit comments

Comments
 (0)