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