Fixed rendering of calendar event previews

This commit is contained in:
Vitor Pamplona
2026-03-10 08:43:59 -04:00
parent 9c8bac7b0b
commit 9ca5fc0496
@@ -37,12 +37,15 @@ import androidx.compose.ui.text.style.TextOverflow
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import com.vitorpamplona.amethyst.R
import com.vitorpamplona.amethyst.model.LocalCache
import com.vitorpamplona.amethyst.model.Note
import com.vitorpamplona.amethyst.ui.components.MyAsyncImage
import com.vitorpamplona.amethyst.ui.navigation.navs.EmptyNav
import com.vitorpamplona.amethyst.ui.navigation.navs.INav
import com.vitorpamplona.amethyst.ui.note.elements.DefaultImageHeader
import com.vitorpamplona.amethyst.ui.note.elements.DefaultImageHeaderBackground
import com.vitorpamplona.amethyst.ui.screen.loggedIn.AccountViewModel
import com.vitorpamplona.amethyst.ui.screen.loggedIn.mockAccountViewModel
import com.vitorpamplona.amethyst.ui.stringRes
import com.vitorpamplona.amethyst.ui.theme.StdVertSpacer
import com.vitorpamplona.amethyst.ui.theme.ThemeComparisonColumn
@@ -52,7 +55,6 @@ import com.vitorpamplona.quartz.nip52Calendar.appt.time.CalendarTimeSlotEvent
import java.text.DateFormat
import java.text.SimpleDateFormat
import java.util.Date
import java.util.Locale
@Composable
fun RenderCalendarTimeSlotEvent(
@@ -64,15 +66,17 @@ fun RenderCalendarTimeSlotEvent(
val title = noteEvent.title()
val image = noteEvent.image()
val summary = remember(noteEvent) {
noteEvent.summary()?.ifBlank { null } ?: noteEvent.content.take(200).ifBlank { null }
}
val summary =
remember(noteEvent) {
noteEvent.summary()?.ifBlank { null } ?: noteEvent.content.take(200).ifBlank { null }
}
val location = noteEvent.location()
val dateRange = remember(noteEvent) {
val start = noteEvent.start()
val end = noteEvent.end()
formatTimestampRange(start, end)
}
val dateRange =
remember(noteEvent) {
val start = noteEvent.start()
val end = noteEvent.end()
formatTimestampRange(start, end)
}
CalendarHeader(
title = title,
@@ -95,15 +99,17 @@ fun RenderCalendarDateSlotEvent(
val title = noteEvent.title()
val image = noteEvent.image()
val summary = remember(noteEvent) {
noteEvent.summary()?.ifBlank { null } ?: noteEvent.content.take(200).ifBlank { null }
}
val summary =
remember(noteEvent) {
noteEvent.summary()?.ifBlank { null } ?: noteEvent.content.take(200).ifBlank { null }
}
val location = noteEvent.location()
val dateRange = remember(noteEvent) {
val start = noteEvent.start()
val end = noteEvent.end()
formatDateRange(start, end)
}
val dateRange =
remember(noteEvent) {
val start = noteEvent.start()
val end = noteEvent.end()
formatDateRange(start, end)
}
CalendarHeader(
title = title,
@@ -147,9 +153,10 @@ private fun CalendarHeader(
text = it,
style = MaterialTheme.typography.bodyLarge,
fontWeight = FontWeight.Bold,
modifier = Modifier
.fillMaxWidth()
.padding(start = 10.dp, end = 10.dp, top = 10.dp),
modifier =
Modifier
.fillMaxWidth()
.padding(start = 10.dp, end = 10.dp, top = 10.dp),
maxLines = 2,
overflow = TextOverflow.Ellipsis,
)
@@ -189,9 +196,10 @@ private fun CalendarHeader(
Text(
text = it,
style = MaterialTheme.typography.bodySmall,
modifier = Modifier
.fillMaxWidth()
.padding(start = 10.dp, end = 10.dp, bottom = 10.dp),
modifier =
Modifier
.fillMaxWidth()
.padding(start = 10.dp, end = 10.dp, bottom = 10.dp),
color = Color.Gray,
maxLines = 3,
overflow = TextOverflow.Ellipsis,
@@ -234,13 +242,49 @@ private fun formatDateRange(
@Composable
@Preview
fun RenderCalendarTimeSlotEventPreview() {
val event =
CalendarTimeSlotEvent(
id = "0c22faa881c52f32754e6f2f7188a1333388acf4bfb32ecc04edb48f3cf4fd5d",
pubKey = "c07b08396b7bffdb659f862dd7ead57ae169caea65ed573d161e13c1cd6d490c",
createdAt = 1773145949,
tags =
arrayOf(
arrayOf("d", "2cc67b34-f8c9-4bb2-aa80-df38d2c16903"),
arrayOf("t", "Meetup"),
arrayOf("r", ""),
arrayOf("title", "Bodø Bitcoin Meet -up!"),
arrayOf("image", "https://cdn.satlantis.io/1cpasswtt00lakevlscka06k40tsknjh2vhk4w0gkrcfurntdfyxqu6qges-1769516859659-ChatGPT%20Image%2027.%20jan.%202026%2C%2013_27_28.png"),
arrayOf("start", "1775671200"),
arrayOf("end", "1775674800"),
arrayOf("start_tzid", "Europe/Oslo"),
arrayOf("g", ""),
arrayOf("summary", "Bitcoin is for everyone — whether youre just curious, stacking sats for the first time, or youve been around since the early days.\n\nThis meetup is an open and informal gathering for anyone interested in Bitcoin. Theres no strict agenda, no pressure, and no expectations. Just good conversations, shared curiosity, and a chance to meet like-minded people in Bodø.\n\nWho is this for?\n\nNew to Bitcoin and want to learn the basics\n\nLong-time Bitcoiners (OGs very welcome)\n\nBuilders, investors, students, professionals, skeptics, and the simply curious\n\nAnyone who wants to understand why Bitcoin matters\n\nWell talk Bitcoin at whatever level feels natural — from fundamentals and real-world use cases to philosophy, technology, and current developments.\n\nDuring the meetup, Ill also announce and briefly share details about the upcoming Bitcoin conference in Bodø on 14 August, bringing international and Nordic voices together around Bitcoin.\n\n📍 Location: Bodø, Bjørk\n🕒 Time: 20.00\n🍻 Format: Casual, social, open discussion\n\nCome as you are. Bring questions, ideas, or just yourself.\nEveryone is welcome."),
arrayOf("url", ""),
arrayOf("cohosts", "172100"),
arrayOf("calendar_event_tags", "education, meet-up, bitcoin, networking, fun"),
arrayOf("website", ""),
arrayOf("autoFollowHosts", "false"),
arrayOf("rsvp_gated_enabled", "false"),
arrayOf("allowCohostsToDownloadAttendeeList", "false"),
arrayOf("venue", "167911"),
arrayOf("location", "Storgata 8, 8006 Bodø, Norway"),
arrayOf("googleMapsUri", "https://maps.google.com/?cid=601501172909304252&g_mp=CiVnb29nbGUubWFwcy5wbGFjZXMudjEuUGxhY2VzLkdldFBsYWNlEAIYBCAA"),
arrayOf("venue_name", "Restaurant Bjørk"),
arrayOf("google_place_id", "ChIJYd5l1F0Q30URvGk9PyH2WAg"),
arrayOf("rsvp_waitlist_enabled", "false"),
),
content = "Bitcoin is for everyone — whether youre just curious, stacking sats for the first time, or youve been around since the early days.\n\nThis meetup is an open and informal gathering for anyone interested in Bitcoin. Theres no strict agenda, no pressure, and no expectations. Just good conversations, shared curiosity, and a chance to meet like-minded people in Bodø.\n\nWho is this for?\n\nNew to Bitcoin and want to learn the basics\n\nLong-time Bitcoiners (OGs very welcome)\n\nBuilders, investors, students, professionals, skeptics, and the simply curious\n\nAnyone who wants to understand why Bitcoin matters\n\nWell talk Bitcoin at whatever level feels natural — from fundamentals and real-world use cases to philosophy, technology, and current developments.\n\nDuring the meetup, Ill also announce and briefly share details about the upcoming Bitcoin conference in Bodø on 14 August, bringing international and Nordic voices together around Bitcoin.\n\n📍 Location: Bodø, Bjørk\n🕒 Time: 20.00\n🍻 Format: Casual, social, open discussion\n\nCome as you are. Bring questions, ideas, or just yourself.\nEveryone is welcome.",
sig = "a63bdfc5d33432ef6a1454c7b395586430f5602b822ccd07b9d1ccd9608ecda8508b58374bff28ab87d9b9c92c9cd5a7e95bfe67587ccc852e3fea78c0c682c3",
)
LocalCache.justConsume(event, null, true)
val note = LocalCache.getOrCreateNote(event.id)
ThemeComparisonColumn {
CalendarHeader(
title = "Nostr Developer Meetup",
image = null,
summary = "Join us for an evening of lightning talks and open discussion on the latest Nostr protocol developments.",
location = "Berlin, Germany",
dateRange = "Mar 15, 2025, 7:00 PM 10:00 PM",
RenderCalendarTimeSlotEvent(
note,
mockAccountViewModel(),
EmptyNav(),
)
}
}
@@ -248,13 +292,31 @@ fun RenderCalendarTimeSlotEventPreview() {
@Composable
@Preview
fun RenderCalendarDateSlotEventPreview() {
val event =
CalendarDateSlotEvent(
id = "d8d76e5a7786210684317fe0264cc44fdc8147254456c20a9fb99db1c090a37f",
pubKey = "068598899f82af67fc67cfcc44457ed9a8cc686b7d63ab9db969c96c3fe9bffd",
createdAt = 1771952727,
content = "Join the OER Community #qualität #communities #oer #oep",
sig = "6122acb989dbe24780c463d3026c255d0a223221e96ea29331c68b7442a3710460d6886705fe8f9b4fb0c5565f7e6ed9cb5d9b254e5b656926beb56a0d83da47",
tags =
arrayOf(
arrayOf("d", "event-1771952727237-oue85wf9r"),
arrayOf("h", "d6d214fe27fcc0a691dd0f04d152b7cdda7f61f96f26dc421df46af0bb51792e"),
arrayOf("title", "FOERBICO Tagung"),
arrayOf("start", "1771891200"),
arrayOf("end", "1771977600"),
),
)
LocalCache.justConsume(event, null, true)
val note = LocalCache.getOrCreateNote(event.id)
ThemeComparisonColumn {
CalendarHeader(
title = "Bitcoin Conference 2025",
image = null,
summary = null,
location = null,
dateRange = "2025-05-01 2025-05-03",
RenderCalendarDateSlotEvent(
note,
mockAccountViewModel(),
EmptyNav(),
)
}
}