Skip to content

Commit

Permalink
[추가] 최근 검색어 기능 구현 (#173)
Browse files Browse the repository at this point in the history
  • Loading branch information
lgvv authored Mar 25, 2024
1 parent 57a41ea commit 68a7a8c
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 5 deletions.
5 changes: 5 additions & 0 deletions package-kuring/Sources/Caches/Dependency/RecentSearch.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import Dependencies
public struct RecentSearch {
public var add: (_ keyword: String) -> Void
public var remove: (_ keyword: String) -> Void
public var removeAll: () -> Void
public var getAll: () -> [String]

/// 최근 검색어
Expand All @@ -29,8 +30,12 @@ extension RecentSearch {
keywords.removeAll { $0 == keyword }
Self.recentKeywords = keywords

}, removeAll: {
Self.recentKeywords = []

}, getAll: {
Self.recentKeywords

}
)
}
Expand Down
11 changes: 10 additions & 1 deletion package-kuring/Sources/Features/SearchFeatures/Search.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@
// See the 'License.txt' file for licensing information.
//

import Caches
import Models
import Networks
import Dependencies
import ComposableArchitecture

@Reducer
Expand Down Expand Up @@ -65,8 +67,10 @@ public struct SearchFeature {
searchInfo: SearchInfo = .init(),
focus: Field? = .search
) {
@Dependency(\.recentSearch) var recentSearch

self.staffDetail = staffDetail
self.recents = recents
self.recents = recentSearch.getAll()
self.resultNotices = resultNotices
self.resultStaffs = resultStaffs
self.searchInfo = searchInfo
Expand Down Expand Up @@ -125,6 +129,7 @@ public struct SearchFeature {
}

@Dependency(\.kuringLink) var kuringLink
@Dependency(\.recentSearch) var recentSearch

public var body: some ReducerOf<Self> {
BindingReducer()
Expand All @@ -145,6 +150,8 @@ public struct SearchFeature {

case .deleteAllRecentsButtonTapped:
state.recents.removeAll()
recentSearch.removeAll()

return .none

case .clearKeywordButtonTapped:
Expand All @@ -159,6 +166,8 @@ public struct SearchFeature {
// 최근 검색어 추가
if !state.recents.contains(state.searchInfo.text) { // 중복체크
state.recents.append(state.searchInfo.text)

recentSearch.add(state.searchInfo.text)
}

state.searchInfo.searchPhase = .searching
Expand Down
7 changes: 3 additions & 4 deletions package-kuring/Sources/UIKit/SearchUI/SearchView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -129,13 +129,13 @@ public struct SearchView: View {
Button {
store.send(.selectSearchType(.notice))
} label: {
SegmentView("공지", isSelect: store.searchInfo.searchType == .notice)
segmentView("공지", isSelect: store.searchInfo.searchType == .notice)
}

Button {
store.send(.selectSearchType(.staff))
} label: {
SegmentView("교직원", isSelect: store.searchInfo.searchType == .staff)
segmentView("교직원", isSelect: store.searchInfo.searchType == .staff)
}
}
.padding(5)
Expand Down Expand Up @@ -224,7 +224,7 @@ public struct SearchView: View {
}
}

private func SegmentView(_ title: String, isSelect: Bool) -> some View {
private func segmentView(_ title: String, isSelect: Bool) -> some View {
RoundedRectangle(cornerRadius: 10)
.foregroundStyle(isSelect ? Color.Kuring.bg : .clear)
.shadow(
Expand Down Expand Up @@ -257,7 +257,6 @@ public struct SearchView: View {

public init(store: StoreOf<SearchFeature>) {
self.store = store
// UITableView
}
}

Expand Down

0 comments on commit 68a7a8c

Please sign in to comment.