diff --git a/composeApp/src/commonMain/kotlin/in/procyk/shin/ui/ShortenResponse.kt b/composeApp/src/commonMain/kotlin/in/procyk/shin/ui/ShortenResponse.kt index a6a9411..b6f9034 100644 --- a/composeApp/src/commonMain/kotlin/in/procyk/shin/ui/ShortenResponse.kt +++ b/composeApp/src/commonMain/kotlin/in/procyk/shin/ui/ShortenResponse.kt @@ -8,7 +8,6 @@ import androidx.compose.foundation.interaction.MutableInteractionSource import androidx.compose.foundation.interaction.collectIsHoveredAsState import androidx.compose.foundation.layout.* import androidx.compose.foundation.text.ClickableText -import androidx.compose.material3.Button import androidx.compose.material3.MaterialTheme import androidx.compose.material3.OutlinedButton import androidx.compose.material3.Text @@ -28,41 +27,42 @@ import androidx.compose.ui.unit.sp import applyIf @Composable -internal fun ShortenResponse(shortenedUrl: String?) { +internal fun ShortenResponse( + shortenedUrl: String?, +) { AnimatedVisibility( visible = shortenedUrl != null, enter = expandVertically(expandFrom = Alignment.Top), exit = shrinkVertically(shrinkTowards = Alignment.Top), ) { - shortenedUrl?.let { + shortenedUrl?.let { url -> Column( horizontalAlignment = Alignment.CenterHorizontally, verticalArrangement = Arrangement.spacedBy(16.dp, alignment = Alignment.CenterVertically) ) { - val uri by remember(it) { mutableStateOf(it.normalizeAsHttpUrl()) } Spacer(Modifier.height(16.dp)) val color = MaterialTheme.colorScheme.primary - val annotatedString = remember(uri, color) { + val annotatedString = remember(url, color) { buildAnnotatedString { - append(uri) + append(url) addStyle( style = SpanStyle( color = color, fontSize = 18.sp, ), start = 0, - end = uri.length, + end = url.length, ) addStyle( style = ParagraphStyle(textAlign = TextAlign.Center), start = 0, - end = uri.length, + end = url.length, ) addStringAnnotation( tag = URL_TAG, - annotation = uri, + annotation = url, start = 0, - end = uri.length + end = url.length ) } } @@ -81,15 +81,15 @@ internal fun ShortenResponse(shortenedUrl: String?) { .getStringAnnotations(URL_TAG, position, position) .single() .let { - clipboardManager.setText(AnnotatedString(uri)) - localUriHandler.openUri(uri) + clipboardManager.setText(AnnotatedString(url)) + localUriHandler.openUri(url) } } ) Spacer(Modifier.height(16.dp)) - QrCode(uri) + QrCode(url) OutlinedButton( - onClick = { clipboardManager.setText(AnnotatedString(uri)) }, + onClick = { clipboardManager.setText(AnnotatedString(url)) }, ) { Text("Copy to Clipboard") } @@ -99,6 +99,4 @@ internal fun ShortenResponse(shortenedUrl: String?) { } } -private fun String.normalizeAsHttpUrl() = applyIf(!contains("://")) { "http://$this" } - private const val URL_TAG: String = "SHORT_URL_TAG" diff --git a/server/src/main/kotlin/in/procyk/shin/Routes.kt b/server/src/main/kotlin/in/procyk/shin/Routes.kt index cf12ff8..fc40fe5 100644 --- a/server/src/main/kotlin/in/procyk/shin/Routes.kt +++ b/server/src/main/kotlin/in/procyk/shin/Routes.kt @@ -19,7 +19,7 @@ internal fun Application.installRoutes(): Routing = routing { val redirectBaseUrl = dotenv.env("REDIRECT_BASE_URL") post { val shortId = service.findOrCreateShortenedId(it.url) - if (shortId != null) call.respond(HttpStatusCode.OK, "$redirectBaseUrl$shortId") + if (shortId != null) call.respond(HttpStatusCode.OK, "https://$redirectBaseUrl$shortId") else call.respond(HttpStatusCode.BadRequest) } get {