Skip to content

Commit

Permalink
Added a Header + Preview Data
Browse files Browse the repository at this point in the history
  • Loading branch information
Rahkeen committed Jul 15, 2024
1 parent 2ac6d92 commit 55a3642
Showing 1 changed file with 66 additions and 16 deletions.
Original file line number Diff line number Diff line change
@@ -1,11 +1,22 @@
package com.emergetools.hackernews.features.bookmarks

import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxSize
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.MaterialTheme
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import com.emergetools.hackernews.features.comments.CommentsDestinations
import com.emergetools.hackernews.features.stories.StoriesDestinations
import com.emergetools.hackernews.features.stories.StoryItem
import com.emergetools.hackernews.features.stories.StoryRow
import com.emergetools.hackernews.ui.theme.HackerNewsTheme

Expand All @@ -15,32 +26,71 @@ fun BookmarksScreen(
actions: (BookmarksAction) -> Unit,
navigator: (BookmarksNavigation) -> Unit,
) {
LazyColumn {
items(items = state.bookmarks, key = { it.id }) { item ->
StoryRow(
item = item,
onClick = {
if (it.url != null){
navigator(BookmarksNavigation.GoToStory(StoriesDestinations.Closeup(it.url)))
} else {
Column(
modifier = Modifier
.fillMaxSize()
.background(color = MaterialTheme.colorScheme.background),
verticalArrangement = Arrangement.spacedBy(8.dp)
) {
Text(
text = "Bookmarks",
modifier = Modifier
.fillMaxWidth()
.padding(8.dp),
style = MaterialTheme.typography.titleMedium
)
LazyColumn {
items(items = state.bookmarks, key = { it.id }) { item ->
StoryRow(
item = item,
onClick = {
if (it.url != null){
navigator(BookmarksNavigation.GoToStory(StoriesDestinations.Closeup(it.url)))
} else {
navigator(BookmarksNavigation.GoToComments(CommentsDestinations.Comments(it.id)))
}
},
onBookmark = { actions(BookmarksAction.RemoveBookmark(it)) },
onCommentClicked = {
navigator(BookmarksNavigation.GoToComments(CommentsDestinations.Comments(it.id)))
}
},
onBookmark = { actions(BookmarksAction.RemoveBookmark(it)) },
onCommentClicked = {
navigator(BookmarksNavigation.GoToComments(CommentsDestinations.Comments(it.id)))
}
)
)
}
}
}
}

@Preview
@Composable
private fun BookmarksScreenPreview() {
fun BookmarksScreenPreview() {
HackerNewsTheme {
BookmarksScreen(
state = BookmarksState(),
state = BookmarksState(
bookmarks = listOf(
StoryItem.Content(
id = 1L,
title = "Hello There",
author = "newuser",
score = 10,
commentCount = 0,
epochTimestamp = 100L,
timeLabel = "2h ago",
bookmarked = true,
url = ""
),
StoryItem.Content(
id = 2L,
title = "Show HN: A new Android client",
author = "heyrikin",
score = 10,
commentCount = 45,
epochTimestamp = 100L,
timeLabel = "3h ago",
bookmarked = true,
url = ""
),
)
),
actions = {},
navigator = {}
)
Expand Down

0 comments on commit 55a3642

Please sign in to comment.