Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[add] 검색 기능 추가 #35

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions Cuckoo_swiftUI/Cuckoo/Cuckoo.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,11 @@
7D8DE4C12B1EB0A6004502FF /* NotificationLog.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7D8DE4C02B1EB0A6004502FF /* NotificationLog.swift */; };
7D9AB3CE2B2295AE00B00C09 /* SettingTagViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7D9AB3CD2B2295AE00B00C09 /* SettingTagViewModel.swift */; };
7DF6B4D22B1B204800B64CC0 /* MemoDetailViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7DF6B4D12B1B204800B64CC0 /* MemoDetailViewModel.swift */; };
7DF6B4D42B1B26E800B64CC0 /* MainContainerViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7DF6B4D32B1B26E800B64CC0 /* MainContainerViewModel.swift */; };
A82451F02AFE69A600EB4F54 /* AddMemoView.swift in Sources */ = {isa = PBXBuildFile; fileRef = A82451EF2AFE69A600EB4F54 /* AddMemoView.swift */; };
A82451F22B09F2B300EB4F54 /* NavView.swift in Sources */ = {isa = PBXBuildFile; fileRef = A82451F12B09F2B300EB4F54 /* NavView.swift */; };
A82451F82B17470500EB4F54 /* AlarmView.swift in Sources */ = {isa = PBXBuildFile; fileRef = A82451F72B17470500EB4F54 /* AlarmView.swift */; };
A84350DE2B2369B5006CDD60 /* MemoDummy.swift in Sources */ = {isa = PBXBuildFile; fileRef = A84350DD2B2369B5006CDD60 /* MemoDummy.swift */; };
A84350E02B2372F5006CDD60 /* MainViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = A84350DF2B2372F5006CDD60 /* MainViewModel.swift */; };
A8BC238F2AFA013B00A2F87F /* MainContainerView.swift in Sources */ = {isa = PBXBuildFile; fileRef = A8BC238E2AFA013B00A2F87F /* MainContainerView.swift */; };
A8BC23912AFA014B00A2F87F /* MainView.swift in Sources */ = {isa = PBXBuildFile; fileRef = A8BC23902AFA014B00A2F87F /* MainView.swift */; };
/* End PBXBuildFile section */
Expand Down Expand Up @@ -89,11 +89,11 @@
7D8DE4C02B1EB0A6004502FF /* NotificationLog.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NotificationLog.swift; sourceTree = "<group>"; };
7D9AB3CD2B2295AE00B00C09 /* SettingTagViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SettingTagViewModel.swift; sourceTree = "<group>"; };
7DF6B4D12B1B204800B64CC0 /* MemoDetailViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MemoDetailViewModel.swift; sourceTree = "<group>"; };
7DF6B4D32B1B26E800B64CC0 /* MainContainerViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MainContainerViewModel.swift; sourceTree = "<group>"; };
A82451EF2AFE69A600EB4F54 /* AddMemoView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AddMemoView.swift; sourceTree = "<group>"; };
A82451F12B09F2B300EB4F54 /* NavView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NavView.swift; sourceTree = "<group>"; };
A82451F72B17470500EB4F54 /* AlarmView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AlarmView.swift; sourceTree = "<group>"; };
A84350DD2B2369B5006CDD60 /* MemoDummy.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MemoDummy.swift; sourceTree = "<group>"; };
A84350DF2B2372F5006CDD60 /* MainViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MainViewModel.swift; sourceTree = "<group>"; };
A8BC238E2AFA013B00A2F87F /* MainContainerView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MainContainerView.swift; sourceTree = "<group>"; };
A8BC23902AFA014B00A2F87F /* MainView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MainView.swift; sourceTree = "<group>"; };
/* End PBXFileReference section */
Expand Down Expand Up @@ -166,8 +166,8 @@
children = (
00A73DFA2B0C31D700B59084 /* AddMemoViewModel.swift */,
7DF6B4D12B1B204800B64CC0 /* MemoDetailViewModel.swift */,
7DF6B4D32B1B26E800B64CC0 /* MainContainerViewModel.swift */,
7D9AB3CD2B2295AE00B00C09 /* SettingTagViewModel.swift */,
A84350DF2B2372F5006CDD60 /* MainViewModel.swift */,
);
path = ViewModels;
sourceTree = "<group>";
Expand Down Expand Up @@ -390,6 +390,7 @@
A82451F22B09F2B300EB4F54 /* NavView.swift in Sources */,
00A73E0B2B0C40B700B59084 /* 1_Init_AddNameAndTagView.swift in Sources */,
00A73DFD2B0C323800B59084 /* Memo.swift in Sources */,
A84350E02B2372F5006CDD60 /* MainViewModel.swift in Sources */,
7D9AB3CE2B2295AE00B00C09 /* SettingTagViewModel.swift in Sources */,
00A73E012B0C35D300B59084 /* Tag.swift in Sources */,
00652D962B143E70004C3345 /* SettingTagView.swift in Sources */,
Expand All @@ -409,7 +410,6 @@
00652D902B12E2DB004C3345 /* 2_Init_AddAlarmPresetView.swift in Sources */,
00652D942B143E51004C3345 /* MemoDetailView.swift in Sources */,
7A7F87832AEF559C00F14B11 /* CuckooApp.swift in Sources */,
7DF6B4D42B1B26E800B64CC0 /* MainContainerViewModel.swift in Sources */,
00DBF6FC2B1F1FF1001EBCE3 /* SettingAlarmPresetView.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand Down
Binary file not shown.

This file was deleted.

33 changes: 33 additions & 0 deletions Cuckoo_swiftUI/Cuckoo/Cuckoo/ViewModels/MainViewModel.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
//
// MainViewModel.swift
// Cuckoo
//
// Created by 장동우 on 2023/12/09.
//

import Foundation

class MainViewModel: ObservableObject {
@Published var searchingText : String
@Published var filteredMemos : [Memo]


init(){
self.searchingText = ""
self.filteredMemos = items

}

func filterMemos(searchingText: String){
if searchingText.isEmpty{
filteredMemos = items
}else{
filteredMemos = items.filter { memo in
memo.title.localizedCaseInsensitiveContains(searchingText) ||
memo.comment.localizedCaseInsensitiveContains(searchingText) ||
memo.isPinned == true
}
}
}

}
20 changes: 12 additions & 8 deletions Cuckoo_swiftUI/Cuckoo/Cuckoo/Views/MainView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,16 @@ import SwiftUI


struct MainView: View {

@StateObject var viewModel = MainViewModel()
//title 수정용
@State private var isPresentingMemoSheet = false
@State private var searchContent: String = ""


// TODO : <og:preview> tag에서 미리보기 이미지 떼오는 hook

var itemCount: Int {
return items.count
return viewModel.filteredMemos.count
}

var body: some View {
Expand All @@ -27,12 +29,13 @@ struct MainView: View {
Spacer()

// Search Bar & Tag
MainViewSearchFilter()
MainViewSearchFilter(searchContent: $searchContent){
viewModel.filterMemos(searchingText: searchContent)
}
Spacer()

// Body
ScrollView {
ForEach(items, id: \.id) { item in
ForEach(viewModel.filteredMemos, id: \.id) { item in
VStack(alignment: .leading) {
NavigationLink(destination: MemoDetailView(viewModel: MemoDetailViewModel(memo: item))) {
MainContainerView(memo: item)
Expand Down Expand Up @@ -61,7 +64,6 @@ struct MainView_PreViews: PreviewProvider {
}
}


// Components

struct MainViewHeader: View {
Expand Down Expand Up @@ -122,13 +124,15 @@ struct MainViewHeader: View {
}

struct MainViewSearchFilter: View {
@State private var searchContent: String = "" // 사용자가 입력할 내용을 저장할 상태 변수입니다.
@Binding var searchContent : String // 사용자가 입력할 내용을 저장할 상태 변수입니다.
var onCommit: () -> Void


var body: some View {
// TextEditor의 스크롤 가능한 영역 설정
VStack(spacing: 18) {
HStack(spacing: 0){
TextField("검색어를 입력해주세요!", text: $searchContent)
TextField("검색어를 입력해주세요!", text: $searchContent,onCommit: onCommit)
.font(.system(size: 14, weight: .medium))
.padding(.leading, 25)
.padding(10)
Expand Down