Skip to content

Commit

Permalink
Merge pull request #241 from DeveloperAcademy-POSTECH/SearchView/UI
Browse files Browse the repository at this point in the history
[Feat] Search view/UI
  • Loading branch information
otoolz authored Nov 14, 2022
2 parents 470e9e7 + f20f3b8 commit 949d088
Show file tree
Hide file tree
Showing 3 changed files with 125 additions and 1 deletion.
4 changes: 4 additions & 0 deletions HappyAnding/HappyAnding.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
4D778A34290A53BA00C15AC4 /* Application+Extension.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4D778A33290A53BA00C15AC4 /* Application+Extension.swift */; };
872A7D8F2918393B004A05B8 /* PrivacyPolicyView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 872A7D8E2918393B004A05B8 /* PrivacyPolicyView.swift */; };
8792478D2918CE450040D5C3 /* UINavigationContoller+Extension.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8792478C2918CE450040D5C3 /* UINavigationContoller+Extension.swift */; };
8792479B291BDF820040D5C3 /* SearchView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8792479A291BDF820040D5C3 /* SearchView.swift */; };
87E606B0291062F900C3DA13 /* AppleAuthCoordinator.swift in Sources */ = {isa = PBXBuildFile; fileRef = 87E606AF291062F900C3DA13 /* AppleAuthCoordinator.swift */; };
87E606B22910649B00C3DA13 /* SignInWithAppleView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 87E606B12910649B00C3DA13 /* SignInWithAppleView.swift */; };
87E606B629114F7D00C3DA13 /* WriteNicknameView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 87E606B529114F7D00C3DA13 /* WriteNicknameView.swift */; };
Expand Down Expand Up @@ -107,6 +108,7 @@
4D778A33290A53BA00C15AC4 /* Application+Extension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Application+Extension.swift"; sourceTree = "<group>"; };
872A7D8E2918393B004A05B8 /* PrivacyPolicyView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PrivacyPolicyView.swift; sourceTree = "<group>"; };
8792478C2918CE450040D5C3 /* UINavigationContoller+Extension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UINavigationContoller+Extension.swift"; sourceTree = "<group>"; };
8792479A291BDF820040D5C3 /* SearchView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SearchView.swift; sourceTree = "<group>"; };
87E606AD2910623C00C3DA13 /* HappyAnding.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = HappyAnding.entitlements; sourceTree = "<group>"; };
87E606AF291062F900C3DA13 /* AppleAuthCoordinator.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppleAuthCoordinator.swift; sourceTree = "<group>"; };
87E606B12910649B00C3DA13 /* SignInWithAppleView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SignInWithAppleView.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -309,6 +311,7 @@
87E606AE291062D300C3DA13 /* SignInViews */,
F956C9F82903F87200C17621 /* ShortcutTestModel.swift */,
F9914527290850370046986E /* TestUserCurationListView.swift */,
8792479A291BDF820040D5C3 /* SearchView.swift */,
3D41EE07290A4C18008BE986 /* Launch Screen.storyboard */,
);
path = Views;
Expand Down Expand Up @@ -611,6 +614,7 @@
87E99CC429014572009B691F /* Color+Extension.swift in Sources */,
87E99CD929042536009B691F /* SectionType.swift in Sources */,
872A7D8F2918393B004A05B8 /* PrivacyPolicyView.swift in Sources */,
8792479B291BDF820040D5C3 /* SearchView.swift in Sources */,
A3FF018E291ACFA500384211 /* WithdrawalView.swift in Sources */,
4D778A34290A53BA00C15AC4 /* Application+Extension.swift in Sources */,
87E99CBF28FFF2AB009B691F /* WriteShortcutTagView.swift in Sources */,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,22 @@ struct ExploreShortcutView: View {
.navigationBarTitleDisplayMode(.large)
.scrollIndicators(.hidden)
.background(Color.Background)
.toolbar {
ToolbarItem {
NavigationLink(destination: SearchView()) {
Image(systemName: "magnifyingglass")
.Headline()
.foregroundColor(.Gray5)
}
}
}
}
}
}

/*
struct ExploreShortcutView_Previews: PreviewProvider {
static var previews: some View {
ExploreShortcutView()
}
}
*/
110 changes: 110 additions & 0 deletions HappyAnding/HappyAnding/Views/SearchView.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
//
// SearchView.swift
// HappyAnding
//
// Created by 이지원 on 2022/11/09.
//

import MessageUI
import SwiftUI

struct SearchView: View {
@Environment(\.isSearching) private var isSearching: Bool
@Environment(\.dismissSearch) private var dismissSearch

@State var isSearched: Bool = false
@State var searchText: String = ""
@State var searchResults: [Shortcuts] = []

let keywords: [String] = ["단축어", "갓생", "포항꿀주먹"]

var body: some View {
VStack {
if !isSearched {
recommendKeword
Spacer()
} else {
if searchResults.count == 0 {
proposeView
} else {
ScrollView {
ForEach(searchResults, id: \.self) { result in
NavigationLink(destination: ReadShortcutView(shortcutID: result.id)) {
ShortcutCell(shortcut: result)
.listRowInsets(EdgeInsets())
.listRowSeparator(.hidden)
}
}
}
}
}
}
.searchable(text: $searchText)
.onSubmit(of: .search, runSearch)
.onChange(of: searchText) { value in
if searchText.isEmpty && !isSearching {
// Search cancelled here
print("canceled")
searchResults.removeAll()
isSearched = false
}
} .navigationBarTitleDisplayMode(.inline)
.background(Color.Background)
}

private func runSearch() {
Task {
isSearched = true
// firebase 검색 기능 추가해서 searchResults에 넣기
}
}

var recommendKeword: some View {
VStack(alignment: .leading) {
Text("추천 검색어")
.padding(.leading, 16)

ScrollView(.horizontal) {
HStack {
// TODO: 선택된 텍스트 검색하는 기능
ForEach(keywords, id: \.self) { keyword in
Text(keyword)
.Body2()
.foregroundColor(Color.Gray4)
.padding(10)
.overlay(
RoundedRectangle(cornerRadius: 12)
.stroke(Color.Gray4, lineWidth: 1)
)
}
}
.padding(.leading, 12)
}
}
}

var proposeView: some View {
VStack(alignment: .center) {
Text("\(searchText)의 결과가 없어요.\n원하는 단축어를 제안해보는건 어떠세요?").multilineTextAlignment(.center)
.Body1()
.foregroundColor(Color.Gray4)

Button {
//TODO: 버튼 클릭 시 단축어 제안하는 페이지 연결
} label: {
Text("단축어 제안하기")
.padding(.horizontal, 28)
.padding(.vertical, 8)
}.buttonStyle(.borderedProminent)
.padding(16)
}
.frame(maxWidth: .infinity, maxHeight: .infinity)
.background(Color.Background)
}
}

struct SearchView_Previews: PreviewProvider {
static var previews: some View {
SearchView()
}
}

0 comments on commit 949d088

Please sign in to comment.