implemented search for projects
failed to make a colour filter
This commit is contained in:
parent
937344a1e9
commit
7abd5e3ba4
@ -10,54 +10,42 @@ import SwiftData
|
|||||||
|
|
||||||
struct MainView: View {
|
struct MainView: View {
|
||||||
@Environment(\.modelContext) private var modelContext
|
@Environment(\.modelContext) private var modelContext
|
||||||
@Query private var items: [OCProject]
|
|
||||||
|
|
||||||
@State private var showSettingsView = false
|
@State private var showSettingsView = false
|
||||||
@State private var newProjectName = ""
|
@State private var newProjectName = ""
|
||||||
@State private var addNewProject = false
|
@State private var addNewProject = false
|
||||||
@State private var filterColor = ""
|
@State private var filterColor = ""
|
||||||
|
|
||||||
|
@State private var searchText = ""
|
||||||
|
|
||||||
var body: some View {
|
var body: some View {
|
||||||
NavigationSplitView {
|
NavigationSplitView {
|
||||||
List {
|
List {
|
||||||
ForEach(items) { project in
|
ProjectListView(sort: SortDescriptor(\.creationDate, order: .reverse),
|
||||||
NavigationLink {
|
searchString: searchText,
|
||||||
CardsView(project: project)
|
color: filterColor)
|
||||||
} label: {
|
|
||||||
VStack(alignment: .leading) {
|
|
||||||
Text("\(project.name)")
|
|
||||||
.bold()
|
|
||||||
.font(.title2)
|
|
||||||
.foregroundStyle(Color(hex: project.color) ?? .white)
|
|
||||||
Text("\(project.cards.count) \(project.cards.count == 1 ? "Card" : "Cards")")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
.padding(.vertical, 3)
|
|
||||||
}
|
|
||||||
.onDelete(perform: deleteItems)
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
.searchable(text: $searchText)
|
||||||
.toolbar {
|
.toolbar {
|
||||||
ToolbarItem(placement: .topBarLeading) {
|
ToolbarItem(placement: .topBarLeading) {
|
||||||
Button(action: {showSettingsView.toggle()}) {
|
Button(action: {showSettingsView.toggle()}) {
|
||||||
Image(systemName: "gear")
|
Image(systemName: "gear")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// ToolbarItem(placement: .topBarTrailing) {
|
ToolbarItem(placement: .topBarTrailing) {
|
||||||
// Menu {
|
Menu {
|
||||||
// Picker(selection: $filterColor) {
|
Picker(selection: $filterColor) {
|
||||||
// ForEach(Constants.colors, id: \.self) { clr in
|
ForEach(Constants.colorText, id: \.self) { clr in
|
||||||
// Circle()
|
Text(clr)
|
||||||
// .foregroundStyle(clr)
|
}
|
||||||
// }
|
} label: {
|
||||||
// } label: {
|
Text("Color")
|
||||||
// Text("Color")
|
}
|
||||||
// }
|
.pickerStyle(.menu)
|
||||||
// .pickerStyle(.menu)
|
} label: {
|
||||||
// } label: {
|
Image(systemName: "line.3.horizontal.decrease.circle")
|
||||||
// Image(systemName: "line.3.horizontal.decrease.circle")
|
}
|
||||||
// }
|
}
|
||||||
// }
|
|
||||||
ToolbarItem(placement: .topBarTrailing) {
|
ToolbarItem(placement: .topBarTrailing) {
|
||||||
Button(action: { addNewProject.toggle() }) {
|
Button(action: { addNewProject.toggle() }) {
|
||||||
Label("Add Item", systemImage: "plus")
|
Label("Add Item", systemImage: "plus")
|
||||||
@ -82,11 +70,44 @@ struct MainView: View {
|
|||||||
modelContext.insert(newProject)
|
modelContext.insert(newProject)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private struct ProjectListView: View {
|
||||||
|
@Environment(\.modelContext) private var modelContext
|
||||||
|
@Query private var projects: [OCProject]
|
||||||
|
|
||||||
|
init(sort: SortDescriptor<OCProject>, searchString: String, color: String) {
|
||||||
|
_projects = Query(filter: #Predicate {
|
||||||
|
if searchString.isEmpty {
|
||||||
|
return true
|
||||||
|
} else {
|
||||||
|
return $0.name.localizedStandardContains(searchString)
|
||||||
|
}
|
||||||
|
}, sort: [sort])
|
||||||
|
}
|
||||||
|
|
||||||
|
var body: some View {
|
||||||
|
ForEach(projects) { project in
|
||||||
|
NavigationLink {
|
||||||
|
CardsView(project: project)
|
||||||
|
} label: {
|
||||||
|
VStack(alignment: .leading) {
|
||||||
|
Text("\(project.name)")
|
||||||
|
.bold()
|
||||||
|
.font(.title2)
|
||||||
|
.foregroundStyle(Color(hex: project.color) ?? .white)
|
||||||
|
Text("\(project.cards.count) \(project.cards.count == 1 ? "Card" : "Cards")")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
.padding(.vertical, 3)
|
||||||
|
}
|
||||||
|
.onDelete(perform: deleteItems)
|
||||||
|
}
|
||||||
|
|
||||||
private func deleteItems(offsets: IndexSet) {
|
private func deleteItems(offsets: IndexSet) {
|
||||||
withAnimation {
|
withAnimation {
|
||||||
for index in offsets {
|
for index in offsets {
|
||||||
modelContext.delete(items[index])
|
modelContext.delete(projects[index])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -9,4 +9,5 @@ import SwiftUI
|
|||||||
|
|
||||||
public struct Constants {
|
public struct Constants {
|
||||||
static let colors: [Color] = [.red, .orange, .yellow, .green, .blue, .indigo]
|
static let colors: [Color] = [.red, .orange, .yellow, .green, .blue, .indigo]
|
||||||
|
static let colorText = ["None", "Red", "Orange", "Yellow", "Green", "Blue", "Indigo"]
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user