Skip to content

Commit

Permalink
Includes the product in the first message of the marketplace.
Browse files Browse the repository at this point in the history
  • Loading branch information
vitorpamplona committed Feb 1, 2024
1 parent 34d373c commit 54155a3
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ import com.vitorpamplona.amethyst.ui.screen.loggedIn.VideoScreen
import com.vitorpamplona.amethyst.ui.uriToRoute
import kotlinx.coroutines.delay
import kotlinx.coroutines.launch
import java.net.URLDecoder

@Composable
fun AppNavigation(
Expand Down Expand Up @@ -288,9 +289,13 @@ fun AppNavigation(
route.route,
route.arguments,
content = {
val decodedMessage =
it.arguments?.getString("message")?.let {
URLDecoder.decode(it, "utf-8")
}
ChatroomScreen(
roomId = it.arguments?.getString("id"),
draftMessage = it.arguments?.getString("message"),
draftMessage = decodedMessage,
accountViewModel = accountViewModel,
nav = nav,
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,8 @@ fun routeToMessage(
val withKey = ChatroomKey(persistentSetOf(user))
accountViewModel.account.userProfile().createChatroom(withKey)
return if (draftMessage != null) {
"Room/${withKey.hashCode()}?message=$draftMessage"
val encodedMessage = URLEncoder.encode(draftMessage, "utf-8")
"Room/${withKey.hashCode()}?message=$encodedMessage"
} else {
"Room/${withKey.hashCode()}"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ import androidx.compose.runtime.getValue
import androidx.compose.runtime.livedata.observeAsState
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
Expand Down Expand Up @@ -284,26 +285,27 @@ fun Modifier.drawReplyLevel(
color: Color,
selected: Color,
): Modifier =
this.drawBehind {
val paddingDp = 2
val strokeWidthDp = 2
val levelWidthDp = strokeWidthDp + 1

val padding = paddingDp.dp.toPx()
val strokeWidth = strokeWidthDp.dp.toPx()
val levelWidth = levelWidthDp.dp.toPx()

repeat(level) {
this.drawLine(
if (it == level - 1) selected else color,
Offset(padding + it * levelWidth, 0f),
Offset(padding + it * levelWidth, size.height),
strokeWidth = strokeWidth,
)
}
this
.drawBehind {
val paddingDp = 2
val strokeWidthDp = 2
val levelWidthDp = strokeWidthDp + 1

val padding = paddingDp.dp.toPx()
val strokeWidth = strokeWidthDp.dp.toPx()
val levelWidth = levelWidthDp.dp.toPx()

repeat(level) {
this.drawLine(
if (it == level - 1) selected else color,
Offset(padding + it * levelWidth, 0f),
Offset(padding + it * levelWidth, size.height),
strokeWidth = strokeWidth,
)
}

return@drawBehind
}
return@drawBehind
}
.padding(start = (2 + (level * 3)).dp)

@OptIn(ExperimentalFoundationApi::class)
Expand Down Expand Up @@ -353,11 +355,14 @@ fun NoteMaster(
)
} else {
Column(
modifier.fillMaxWidth().padding(top = 10.dp),
modifier
.fillMaxWidth()
.padding(top = 10.dp),
) {
Row(
modifier =
Modifier.padding(start = 12.dp, end = 12.dp)
Modifier
.padding(start = 12.dp, end = 12.dp)
.clickable(onClick = { note.author?.let { nav("User/${it.pubkeyHex}") } }),
) {
NoteAuthorPicture(
Expand Down Expand Up @@ -443,7 +448,8 @@ fun NoteMaster(

Row(
modifier =
Modifier.padding(horizontal = 12.dp)
Modifier
.padding(horizontal = 12.dp)
.combinedClickable(
onClick = {},
onLongClick = { popupExpanded = true },
Expand Down Expand Up @@ -669,7 +675,9 @@ private fun RenderClassifiedsReaderForThread(
}

Row(
Modifier.padding(start = 20.dp, end = 20.dp, bottom = 5.dp, top = 15.dp).fillMaxWidth(),
Modifier
.padding(start = 20.dp, end = 20.dp, bottom = 5.dp, top = 15.dp)
.fillMaxWidth(),
verticalAlignment = Alignment.CenterVertically,
) {
Icon(
Expand All @@ -686,7 +694,9 @@ private fun RenderClassifiedsReaderForThread(

Row(
modifier =
Modifier.padding(start = 10.dp, end = 10.dp, bottom = 5.dp, top = 5.dp).fillMaxWidth(),
Modifier
.padding(start = 10.dp, end = 10.dp, bottom = 5.dp, top = 5.dp)
.fillMaxWidth(),
horizontalArrangement = Arrangement.SpaceBetween,
verticalAlignment = Alignment.CenterVertically,
) {
Expand All @@ -703,6 +713,7 @@ private fun RenderClassifiedsReaderForThread(
}

var message by remember { mutableStateOf(TextFieldValue(msg)) }
val scope = rememberCoroutineScope()

TextField(
value = message,
Expand All @@ -725,7 +736,11 @@ private fun RenderClassifiedsReaderForThread(
isActive = message.text.isNotBlank(),
modifier = EditFieldTrailingIconModifier,
) {
note.author?.let { nav(routeToMessage(it, msg, accountViewModel)) }
scope.launch(Dispatchers.IO) {
note.author?.let {
nav(routeToMessage(it, note.toNostrUri() + "\n\n" + msg, accountViewModel))
}
}
}
},
colors =
Expand Down

0 comments on commit 54155a3

Please sign in to comment.