1
1
mirror of https://github.com/danbee/persephone synced 2025-03-04 08:39:11 +00:00

WIP: Search

This commit is contained in:
Daniel Barber 2019-11-01 21:25:43 -04:00
parent 9f8f3a6ecf
commit 87d4f33b09
Signed by: danbarber
GPG Key ID: 931D8112E0103DD8
7 changed files with 39 additions and 7 deletions

View File

@ -302,6 +302,21 @@
</connections>
</button>
</toolbarItem>
<toolbarItem implicitItemIdentifier="7C15D391-03F5-42C7-AC6D-6E17549C698E" label="Search" paletteLabel="Search" sizingBehavior="auto" id="FRe-rR-Ulo">
<nil key="toolTip"/>
<searchField key="view" wantsLayer="YES" verticalHuggingPriority="750" textCompletion="NO" id="xfU-Xe-eno">
<rect key="frame" x="0.0" y="14" width="96" height="22"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<searchFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" selectable="YES" editable="YES" borderStyle="bezel" usesSingleLineMode="YES" bezelStyle="round" id="F3N-3P-tS3">
<font key="font" metaFont="system"/>
<color key="textColor" name="controlTextColor" catalog="System" colorSpace="catalog"/>
<color key="backgroundColor" name="textBackgroundColor" catalog="System" colorSpace="catalog"/>
</searchFieldCell>
<connections>
<action selector="handleSearchQuery:" target="B8D-0N-5wS" id="BPh-1O-bUU"/>
</connections>
</searchField>
</toolbarItem>
</allowedToolbarItems>
<defaultToolbarItems>
<toolbarItem reference="p3r-ty-Pxf"/>
@ -314,6 +329,7 @@
<toolbarItem reference="s1h-EC-nvL"/>
<toolbarItem reference="5U7-UV-xn2"/>
<toolbarItem reference="9ol-aR-mzv"/>
<toolbarItem reference="FRe-rR-Ulo"/>
</defaultToolbarItems>
</toolbar>
<connections>
@ -543,9 +559,6 @@
<constraint firstItem="ARv-cj-xlz" firstAttribute="leading" secondItem="BRY-0R-F3u" secondAttribute="leading" id="w2Z-xv-Fwz"/>
</constraints>
</view>
<connections>
<outlet property="browseTabView" destination="ARv-cj-xlz" id="h93-fi-yY7"/>
</connections>
</viewController>
</objects>
<point key="canvasLocation" x="1436" y="238"/>

View File

@ -27,8 +27,6 @@ class WindowController: NSWindowController {
@IBOutlet var shuffleState: NSButton!
@IBOutlet var repeatState: NSButton!
@IBOutlet var browseViewControls: NSSegmentedControl!
override func windowDidLoad() {
super.windowDidLoad()
window?.titleVisibility = .hidden
@ -161,6 +159,10 @@ class WindowController: NSWindowController {
@IBAction func handleRepeatButton(_ sender: NSButton) {
App.mpdClient.setRepeatState(repeatState: sender.state == .on)
}
@IBAction func handleSearchQuery(_ sender: NSSearchField) {
App.store.dispatch(SetSearchQuery(searchQuery: sender.stringValue))
}
}
extension WindowController: NSWindowDelegate {

View File

@ -49,11 +49,17 @@ extension MPDClient {
}
}
func allAlbums() {
func allAlbums(filter: String) {
var albums: [MPDAlbum] = []
var artist: String = ""
mpd_search_db_tags(self.connection, MPD_TAG_ALBUM)
if filter != "" {
mpd_search_add_expression(
self.connection,
"(any =~ 'alanis')"
)
}
mpd_search_add_group_tag(self.connection, MPD_TAG_ALBUM_ARTIST)
mpd_search_commit(self.connection)
@ -72,6 +78,8 @@ extension MPDClient {
mpd_return_pair(self.connection, pair.pair)
}
print(getLastErrorMessage())
self.delegate?.didLoadAlbums(mpdClient: self, albums: albums)
}

View File

@ -93,7 +93,7 @@ extension MPDClient {
// Album commands
case .fetchAllAlbums:
allAlbums()
allAlbums(filter: "Alanis")
case .playAlbum:
guard let album = userData["album"] as? MPDAlbum else { return }
sendPlayAlbum(album)

View File

@ -25,3 +25,7 @@ struct SetSelectedQueueItem: Action {
struct SetSelectedSong: Action {
let selectedSong: Song?
}
struct SetSearchQuery: Action {
let searchQuery: String
}

View File

@ -33,6 +33,9 @@ func uiReducer(action: Action, state: UIState?) -> UIState {
case let action as SetSelectedQueueItem:
state.selectedQueueItem = action.selectedQueueItem
case let action as SetSearchQuery:
state.searchQuery = action.searchQuery
default:
break
}

View File

@ -22,4 +22,6 @@ struct UIState: StateType {
var selectedSong: Song?
var selectedQueueItem: QueueItem?
var searchQuery: String = ""
}