Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't create uncategorized group if no category exists - Fix #92 #99

Merged
merged 1 commit into from
Dec 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import androidx.compose.ui.unit.dp
import androidx.lifecycle.compose.collectAsStateWithLifecycle
import com.prof18.feedflow.core.model.CategoryId
import com.prof18.feedflow.core.model.FeedSource
import com.prof18.feedflow.core.model.FeedSourceState
import com.prof18.feedflow.core.model.FeedSourceListState
import com.prof18.feedflow.presentation.FeedSourceListViewModel
import com.prof18.feedflow.presentation.preview.feedSourcesState
import com.prof18.feedflow.ui.components.FeedSourceLogoImage
Expand Down Expand Up @@ -44,7 +44,7 @@ fun FeedSourceListScreen(

@Composable
private fun FeedSourceListContent(
feedSources: List<FeedSourceState>,
feedSources: FeedSourceListState,
onAddFeedSourceClick: () -> Unit,
onDeleteFeedSourceClick: (FeedSource) -> Unit,
navigateBack: () -> Unit,
Expand Down Expand Up @@ -87,7 +87,10 @@ private fun FeedSourceListContent(
private fun FeedSourceListContentPreview() {
FeedFlowTheme {
FeedSourceListContent(
feedSources = feedSourcesState,
feedSources = FeedSourceListState(
feedSourcesWithoutCategory = emptyList(),
feedSourcesWithCategory = feedSourcesState,
),
onAddFeedSourceClick = { },
onDeleteFeedSourceClick = {},
navigateBack = {},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@ package com.prof18.feedflow.core.model
import com.prof18.feedflow.core.model.DrawerItem.DrawerFeedSource.FeedSourceCategoryWrapper

data class NavDrawerState(
val timeline: List<DrawerItem> = listOf(),
val categories: List<DrawerItem> = listOf(),
val timeline: List<DrawerItem> = emptyList(),
val categories: List<DrawerItem> = emptyList(),
val feedSourcesWithoutCategory: List<DrawerItem> = emptyList(),
val feedSourcesByCategory: Map<FeedSourceCategoryWrapper, List<DrawerItem>> = mapOf(),
) {
fun isEmpty(): Boolean =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,11 @@ data class FeedSourceState(
val isExpanded: Boolean = false,
val feedSources: List<FeedSource>,
)

data class FeedSourceListState(
val feedSourcesWithoutCategory: List<FeedSource> = emptyList(),
val feedSourcesWithCategory: List<FeedSourceState> = emptyList(),
) {
fun isEmpty(): Boolean =
feedSourcesWithoutCategory.isEmpty() && feedSourcesWithCategory.isEmpty()
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import com.prof18.feedflow.MR
import com.prof18.feedflow.addfeed.AddFeedScreen
import com.prof18.feedflow.core.model.CategoryId
import com.prof18.feedflow.core.model.FeedSource
import com.prof18.feedflow.core.model.FeedSourceState
import com.prof18.feedflow.core.model.FeedSourceListState
import com.prof18.feedflow.desktopViewModel
import com.prof18.feedflow.di.DI
import com.prof18.feedflow.presentation.FeedSourceListViewModel
Expand Down Expand Up @@ -52,7 +52,7 @@ fun FeedSourceListScreen(
val feedSources by viewModel.feedSourcesState.collectAsState()

FeedSourceListContent(
feedSources = feedSources,
feedSourceListState = feedSources,
onAddFeedClick = {
dialogState = true
},
Expand All @@ -69,7 +69,7 @@ fun FeedSourceListScreen(

@Composable
private fun FeedSourceListContent(
feedSources: List<FeedSourceState>,
feedSourceListState: FeedSourceListState,
onAddFeedClick: () -> Unit,
onDeleteFeedClick: (FeedSource) -> Unit,
navigateBack: () -> Unit,
Expand All @@ -83,7 +83,7 @@ private fun FeedSourceListContent(
)
},
) { paddingValues ->
if (feedSources.isEmpty()) {
if (feedSourceListState.isEmpty()) {
NoFeedSourcesView(
modifier = Modifier
.padding(paddingValues)
Expand All @@ -93,7 +93,7 @@ private fun FeedSourceListContent(
FeedSourcesWithCategoryList(
modifier = Modifier
.padding(paddingValues),
feedSourceState = feedSources,
feedSourceState = feedSourceListState,
onExpandClicked = onExpandClicked,
feedSourceImage = { imageUrl ->
FeedSourceLogoImage(
Expand All @@ -112,7 +112,10 @@ private fun FeedSourceListContent(
private fun FeedSourceListContentPreview() {
FeedFlowTheme {
FeedSourceListContent(
feedSources = feedSourcesState,
feedSourceListState = FeedSourceListState(
feedSourcesWithoutCategory = emptyList(),
feedSourcesWithCategory = feedSourcesState,
),
onAddFeedClick = {},
onDeleteFeedClick = {},
onExpandClicked = {},
Expand All @@ -128,7 +131,10 @@ private fun FeedSourceListContentDarkPreview() {
darkTheme = true,
) {
FeedSourceListContent(
feedSources = feedSourcesState,
feedSourceListState = FeedSourceListState(
feedSourcesWithoutCategory = emptyList(),
feedSourcesWithCategory = feedSourcesState,
),
onAddFeedClick = {},
onDeleteFeedClick = {},
onExpandClicked = {},
Expand Down
7 changes: 6 additions & 1 deletion iosApp/Source/App/CompactView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,12 @@ struct CompactView: View {
private var indexHolder = HomeListIndexHolder()

@State
var navDrawerState: NavDrawerState = NavDrawerState(timeline: [], categories: [], feedSourcesByCategory: [:])
var navDrawerState: NavDrawerState = NavDrawerState(
timeline: [],
categories: [],
feedSourcesWithoutCategory: [],
feedSourcesByCategory: [:]
)

@State
var scrollUpTrigger: Bool = false
Expand Down
109 changes: 74 additions & 35 deletions iosApp/Source/App/Drawer/SidebarDrawer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,30 @@ struct SidebarDrawer: View {
)
}

if !navDrawerState.feedSourcesWithoutCategory.isEmpty {
Section(
content: {
ForEach(navDrawerState.feedSourcesWithoutCategory, id: \.self) { drawerItem in
if let drawerFeedSource = drawerItem as? DrawerItem.DrawerFeedSource {
FeedSourceDrawerItem(
feedSource: drawerFeedSource.feedSource,
onClick: {
self.selectedDrawerItem = drawerItem
self.onFeedFilterSelected(
FeedFilter.Source(
feedSource: drawerFeedSource.feedSource
)
)
}
)
}
}
}, header: {
Text(localizer.drawer_title_feed_sources.localized)
}
)
}

if !navDrawerState.feedSourcesByCategory.isEmpty {

Section(
Expand All @@ -69,49 +93,24 @@ struct SidebarDrawer: View {
id: \.self
) { drawerItem in
if let drawerFeedSource = drawerItem as? DrawerItem.DrawerFeedSource {
HStack {

if let imageUrl = drawerFeedSource.feedSource.logoUrl {
LazyImage(url: URL(string: imageUrl)) { state in
if let image = state.image {
image
.resizable()
.scaledToFill()
.frame(width: 24, height: 24)
.cornerRadius(16)
.clipped()
} else {
Image(systemName: "square.stack.3d.up")
}
}
} else {
Image(systemName: "square.stack.3d.up")
FeedSourceDrawerItem(
feedSource: drawerFeedSource.feedSource,
onClick: {
self.selectedDrawerItem = drawerItem
self.onFeedFilterSelected(
FeedFilter.Source(
feedSource: drawerFeedSource.feedSource
)
)
}

Text(drawerFeedSource.feedSource.title)
.lineLimit(2)
.font(.system(size: 16))
.padding(.bottom, 2)
.padding(.leading, Spacing.small)

Spacer()
}
)
.listRowInsets(
EdgeInsets(
top: Spacing.small,
leading: .zero,
bottom: Spacing.small,
trailing: Spacing.small)
)
.contentShape(Rectangle())
.onTapGesture {
self.selectedDrawerItem = drawerItem
self.onFeedFilterSelected(
FeedFilter.Source(
feedSource: drawerFeedSource.feedSource
)
)
}
} else {
EmptyView()
}
Expand Down Expand Up @@ -139,6 +138,46 @@ struct SidebarDrawer: View {
}
}

struct FeedSourceDrawerItem: View {

let feedSource: FeedSource
let onClick: () -> Void

var body: some View {
HStack {
if let imageUrl = feedSource.logoUrl {
LazyImage(url: URL(string: imageUrl)) { state in
if let image = state.image {
image
.resizable()
.scaledToFill()
.frame(width: 24, height: 24)
.cornerRadius(16)
.clipped()
} else {
Image(systemName: "square.stack.3d.up")
}
}
} else {
Image(systemName: "square.stack.3d.up")
}

Text(feedSource.title)
.lineLimit(2)
.font(.system(size: 16))
.padding(.bottom, 2)
.padding(.leading, Spacing.small)

Spacer()
}

.contentShape(Rectangle())
.onTapGesture {
onClick()
}
}
}

private struct DrawerTimelineItem: View {
var body: some View {
HStack {
Expand Down
7 changes: 6 additions & 1 deletion iosApp/Source/App/RegularView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,12 @@ struct RegularView: View {
var selectedDrawerItem: DrawerItem?

@State
var navDrawerState: NavDrawerState = NavDrawerState(timeline: [], categories: [], feedSourcesByCategory: [:])
var navDrawerState: NavDrawerState = NavDrawerState(
timeline: [],
categories: [],
feedSourcesWithoutCategory: [],
feedSourcesByCategory: [:]
)

@State
var scrollUpTrigger: Bool = false
Expand Down
Loading