mirror of
https://github.com/msfjarvis/compose-lobsters
synced 2025-08-14 17:37:05 +05:30
feat(common): add localSavedState
for save button composable
Signed-off-by: Aditya Wasan <adityawasan55@gmail.com> (cherry picked from commit 910471b32bde54749e437d374822c1d1e7830798)
This commit is contained in:
parent
b6598436b2
commit
743b2db4ef
1 changed files with 11 additions and 2 deletions
|
@ -21,6 +21,10 @@ import androidx.compose.material3.Icon
|
||||||
import androidx.compose.material3.MaterialTheme
|
import androidx.compose.material3.MaterialTheme
|
||||||
import androidx.compose.material3.Text
|
import androidx.compose.material3.Text
|
||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
|
import androidx.compose.runtime.getValue
|
||||||
|
import androidx.compose.runtime.mutableStateOf
|
||||||
|
import androidx.compose.runtime.remember
|
||||||
|
import androidx.compose.runtime.setValue
|
||||||
import androidx.compose.ui.Alignment
|
import androidx.compose.ui.Alignment
|
||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
import androidx.compose.ui.draw.clip
|
import androidx.compose.ui.draw.clip
|
||||||
|
@ -44,6 +48,7 @@ fun LobstersCard(
|
||||||
postActions: PostActions,
|
postActions: PostActions,
|
||||||
modifier: Modifier = Modifier,
|
modifier: Modifier = Modifier,
|
||||||
) {
|
) {
|
||||||
|
var localSavedState by remember(isSaved) { mutableStateOf(isSaved) }
|
||||||
Box(modifier = modifier.clickable { postActions.viewPost(post.url, post.commentsUrl) }) {
|
Box(modifier = modifier.clickable { postActions.viewPost(post.url, post.commentsUrl) }) {
|
||||||
Column(
|
Column(
|
||||||
modifier = Modifier.padding(horizontal = 16.dp, vertical = 4.dp).fillMaxWidth(),
|
modifier = Modifier.padding(horizontal = 16.dp, vertical = 4.dp).fillMaxWidth(),
|
||||||
|
@ -58,8 +63,12 @@ fun LobstersCard(
|
||||||
horizontalArrangement = Arrangement.End,
|
horizontalArrangement = Arrangement.End,
|
||||||
) {
|
) {
|
||||||
SaveButton(
|
SaveButton(
|
||||||
isSaved = isSaved,
|
isSaved = localSavedState,
|
||||||
modifier = Modifier.clickable { postActions.toggleSave(post) },
|
modifier =
|
||||||
|
Modifier.clickable {
|
||||||
|
localSavedState = localSavedState.not()
|
||||||
|
postActions.toggleSave(post)
|
||||||
|
},
|
||||||
)
|
)
|
||||||
Spacer(
|
Spacer(
|
||||||
modifier = Modifier.width(8.dp),
|
modifier = Modifier.width(8.dp),
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue