Skip to content

Commit

Permalink
feat: create simple event card for previous event
Browse files Browse the repository at this point in the history
  • Loading branch information
isfaaghyth committed Aug 26, 2024
1 parent 803e682 commit f1d0009
Show file tree
Hide file tree
Showing 14 changed files with 206 additions and 76 deletions.
2 changes: 1 addition & 1 deletion app/src/commonMain/kotlin/id/gdg/app/AppViewModel.kt
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ class AppViewModel(
_upcomingEvent,
_previousEvents
) { upcoming, previous ->
ChapterUiModel(upcoming, previous)
ChapterUiModel(upcoming, previous, true)
}.stateIn(
viewModelScope,
SharingStarted.WhileSubscribed(5_000),
Expand Down
6 changes: 3 additions & 3 deletions app/src/commonMain/kotlin/id/gdg/app/ui/AppContent.kt
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,9 @@ fun AppContent(
private fun NavHostController.navigateTo(from: AppRouter? = null, to: AppRouter) {
navigate(to.route) {
if (from != null) {
popUpTo(from.route) {
inclusive = true
}
// popUpTo(from.route) {
// inclusive = true
// }
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,9 @@ import id.gdg.app.ui.AppEvent
fun EventDetailScreen(viewModel: AppViewModel, eventId: String) {
val eventDetailUiState by viewModel.eventDetailUiState.collectAsState()

LaunchedEffect(Unit) {
if (eventId.isNotEmpty()) {
viewModel.sendEvent(AppEvent.EventDetail(eventId.toInt()))
}
LaunchedEffect(eventId) {
if (eventId.isEmpty()) return@LaunchedEffect
viewModel.sendEvent(AppEvent.EventDetail(eventId.toInt()))
}

Box {
Expand Down
19 changes: 7 additions & 12 deletions app/src/commonMain/kotlin/id/gdg/app/ui/screen/MainScreen.kt
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ fun MainScreen(
}
}

LaunchedEffect(Unit) {
LaunchedEffect(!chapterUiState.isInitiated) {
viewModel.sendEvent(AppEvent.InitialContent)
}

Expand All @@ -57,14 +57,14 @@ fun MainScreen(
finishedListener = { fraction -> if (fraction == 1f) hasDetailOpened = null }
),
body = {
MainScreenView(
MainScreenContent(
chapterUiState = chapterUiState,
onEventDetailClicked = {
// If the screen size is compact (or mobile device screen size), then
// navigate to detail page with router. Otherwise, render the [panel].
if (windowSizeClazz.widthSizeClass == CommonWindowWidthSizeClass.Compact) {
navigateToDetailScreen(it)
return@MainScreenView
return@MainScreenContent
}

selectedEventId = it
Expand All @@ -90,26 +90,21 @@ fun MainScreen(
}

@Composable
fun MainScreenView(
fun MainScreenContent(
chapterUiState: ChapterUiModel,
onEventDetailClicked: (String) -> Unit,
onRefreshPreviousContentClicked: () -> Unit
) {
Column {
UpcomingEventContent(chapterUiState.upcomingEvent)

Button(
onClick = {
onEventDetailClicked("60014")
}
) {
Text("Show Detail")
}

PreviousEventContent(
data = chapterUiState.previousEvents,
onRefreshContent = {
onRefreshPreviousContentClicked()
},
onEventClicked = {
onEventDetailClicked(it)
}
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,28 @@ package id.gdg.app.ui.screen.content
import androidx.compose.animation.AnimatedVisibility
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.items
import androidx.compose.material3.Button
import androidx.compose.material3.CircularProgressIndicator
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.unit.dp
import id.gdg.app.ui.screen.uimodel.toEventContent
import id.gdg.app.ui.state.partial.PreviousEventsUiModel
import id.gdg.ui.component.EventContent
import id.gdg.ui.component.EventSimpleCard

@Composable
fun PreviousEventContent(
data: PreviousEventsUiModel,
onRefreshContent: () -> Unit,
onEventClicked: (String) -> Unit,
) {
Box {
AnimatedVisibility(data.state.isLoading) {
Expand All @@ -21,7 +33,22 @@ fun PreviousEventContent(

when {
data.state.isSuccess -> {
Text(text = "${data.previousEvents}")
LazyColumn(
modifier = Modifier
.fillMaxWidth(),
) {
item {
Text(
text = "Previous Events",
style = MaterialTheme.typography.titleMedium,
fontWeight = FontWeight.SemiBold
)
}

items(data.previousEvents.map { it.toEventContent() }) {
EventSimpleCard(it) { onEventClicked(it) }
}
}
}
data.state.isFail -> {
Row {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package id.gdg.app.ui.screen.uimodel

import id.gdg.event.model.EventModel
import id.gdg.ui.component.EventContent

fun EventModel.toEventContent(): EventContent {
return EventContent(
id = "$id",
bannerUrl = eventImageUrl,
eventName = title,
date = startDate,
type = audienceType
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,15 @@ import id.gdg.app.ui.state.partial.UpcomingEventUiModel

data class ChapterUiModel(
val upcomingEvent: UpcomingEventUiModel,
val previousEvents: PreviousEventsUiModel
val previousEvents: PreviousEventsUiModel,
val isInitiated: Boolean
) {

companion object {
val Default get() = ChapterUiModel(
upcomingEvent = UpcomingEventUiModel.Empty,
previousEvents = PreviousEventsUiModel.Empty
previousEvents = PreviousEventsUiModel.Empty,
isInitiated = false
)
}
}
1 change: 1 addition & 0 deletions gdg-events/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ kotlin {
implementation(project(":gdg-network"))

implementation(libs.kotlin.serialization.json)
implementation(libs.kotlin.datetime)
implementation(libs.common.koin)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,12 @@ data class EventDetail(
@SerialName("allows_cohosting")
val allowsCohosting: Boolean,

@SerialName("attendee_virtual_venue_link")
val attendeeVirtualVenueLink: String,

@SerialName("audience_type")
val audienceType: String,

@SerialName("banner")
val banner: Banner,

@SerialName("banner_crop_vertical")
val bannerCropVertical: Int,

@SerialName("chapter")
val chapter: Chapter,

Expand Down Expand Up @@ -205,23 +199,20 @@ data class EventDetail(
val useFeaturedAttendees: Boolean,

@SerialName("venue_address")
val venueAddress: String,
val venueAddress: String? = "",

@SerialName("venue_city")
val venueCity: String,
val venueCity: String? = "",

@SerialName("venue_name")
val venueName: String,
val venueName: String? = "",

@SerialName("venue_zip_code")
val venueZipCode: String,
val venueZipCode: String? = "",

@SerialName("video_url")
val videoUrl: String?,

@SerialName("virtual_event_type")
val virtualEventType: String,

@SerialName("visible_on_parent_chapter_only")
val visibleOnParentChapterOnly: Boolean
) {
Expand Down Expand Up @@ -457,45 +448,6 @@ data class EventDetail(
@SerialName("id")
val id: Int,

@SerialName("is_for_sale")
val isForSale: Boolean,

@SerialName("max_per_order")
val maxPerOrder: Int,

@SerialName("min_per_order")
val minPerOrder: Int,

@SerialName("price")
val price: Int,

@SerialName("reported_fees")
val reportedFees: Int,

@SerialName("reported_original_price")
val reportedOriginalPrice: Int,

@SerialName("reported_price")
val reportedPrice: Int,

@SerialName("sale_end_date")
val saleEndDate: String,

@SerialName("sale_end_date_derived_from_event_end")
val saleEndDateDerivedFromEventEnd: Boolean,

@SerialName("sale_end_date_naive")
val saleEndDateNaive: String,

@SerialName("sale_start_date")
val saleStartDate: String,

@SerialName("sale_start_date_derived_from_event_publish")
val saleStartDateDerivedFromEventPublish: Boolean,

@SerialName("sale_start_date_naive")
val saleStartDateNaive: String,

@SerialName("title")
val title: String,

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import id.gdg.event.data.entity.EventDetail
import id.gdg.event.data.entity.Events.Event
import id.gdg.event.model.EventDetailModel
import id.gdg.event.model.EventModel
import kotlinx.datetime.Clock
import kotlinx.datetime.Instant

fun List<Event>.toEventModels(): List<EventModel> {
return map { it.toEventModel() }
Expand All @@ -16,11 +18,29 @@ fun Event.toEventModel(): EventModel {
chapterTitle = chapterTitle,
descriptionShort = descriptionShort,
eventImageUrl = picture,
startDate = startDate,
startDate = formatDate(startDate),
timezoneAbbreviation = timezoneAbbreviation,
audienceType = audienceType.lowercase()
)
}

fun EventDetail.toEventDetailModel(): EventDetailModel {
return EventDetailModel(title)
}

internal fun formatDate(dateString: String): String {
val date = Instant.parse(dateString)
val now = Clock.System.now()

val duration = now - date
val days = duration.inWholeDays
val months = (days / 30).toInt() // Approximate months
val years = (days / 365).toInt() // Approximate years

return when {
years > 0 -> "$years year${if (years > 1) "s" else ""} ago"
months > 0 -> "$months month${if (months > 1) "s" else ""} ago"
days > 0 -> "$days day${if (days > 1) "s" else ""} ago"
else -> "today"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ data class EventModel(
val eventImageUrl: String,
val startDate: String,
val timezoneAbbreviation: String,
val audienceType: String
)
2 changes: 2 additions & 0 deletions gdg-ui/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ kotlin {
implementation(libs.androidx.compose.windowsizeclass)
}
commonMain.dependencies {
api(libs.util.qdsfdhvh.image.loader)

implementation(compose.runtime)
implementation(compose.foundation)
implementation(compose.ui)
Expand Down
Loading

0 comments on commit f1d0009

Please sign in to comment.