-
Notifications
You must be signed in to change notification settings - Fork 169
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add blocks screen * Fix linter * Refresh site upon entering --------- Co-authored-by: Dessalines <[email protected]>
- Loading branch information
1 parent
9a7c7f8
commit 955accc
Showing
31 changed files
with
595 additions
and
131 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package com.jerboa.api | ||
|
||
sealed class ApiAction<out T>(val data: T) { | ||
class Ok<T>(data: T) : ApiAction<T>(data) | ||
|
||
class Loading<T>(data: T) : ApiAction<T>(data) | ||
|
||
class Failed<T>(data: T, val err: Throwable) : ApiAction<T>(data) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package com.jerboa.api | ||
|
||
sealed class ApiState<out T> { | ||
abstract class Holder<T>(val data: T) : ApiState<T>() | ||
|
||
class Success<T>(data: T) : Holder<T>(data) | ||
|
||
class Appending<T>(data: T) : Holder<T>(data) | ||
|
||
class AppendingFailure<T>(data: T) : Holder<T>(data) | ||
|
||
class Failure(val msg: Throwable) : ApiState<Nothing>() | ||
|
||
data object Loading : ApiState<Nothing>() | ||
|
||
data object Refreshing : ApiState<Nothing>() | ||
|
||
data object Empty : ApiState<Nothing>() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package com.jerboa.feed | ||
|
||
import com.jerboa.api.ApiAction | ||
|
||
class ApiActionController<T>( | ||
val idSelect: (T) -> Long, | ||
) { | ||
private val controller = FeedController<ApiAction<T>>() | ||
|
||
val feed: List<ApiAction<T>> | ||
get() = controller.feed | ||
|
||
fun init(newItems: List<T>) { | ||
controller.init(newItems.map { ApiAction.Ok(it) }) | ||
} | ||
|
||
fun setLoading(item: T) { | ||
controller.safeUpdate({ items -> | ||
items.indexOfFirst { idSelect(it.data) == idSelect(item) } | ||
}) { ApiAction.Loading(it.data) } | ||
} | ||
|
||
fun setOk(item: T) { | ||
controller.safeUpdate({ items -> | ||
items.indexOfFirst { idSelect(it.data) == idSelect(item) } | ||
}) { ApiAction.Ok(it.data) } | ||
} | ||
|
||
fun setFailed( | ||
item: T, | ||
error: Throwable, | ||
) { | ||
controller.safeUpdate({ items -> | ||
items.indexOfFirst { idSelect(it.data) == idSelect(item) } | ||
}) { ApiAction.Failed(it.data, error) } | ||
} | ||
|
||
fun removeItem(item: T) { | ||
val index = feed.indexOfFirst { idSelect(it.data) == idSelect(item) } | ||
controller.removeAt(index) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.