Skip to content

Commit a314925

Browse files
authored
Post search (#1206)
* Reworked the search build from two years ago. Fleshed out the UI for ipad view and added themed components. SearchView.swift contains all the code for the feature. ForumsTableViewController was updated to conditinoally show the search button (if user has pms). AnnouncementPersistence.swift was updated in order to get the build working in this version of xcode 16.4. * Addressing PR comments. Tried adding a fixture for the search page for previews, but ended up using a simple solution for the time being. Resolves #23.
1 parent 7889fed commit a314925

File tree

8 files changed

+1557
-2
lines changed

8 files changed

+1557
-2
lines changed
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// View+FontDesign.swift
2+
//
3+
// Copyright 2025 Awful Contributors. CC BY-NC-SA 3.0 US https://github.com/Awful/Awful.app
4+
5+
import SwiftUI
6+
7+
extension View {
8+
@ViewBuilder
9+
func applyFontDesign(if condition: Bool) -> some View {
10+
if #available(iOS 16.1, *) {
11+
self.fontDesign(condition ? .rounded : .default)
12+
} else {
13+
self
14+
}
15+
}
16+
}

App/Resources/Localizable.xcstrings

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
{
22
"sourceLanguage" : "en",
33
"strings" : {
4+
"" : {
5+
6+
},
7+
"%@" : {
8+
9+
},
410
"action.share-url" : {
511
"comment" : "Title of the share URL action for an announcement, post, or thread.",
612
"extractionState" : "manual",
@@ -33,6 +39,9 @@
3339
},
3440
"Author Profile" : {
3541

42+
},
43+
"Back" : {
44+
3645
},
3746
"bookmarks.title" : {
3847
"comment" : "Title of the bookmarks screen, shown in the navbar and the tab bar.",
@@ -281,6 +290,12 @@
281290
},
282291
"Double-check your username and password, then try again." : {
283292

293+
},
294+
"Example searches:" : {
295+
296+
},
297+
"Exit" : {
298+
284299
},
285300
"Five" : {
286301

@@ -648,6 +663,16 @@
648663
}
649664
}
650665
},
666+
"Page %lld of %lld" : {
667+
"localizations" : {
668+
"en" : {
669+
"stringUnit" : {
670+
"state" : "new",
671+
"value" : "Page %1$lld of %2$lld"
672+
}
673+
}
674+
}
675+
},
651676
"posts-page.copied-post" : {
652677
"comment" : "Title of alert shown when post successfully copied to pasteboard.",
653678
"extractionState" : "migrated",
@@ -1030,6 +1055,21 @@
10301055
}
10311056
}
10321057
}
1058+
},
1059+
"Search" : {
1060+
1061+
},
1062+
"Search Forums" : {
1063+
1064+
},
1065+
"Search forums..." : {
1066+
1067+
},
1068+
"Search Results" : {
1069+
1070+
},
1071+
"Select Forums" : {
1072+
10331073
},
10341074
"session-expiry-imminent.message" : {
10351075
"comment" : "Message of an alert shown on launch if the user's session expires within a week. Parameter is the expiry date.",
@@ -1180,6 +1220,9 @@
11801220
}
11811221
}
11821222
}
1223+
},
1224+
"Toggle All" : {
1225+
11831226
},
11841227
"V" : {
11851228

App/View Controllers/Forums/ForumsTableViewController.swift

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,15 @@ import Combine
99
import CoreData
1010
import os
1111
import UIKit
12+
import SwiftUI
1213

1314
private let logger = Logger(subsystem: Bundle.main.bundleIdentifier!, category: "ForumsTableViewController")
1415

1516
final class ForumsTableViewController: TableViewController {
1617

1718
private var cancellables: Set<AnyCancellable> = []
1819
@FoilDefaultStorage(Settings.enableHaptics) private var enableHaptics
20+
@FoilDefaultStorage(Settings.canSendPrivateMessages) private var canSendPrivateMessages
1921
private var favoriteForumCountObserver: ManagedObjectCountObserver!
2022
private var listDataSource: ForumListDataSource!
2123
let managedObjectContext: NSManagedObjectContext
@@ -166,6 +168,40 @@ final class ForumsTableViewController: TableViewController {
166168
pullToRefreshBlock = { [weak self] in
167169
self?.refresh()
168170
}
171+
172+
lazy var searchButton: UIBarButtonItem = {
173+
let button = UIBarButtonItem(title: "Search", style: .plain, target: self, action: #selector(searchForums))
174+
button.isEnabled = canSendPrivateMessages
175+
return button
176+
}()
177+
178+
if canSendPrivateMessages {
179+
navigationItem.setLeftBarButton(searchButton, animated: true)
180+
}
181+
182+
// Add observer for changes to canSendPrivateMessages
183+
$canSendPrivateMessages
184+
.receive(on: RunLoop.main)
185+
.sink { [weak self] canSend in
186+
guard let self else { return }
187+
if canSend {
188+
navigationItem.setLeftBarButton(searchButton, animated: true)
189+
} else {
190+
navigationItem.setLeftBarButton(nil, animated: true)
191+
}
192+
}
193+
.store(in: &cancellables)
194+
}
195+
196+
@objc private func searchForums() {
197+
let searchView = SearchHostingController()
198+
searchView.restorationIdentifier = "Search view"
199+
if traitCollection.userInterfaceIdiom == .pad {
200+
searchView.modalPresentationStyle = .pageSheet
201+
} else {
202+
searchView.modalPresentationStyle = .fullScreen
203+
}
204+
present(searchView, animated: true)
169205
}
170206

171207
override func themeDidChange() {

0 commit comments

Comments
 (0)