-
Notifications
You must be signed in to change notification settings - Fork 167
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Adding ability to remove and restore comments. #1182 * Fix weird formatting miss. * Use ImmutableList instead of List. * Surrounding canMod with remember. * Adding ability to remove and restore posts. #1182 * Fixing jerboaappstate. * Removing extra RemoveViewModel. * Changing remove icon to gavel. * Change a few strings to non-contextual. * Add remove comment to commentmentionnode. * Remove non-optional body from compiler warning. * Wrapping remember around moderators.
- Loading branch information
1 parent
47ee753
commit 4a9ffba
Showing
20 changed files
with
381 additions
and
16 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,69 @@ | ||
package com.jerboa.model | ||
|
||
import android.content.Context | ||
import android.util.Log | ||
import android.widget.Toast | ||
import androidx.compose.runtime.getValue | ||
import androidx.compose.runtime.mutableStateOf | ||
import androidx.compose.runtime.setValue | ||
import androidx.compose.ui.focus.FocusManager | ||
import androidx.lifecycle.ViewModel | ||
import androidx.lifecycle.viewModelScope | ||
import com.jerboa.R | ||
import com.jerboa.api.API | ||
import com.jerboa.api.ApiState | ||
import com.jerboa.api.toApiState | ||
import com.jerboa.ui.components.common.apiErrorToast | ||
import it.vercruysse.lemmyapi.v0x19.datatypes.PostId | ||
import it.vercruysse.lemmyapi.v0x19.datatypes.PostResponse | ||
import it.vercruysse.lemmyapi.v0x19.datatypes.PostView | ||
import it.vercruysse.lemmyapi.v0x19.datatypes.RemovePost | ||
import kotlinx.coroutines.launch | ||
|
||
class PostRemoveViewModel : ViewModel() { | ||
var postRemoveRes: ApiState<PostResponse> by mutableStateOf(ApiState.Empty) | ||
private set | ||
|
||
fun removeOrRestorePost( | ||
postId: PostId, | ||
removed: Boolean, | ||
reason: String, | ||
ctx: Context, | ||
focusManager: FocusManager, | ||
onSuccess: (PostView) -> Unit, | ||
) { | ||
viewModelScope.launch { | ||
val form = | ||
RemovePost( | ||
post_id = postId, | ||
removed = removed, | ||
reason = reason, | ||
) | ||
|
||
postRemoveRes = ApiState.Loading | ||
postRemoveRes = API.getInstance().removePost(form).toApiState() | ||
|
||
when (val res = postRemoveRes) { | ||
is ApiState.Failure -> { | ||
Log.d("removePost", "failed", res.msg) | ||
apiErrorToast(msg = res.msg, ctx = ctx) | ||
} | ||
|
||
is ApiState.Success -> { | ||
val message = | ||
if (removed) { | ||
ctx.getString(R.string.post_removed) | ||
} else { | ||
ctx.getString(R.string.post_restored) | ||
} | ||
val postView = res.data.post_view | ||
Toast.makeText(ctx, message, Toast.LENGTH_SHORT).show() | ||
|
||
focusManager.clearFocus() | ||
onSuccess(postView) | ||
} | ||
else -> {} | ||
} | ||
} | ||
} | ||
} |
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
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.