diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/model/nip51Lists/labeledBookmarkLists/LabeledBookmarkListsState.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/model/nip51Lists/labeledBookmarkLists/LabeledBookmarkListsState.kt index 48d7099fb..bac6be565 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/model/nip51Lists/labeledBookmarkLists/LabeledBookmarkListsState.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/model/nip51Lists/labeledBookmarkLists/LabeledBookmarkListsState.kt @@ -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, diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/navigation/routes/Routes.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/navigation/routes/Routes.kt index c69ce89c5..827825f70 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/navigation/routes/Routes.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/navigation/routes/Routes.kt @@ -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() diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/bookmarkgroups/list/ListOfBookmarkGroupsFeedView.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/bookmarkgroups/list/ListOfBookmarkGroupsFeedView.kt index 3ae22735a..2621d06d7 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/bookmarkgroups/list/ListOfBookmarkGroupsFeedView.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/bookmarkgroups/list/ListOfBookmarkGroupsFeedView.kt @@ -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>, - 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) }, diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/bookmarkgroups/list/ListOfBookmarkGroupsScreen.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/bookmarkgroups/list/ListOfBookmarkGroupsScreen.kt index 7b892549f..131a860e0 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/bookmarkgroups/list/ListOfBookmarkGroupsScreen.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/bookmarkgroups/list/ListOfBookmarkGroupsScreen.kt @@ -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>, 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,