Moves relayToAdd from the Object to a param in the relay screen

This commit is contained in:
Vitor Pamplona
2024-12-09 14:59:35 -05:00
parent 95966e5874
commit 6a787f2774
6 changed files with 39 additions and 39 deletions
@@ -37,7 +37,6 @@ import androidx.compose.material3.Text
import androidx.compose.material3.TopAppBar import androidx.compose.material3.TopAppBar
import androidx.compose.material3.TopAppBarDefaults import androidx.compose.material3.TopAppBarDefaults
import androidx.compose.runtime.Composable import androidx.compose.runtime.Composable
import androidx.compose.runtime.DisposableEffect
import androidx.compose.runtime.LaunchedEffect import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.getValue import androidx.compose.runtime.getValue
import androidx.compose.runtime.setValue import androidx.compose.runtime.setValue
@@ -52,7 +51,6 @@ import com.vitorpamplona.amethyst.R
import com.vitorpamplona.amethyst.model.DefaultDMRelayList import com.vitorpamplona.amethyst.model.DefaultDMRelayList
import com.vitorpamplona.amethyst.model.DefaultSearchRelayList import com.vitorpamplona.amethyst.model.DefaultSearchRelayList
import com.vitorpamplona.amethyst.ui.navigation.INav import com.vitorpamplona.amethyst.ui.navigation.INav
import com.vitorpamplona.amethyst.ui.navigation.rememberExtendedNav
import com.vitorpamplona.amethyst.ui.screen.loggedIn.AccountViewModel import com.vitorpamplona.amethyst.ui.screen.loggedIn.AccountViewModel
import com.vitorpamplona.amethyst.ui.screen.loggedIn.CloseButton import com.vitorpamplona.amethyst.ui.screen.loggedIn.CloseButton
import com.vitorpamplona.amethyst.ui.screen.loggedIn.SaveButton import com.vitorpamplona.amethyst.ui.screen.loggedIn.SaveButton
@@ -65,20 +63,13 @@ import com.vitorpamplona.amethyst.ui.theme.grayText
import com.vitorpamplona.ammolite.relays.Constants import com.vitorpamplona.ammolite.relays.Constants
import com.vitorpamplona.ammolite.relays.RelayStat import com.vitorpamplona.ammolite.relays.RelayStat
object RelayToAdd {
var relayToAdd: String = ""
}
@Composable @Composable
fun AllRelayListView( fun AllRelayListView(
relayToAdd: String? = null,
accountViewModel: AccountViewModel, accountViewModel: AccountViewModel,
nav: INav, nav: INav,
) { ) {
DisposableEffect(Unit) { MappedAllRelayListView(relayToAdd ?: "", accountViewModel, nav)
onDispose { RelayToAdd.relayToAdd = "" }
}
MappedAllRelayListView(RelayToAdd.relayToAdd, accountViewModel, rememberExtendedNav(nav, {}))
} }
@OptIn(ExperimentalMaterial3Api::class) @OptIn(ExperimentalMaterial3Api::class)
@@ -286,6 +286,19 @@ fun AppNavigation(
NIP47SetupScreen(accountViewModel, nav, nip47) NIP47SetupScreen(accountViewModel, nav, nip47)
} }
composable(
Route.EditRelays.route,
content = {
val relayToAdd = it.arguments?.getString("toAdd")
AllRelayListView(
relayToAdd = relayToAdd,
accountViewModel = accountViewModel,
nav = nav,
)
},
)
composable( composable(
Route.NewPost.route, Route.NewPost.route,
Route.NewPost.arguments, Route.NewPost.arguments,
@@ -321,16 +334,6 @@ fun AppNavigation(
nav = nav, nav = nav,
) )
} }
composable(
Route.EditRelays.route,
content = {
AllRelayListView(
accountViewModel = accountViewModel,
nav = nav,
)
},
)
} }
} }
@@ -473,7 +473,7 @@ fun ListContent(
accountViewModel = accountViewModel, accountViewModel = accountViewModel,
onClick = { onClick = {
nav.closeDrawer() nav.closeDrawer()
nav.nav(Route.EditRelays.route) nav.nav(Route.EditRelays.base)
}, },
) )
@@ -68,13 +68,6 @@ sealed class Route(
contentDescriptor = R.string.route_global, contentDescriptor = R.string.route_global,
) )
object EditRelays :
Route(
route = "EditRelays",
icon = R.drawable.ic_globe,
contentDescriptor = R.string.relays,
)
object Search : object Search :
Route( Route(
route = "Search", route = "Search",
@@ -216,6 +209,21 @@ sealed class Route(
icon = R.drawable.ic_settings, icon = R.drawable.ic_settings,
) )
object EditRelays :
Route(
route = "EditRelays?toAdd={toAdd}",
icon = R.drawable.ic_globe,
contentDescriptor = R.string.relays,
arguments =
listOf(
navArgument("toAdd") {
type = NavType.StringType
nullable = true
defaultValue = null
},
).toImmutableList(),
)
object NIP47Setup : object NIP47Setup :
Route( Route(
route = "NIP47Setup?nip47={nip47}", route = "NIP47Setup?nip47={nip47}",
@@ -45,7 +45,6 @@ import androidx.compose.ui.text.style.TextOverflow
import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.dp
import com.vitorpamplona.amethyst.R import com.vitorpamplona.amethyst.R
import com.vitorpamplona.amethyst.model.Note import com.vitorpamplona.amethyst.model.Note
import com.vitorpamplona.amethyst.ui.actions.relays.RelayToAdd
import com.vitorpamplona.amethyst.ui.components.ShowMoreButton import com.vitorpamplona.amethyst.ui.components.ShowMoreButton
import com.vitorpamplona.amethyst.ui.navigation.INav import com.vitorpamplona.amethyst.ui.navigation.INav
import com.vitorpamplona.amethyst.ui.navigation.Route import com.vitorpamplona.amethyst.ui.navigation.Route
@@ -62,6 +61,8 @@ import com.vitorpamplona.quartz.events.SearchRelayListEvent
import kotlinx.collections.immutable.ImmutableList import kotlinx.collections.immutable.ImmutableList
import kotlinx.collections.immutable.persistentListOf import kotlinx.collections.immutable.persistentListOf
import kotlinx.collections.immutable.toImmutableList import kotlinx.collections.immutable.toImmutableList
import java.net.URLEncoder
import java.nio.charset.StandardCharsets
@Composable @Composable
fun DisplayRelaySet( fun DisplayRelaySet(
@@ -292,13 +293,11 @@ private fun RelayOptionsAction(
if (isCurrentlyOnTheUsersList) { if (isCurrentlyOnTheUsersList) {
AddRelayButton { AddRelayButton {
RelayToAdd.relayToAdd = relay nav.nav(Route.EditRelays.base + "?toAdd=" + URLEncoder.encode(relay, StandardCharsets.UTF_8.toString()))
nav.nav(Route.EditRelays.route)
} }
} else { } else {
RemoveRelayButton { RemoveRelayButton {
RelayToAdd.relayToAdd = relay nav.nav(Route.EditRelays.base + "?toAdd=" + URLEncoder.encode(relay, StandardCharsets.UTF_8.toString()))
nav.nav(Route.EditRelays.route)
} }
} }
} }
@@ -28,7 +28,6 @@ import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue import androidx.compose.runtime.getValue
import androidx.compose.runtime.setValue import androidx.compose.runtime.setValue
import androidx.lifecycle.compose.collectAsStateWithLifecycle import androidx.lifecycle.compose.collectAsStateWithLifecycle
import com.vitorpamplona.amethyst.ui.actions.relays.RelayToAdd
import com.vitorpamplona.amethyst.ui.feeds.RefresheableBox import com.vitorpamplona.amethyst.ui.feeds.RefresheableBox
import com.vitorpamplona.amethyst.ui.navigation.INav import com.vitorpamplona.amethyst.ui.navigation.INav
import com.vitorpamplona.amethyst.ui.navigation.Route import com.vitorpamplona.amethyst.ui.navigation.Route
@@ -36,6 +35,8 @@ import com.vitorpamplona.amethyst.ui.note.RelayCompose
import com.vitorpamplona.amethyst.ui.screen.loggedIn.AccountViewModel import com.vitorpamplona.amethyst.ui.screen.loggedIn.AccountViewModel
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
import java.net.URLEncoder
import java.nio.charset.StandardCharsets
@Composable @Composable
fun RelayFeedView( fun RelayFeedView(
@@ -58,12 +59,10 @@ fun RelayFeedView(
item, item,
accountViewModel = accountViewModel, accountViewModel = accountViewModel,
onAddRelay = { onAddRelay = {
RelayToAdd.relayToAdd = item.url nav.nav(Route.EditRelays.base + "?toAdd=" + URLEncoder.encode(item.url, StandardCharsets.UTF_8.toString()))
nav.nav(Route.EditRelays.route)
}, },
onRemoveRelay = { onRemoveRelay = {
RelayToAdd.relayToAdd = item.url nav.nav(Route.EditRelays.base + "?toAdd=" + URLEncoder.encode(item.url, StandardCharsets.UTF_8.toString()))
nav.nav(Route.EditRelays.route)
}, },
) )
HorizontalDivider( HorizontalDivider(