Skip to content

Commit

Permalink
#1899 (dashboard)
Browse files Browse the repository at this point in the history
- Added the Dashboard layout options to Settings for Mac & iPad. (It’ll be added to menus later.)
- Implemented displaying the different Dashboard layouts.
- Implemented hiding the Dashboard in the feeds list.
  • Loading branch information
Dejal committed Dec 31, 2024
1 parent 9b0edad commit 6f5d7c5
Show file tree
Hide file tree
Showing 9 changed files with 124 additions and 18 deletions.
2 changes: 1 addition & 1 deletion clients/ios/Classes/DashList.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import Foundation

/// A list in the Dashboard.
@MainActor class DashList: Identifiable {
@MainActor class DashList: @preconcurrency Identifiable {
var id = UUID()
var index: Int

Expand Down
9 changes: 7 additions & 2 deletions clients/ios/Classes/FeedDetailDashListView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,13 @@ struct DashListStoriesView: View {

var body: some View {
VStack(alignment: .center) {
ForEach(dash.stories) { story in
CardView(feedDetailInteraction: interaction, cache: cache, story: story)
if dash.isLoaded {
ForEach(dash.stories) { story in
CardView(feedDetailInteraction: interaction, cache: cache, story: story)
}
} else {
ProgressView()
.padding([.top, .bottom], 200)
}
}
.font(.custom("WhitneySSm-Medium", size: 14, relativeTo: .body))
Expand Down
47 changes: 37 additions & 10 deletions clients/ios/Classes/FeedDetailDashboardView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,26 +14,53 @@ struct FeedDetailDashboardView: View {

@ObservedObject var cache: StoryCache

var columns: [GridItem] {
return Array(repeating: GridItem(.flexible(), spacing: 20), count: cache.settings.dashboardColumns)
}

var body: some View {
GeometryReader { reader in
ScrollView {
ScrollViewReader { scroller in
LazyVGrid(columns: columns, spacing: 20) {
Section {
ForEach(cache.dashboard, id: \.id) { dash in
makeDashListView(for: dash)
switch cache.settings.dashboardLayout {
case .none:
EmptyView()
case .single:
VStack(alignment: .leading, spacing: 10) {
makeDashSection(for: cache.dashboardLeft)
makeDashSection(for: cache.dashboardRight)
}
case .vertical:
HStack(alignment: .top, spacing: 10) {
VStack(alignment: .leading, spacing: 10) {
makeDashSection(for: cache.dashboardLeft)
}

VStack(alignment: .leading, spacing: 10) {
makeDashSection(for: cache.dashboardRight)
}
}
case .horizontal:
VStack(alignment: .leading, spacing: 10) {
HStack(alignment: .top, spacing: 10) {
makeDashSection(for: cache.dashboardLeft)
}

HStack(alignment: .top, spacing: 10) {
makeDashSection(for: cache.dashboardRight)
}
}
}
}
.padding()
}
}
}
.background(Color.themed([0xE0E0E0, 0xFFF8CA, 0x363636, 0x101010]))
.padding(10)
}

@ViewBuilder
func makeDashSection(for dashes: [DashList]) -> some View {
Section {
ForEach(dashes, id: \.id) { dash in
makeDashListView(for: dash)
}
}
}

@ViewBuilder
Expand Down
5 changes: 5 additions & 0 deletions clients/ios/Classes/FeedsObjCViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -1936,6 +1936,11 @@ - (CGFloat)tableView:(UITableView *)tableView
return 0;
}

if (section == NewsBlurTopSectionDashboard &&
[[prefs stringForKey:@"dashboard_layout"] isEqualToString:@"none"]) {
return 0;
}

if (section == NewsBlurTopSectionInfrequentSiteStories &&
![prefs boolForKey:@"show_infrequent_site_stories"]) {
return 0;
Expand Down
14 changes: 14 additions & 0 deletions clients/ios/Classes/StoryCache.swift
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@ import Foundation

@Published var dashboard = [DashList]()

@Published var dashboardLeft = [DashList]()
@Published var dashboardRight = [DashList]()

var all: [Story] {
if let selected {
return before + [selected] + after
Expand Down Expand Up @@ -149,6 +152,8 @@ import Foundation

func prepareDashboard() {
dashboard.removeAll()
dashboardLeft.removeAll()
dashboardRight.removeAll()

guard let dashboardArray = appDelegate.dashboardArray as? [[String : Any]] else {
return
Expand All @@ -169,7 +174,16 @@ import Foundation
let dash = DashList(index: index, side: side, order: order, feedId: feedId, folderId: folderId)

dashboard.append(dash)

if side == .left {
dashboardLeft.append(dash)
} else {
dashboardRight.append(dash)
}
}

dashboardLeft.sort { $0.order < $1.order }
dashboardRight.sort { $0.order < $1.order }
}

func reloadDashboard(for index: Int) {
Expand Down
15 changes: 11 additions & 4 deletions clients/ios/Classes/StorySettings.swift
Original file line number Diff line number Diff line change
Expand Up @@ -148,11 +148,18 @@ import Foundation
}
}

var dashboardColumns: Int {
guard let pref = UserDefaults.standard.string(forKey: "dashboard_columns"), let columns = Int(pref) else {
return 2
enum DashboardLayout: String, RawRepresentable {
case none
case single
case vertical
case horizontal
}

var dashboardLayout: DashboardLayout {
guard let pref = UserDefaults.standard.string(forKey: "dashboard_layout"), let layout = DashboardLayout(rawValue: pref) else {
return .vertical
}

return columns
return layout
}
}
24 changes: 24 additions & 0 deletions clients/ios/Resources/Settings.bundle/Root~ipad.plist
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,30 @@
<key>Key</key>
<string>feed_opening</string>
</dict>
<dict>
<key>Type</key>
<string>PSMultiValueSpecifier</string>
<key>Title</key>
<string>Dashboard</string>
<key>Titles</key>
<array>
<string>Hidden</string>
<string>Single column</string>
<string>Two columns</string>
<string>Two rows</string>
</array>
<key>DefaultValue</key>
<string>vertical</string>
<key>Values</key>
<array>
<string>none</string>
<string>single</string>
<string>vertical</string>
<string>horizontal</string>
</array>
<key>Key</key>
<string>dashboard_layout</string>
</dict>
<dict>
<key>FooterText</key>
<string>You can change this setting in the Infrequent Site Stories view.</string>
Expand Down
24 changes: 24 additions & 0 deletions clients/ios/Resources/mac/Settings.bundle/StoryList.plist
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,30 @@
<key>Key</key>
<string>feed_opening</string>
</dict>
<dict>
<key>Type</key>
<string>PSMultiValueSpecifier</string>
<key>Title</key>
<string>Dashboard</string>
<key>Titles</key>
<array>
<string>Hidden</string>
<string>Single column</string>
<string>Two columns</string>
<string>Two rows</string>
</array>
<key>DefaultValue</key>
<string>vertical</string>
<key>Values</key>
<array>
<string>none</string>
<string>single</string>
<string>vertical</string>
<string>horizontal</string>
</array>
<key>Key</key>
<string>dashboard_layout</string>
</dict>
<dict>
<key>FooterText</key>
<string>You can change this setting in the Infrequent Site Stories view.</string>
Expand Down
2 changes: 1 addition & 1 deletion clients/ios/TestFlight/WhatToTest.en-US.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
- Fixed the wrong story sometimes being selected when first opening the app.
- Work on the Dashboard continues; it is mostly functional now, but still a bunch of things to do.

0 comments on commit 6f5d7c5

Please sign in to comment.