Slight function name refactor in LabeledBookmarkListsState, and inclusion of a method to reference a particular bookmark group. Add route for viewing a bookmark group, and wire UI accordingly.

This commit is contained in:
KotlinGeekDev
2025-11-16 15:40:46 +01:00
parent 37b6f84d9f
commit eb8b19ceb9
4 changed files with 33 additions and 16 deletions
@@ -127,7 +127,16 @@ class LabeledBookmarkListsState(
fun getLabeledBookmarkListNote(bookmarkIdentifier: String): AddressableNote? = existingLabeledBookmarkNotes().find { it.dTag() == bookmarkIdentifier }
fun getLabeledBookmarkList(bookmarkIdentifier: String): LabeledBookmarkListEvent = getLabeledBookmarkListNote(bookmarkIdentifier)?.event as LabeledBookmarkListEvent
fun getLabeledBookmarkListEvent(bookmarkIdentifier: String): LabeledBookmarkListEvent = getLabeledBookmarkListNote(bookmarkIdentifier)?.event as LabeledBookmarkListEvent
fun getLabeledBookmarkListFlow(bookmarkIdentifier: String) =
labeledBookmarkListNotes
.map { getLabeledBookmarkListEvent(bookmarkIdentifier).toLabeledBookmarkList() }
.onStart {
emit(
getLabeledBookmarkListEvent(bookmarkIdentifier).toLabeledBookmarkList(),
)
}.flowOn(Dispatchers.IO)
suspend fun addLabeledBookmarkList(
listName: String,
@@ -152,7 +161,7 @@ class LabeledBookmarkListsState(
bookmarkList: LabeledBookmarkList,
account: Account,
) {
val listEvent = getLabeledBookmarkList(bookmarkList.identifier)
val listEvent = getLabeledBookmarkListEvent(bookmarkList.identifier)
val renamedList =
LabeledBookmarkListEvent.modifyName(
earlierVersion = listEvent,
@@ -167,7 +176,7 @@ class LabeledBookmarkListsState(
bookmarkList: LabeledBookmarkList,
account: Account,
) {
val listEvent = getLabeledBookmarkList(bookmarkList.identifier)
val listEvent = getLabeledBookmarkListEvent(bookmarkList.identifier)
val modifiedList =
LabeledBookmarkListEvent.modifyDescription(
earlierVersion = listEvent,
@@ -198,7 +207,7 @@ class LabeledBookmarkListsState(
bookmarkList: LabeledBookmarkList,
account: Account,
) {
val listEvent = getLabeledBookmarkList(bookmarkList.identifier)
val listEvent = getLabeledBookmarkListEvent(bookmarkList.identifier)
val deletionEvent = account.signer.sign(DeletionEvent.build(listOf(listEvent)))
account.sendMyPublicAndPrivateOutbox(deletionEvent)
}
@@ -209,7 +218,7 @@ class LabeledBookmarkListsState(
isBookmarkPrivate: Boolean,
account: Account,
) {
val currentBookmarkList = getLabeledBookmarkList(bookmarkList.identifier)
val currentBookmarkList = getLabeledBookmarkListEvent(bookmarkList.identifier)
val updatedList =
LabeledBookmarkListEvent.addBookmark(
earlierVersion = currentBookmarkList,
@@ -226,7 +235,7 @@ class LabeledBookmarkListsState(
isBookmarkPrivate: Boolean,
account: Account,
) {
val currentBookmarkList = getLabeledBookmarkList(bookmarkList.identifier)
val currentBookmarkList = getLabeledBookmarkListEvent(bookmarkList.identifier)
val updatedList =
LabeledBookmarkListEvent.removeBookmark(
earlierVersion = currentBookmarkList,
@@ -23,6 +23,7 @@ package com.vitorpamplona.amethyst.ui.navigation.routes
import androidx.navigation.NavDestination.Companion.hasRoute
import androidx.navigation.NavHostController
import androidx.navigation.toRoute
import com.vitorpamplona.amethyst.ui.screen.loggedIn.bookmarkgroups.BookmarkType
import com.vitorpamplona.quartz.nip01Core.core.Address
import com.vitorpamplona.quartz.nip01Core.core.HexKey
import com.vitorpamplona.quartz.nip17Dm.base.ChatroomKey
@@ -49,6 +50,11 @@ sealed class Route {
@Serializable object BookmarkGroups : Route()
@Serializable data class BookmarkGroupView(
val dTag: String,
val bookmarkType: BookmarkType,
) : Route()
@Serializable object Drafts : Route()
@Serializable object Settings : Route()
@@ -37,6 +37,7 @@ import androidx.compose.ui.Modifier
import androidx.lifecycle.compose.collectAsStateWithLifecycle
import com.vitorpamplona.amethyst.R
import com.vitorpamplona.amethyst.model.nip51Lists.labeledBookmarkLists.LabeledBookmarkList
import com.vitorpamplona.amethyst.ui.screen.loggedIn.bookmarkgroups.BookmarkType
import com.vitorpamplona.amethyst.ui.stringRes
import com.vitorpamplona.amethyst.ui.theme.DividerThickness
import com.vitorpamplona.amethyst.ui.theme.FeedPadding
@@ -47,7 +48,7 @@ import kotlinx.coroutines.flow.StateFlow
@Composable
fun ListOfBookmarkGroupsFeedView(
groupListFeedSource: StateFlow<List<LabeledBookmarkList>>,
onOpenItem: (String) -> Unit,
onOpenItem: (String, BookmarkType) -> Unit,
onRenameItem: (targetBookmarkGroup: LabeledBookmarkList, newName: String) -> Unit,
onItemDescriptionChange: (bookmarkGroup: LabeledBookmarkList, newDescription: String?) -> Unit,
onItemClone: (bookmarkGroup: LabeledBookmarkList, customName: String?, customDesc: String?) -> Unit,
@@ -69,7 +70,7 @@ fun ListOfBookmarkGroupsFeedView(
BookmarkGroupItem(
modifier = Modifier.fillMaxSize().animateItem(),
bookmarkList = groupItem,
onClick = { onOpenItem(groupItem.identifier) },
onClick = { bookmarkType -> onOpenItem(groupItem.identifier, bookmarkType) },
onRename = { onRenameItem(groupItem, it) },
onDescriptionChange = { onItemDescriptionChange(groupItem, it) },
onClone = { cloneName, cloneDescription -> onItemClone(groupItem, cloneName, cloneDescription) },
@@ -41,6 +41,7 @@ import com.vitorpamplona.amethyst.ui.navigation.navs.INav
import com.vitorpamplona.amethyst.ui.navigation.routes.Route
import com.vitorpamplona.amethyst.ui.navigation.topbars.TopBarWithBackButton
import com.vitorpamplona.amethyst.ui.screen.loggedIn.AccountViewModel
import com.vitorpamplona.amethyst.ui.screen.loggedIn.bookmarkgroups.BookmarkType
import com.vitorpamplona.amethyst.ui.stringRes
import kotlinx.coroutines.flow.StateFlow
@@ -52,7 +53,7 @@ fun ListOfBookmarkGroupsScreen(
ListOfBookmarkGroupsFeed(
listSource = accountViewModel.account.labeledBookmarkLists.listFeedFlow,
addBookmarkGroup = { title, description ->
accountViewModel.runIOCatching {
accountViewModel.launchSigner {
accountViewModel.account.labeledBookmarkLists.addLabeledBookmarkList(
listName = title,
listDescription = description,
@@ -60,11 +61,11 @@ fun ListOfBookmarkGroupsScreen(
)
}
},
openBookmarkGroup = {
nav.nav(Route.BookmarkGroupView(it))
openBookmarkGroup = { identifier, bookmarkType ->
nav.nav(Route.BookmarkGroupView(identifier, bookmarkType))
},
renameBookmarkGroup = { bookmarkGroup, newName ->
accountViewModel.runIOCatching {
accountViewModel.launchSigner {
accountViewModel.account.labeledBookmarkLists.renameBookmarkList(
newName = newName,
bookmarkList = bookmarkGroup,
@@ -73,7 +74,7 @@ fun ListOfBookmarkGroupsScreen(
}
},
changeBookmarkGroupDescription = { bookmarkGroup, newDescription ->
accountViewModel.runIOCatching {
accountViewModel.launchSigner {
accountViewModel.account.labeledBookmarkLists.modifyListDescription(
newDescription = newDescription,
bookmarkList = bookmarkGroup,
@@ -82,7 +83,7 @@ fun ListOfBookmarkGroupsScreen(
}
},
cloneBookmarkGroup = { bookmarkGroup, customName, customDesc ->
accountViewModel.runIOCatching {
accountViewModel.launchSigner {
accountViewModel.account.labeledBookmarkLists.cloneBookmarkList(
currentBookmarkList = bookmarkGroup,
customCloneName = customName,
@@ -92,7 +93,7 @@ fun ListOfBookmarkGroupsScreen(
}
},
deleteBookmarkGroup = { bookmarkGroup ->
accountViewModel.runIOCatching {
accountViewModel.launchSigner {
accountViewModel.account.labeledBookmarkLists.deleteBookmarkList(
bookmarkList = bookmarkGroup,
account = accountViewModel.account,
@@ -107,7 +108,7 @@ fun ListOfBookmarkGroupsScreen(
fun ListOfBookmarkGroupsFeed(
listSource: StateFlow<List<LabeledBookmarkList>>,
addBookmarkGroup: (title: String, description: String?) -> Unit,
openBookmarkGroup: (identifier: String) -> Unit,
openBookmarkGroup: (identifier: String, bookmarkType: BookmarkType) -> Unit,
renameBookmarkGroup: (bookmarkGroup: LabeledBookmarkList, newName: String) -> Unit,
changeBookmarkGroupDescription: (bookmarkGroup: LabeledBookmarkList, newDescription: String?) -> Unit,
cloneBookmarkGroup: (bookmarkGroup: LabeledBookmarkList, customName: String?, customDesc: String?) -> Unit,