-
Notifications
You must be signed in to change notification settings - Fork 411
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
217 additions
and
66 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
// | ||
// InfoListView.swift | ||
// SwiftPamphletApp | ||
// | ||
// Created by Ming Dai on 2024/3/11. | ||
// | ||
|
||
import SwiftUI | ||
import SwiftData | ||
|
||
struct InfoListView: View { | ||
@Environment(\.modelContext) var modelContext | ||
@State private var searchText = "" | ||
@Binding var selectInfo:IOInfo? | ||
@State private var sortOrder = [SortDescriptor(\IOInfo.updateDate, order: .reverse)] | ||
|
||
@Query(sort: [SortDescriptor(\IOCategory.updateDate, order: .reverse)]) var cates: [IOCategory] | ||
@State private var filterCate = "" | ||
|
||
var body: some View { | ||
if filterCate.isEmpty { | ||
InfosView(searchString: searchText, selectInfo: $selectInfo, sortOrder: sortOrder) | ||
.navigationTitle("资料列表") | ||
.toolbar { | ||
Menu("Sort", systemImage: "arrow.up.arrow.down") { | ||
Picker("分类", selection: $filterCate) { | ||
ForEach(cates) { cate in | ||
Text(cate.name) | ||
.tag(cate.name) | ||
} | ||
} | ||
Picker("排序", selection: $sortOrder) { | ||
Text("正序") | ||
.tag([SortDescriptor(\IOInfo.updateDate)]) | ||
Text("倒序") | ||
.tag([SortDescriptor(\IOInfo.updateDate, order: .reverse)]) | ||
} | ||
} | ||
Button("添加资料", systemImage: "plus", action: addInfo) | ||
|
||
} | ||
.searchable(text: $searchText) | ||
} else { | ||
InfosFilterWithCateView(filterCateName: filterCate, selectInfo: $selectInfo, sortOrder: sortOrder) | ||
.navigationTitle("资料列表") | ||
.toolbar { | ||
Menu("Sort", systemImage: "arrow.up.arrow.down") { | ||
Picker("分类", selection: $filterCate) { | ||
ForEach(cates) { cate in | ||
Text(cate.name) | ||
.tag(cate.name) | ||
} | ||
} | ||
Picker("排序", selection: $sortOrder) { | ||
Text("正序") | ||
.tag([SortDescriptor(\IOInfo.updateDate)]) | ||
Text("倒序") | ||
.tag([SortDescriptor(\IOInfo.updateDate, order: .reverse)]) | ||
} | ||
|
||
} | ||
Button("添加资料", systemImage: "plus", action: addInfoWithCate) | ||
} | ||
} | ||
|
||
} | ||
|
||
func addInfo() { | ||
let info = IOInfo(name: "无标题", url: "", des: "\n", createDate: Date.now, updateDate: Date.now) | ||
modelContext.insert(info) | ||
selectInfo = info | ||
} | ||
func addInfoWithCate() { | ||
let info = IOInfo(name: "无标题", url: "", des: "\n", createDate: Date.now, updateDate: Date.now) | ||
for cate in cates { | ||
if cate.name == filterCate { | ||
info.category = cate | ||
} | ||
} | ||
modelContext.insert(info) | ||
selectInfo = info | ||
} | ||
|
||
} | ||
|
||
|
File renamed without changes.
36 changes: 36 additions & 0 deletions
36
SwiftPamphletApp/InfoOrganizer/Info/InfosFilterWithCateView.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
// | ||
// InfosFilterWithCateView.swift | ||
// SwiftPamphletApp | ||
// | ||
// Created by Ming Dai on 2024/3/12. | ||
// | ||
|
||
import SwiftUI | ||
import SwiftData | ||
|
||
struct InfosFilterWithCateView: View { | ||
@Environment(\.modelContext) var modelContext | ||
@Query var infos: [IOInfo] | ||
@Binding var selectInfo: IOInfo? | ||
|
||
init(filterCateName: String = "", selectInfo: Binding<IOInfo?>, sortOrder: [SortDescriptor<IOInfo>] = []) { | ||
_infos = Query(filter: #Predicate { info in | ||
if filterCateName.isEmpty { | ||
true | ||
} else { | ||
info.category?.name == filterCateName | ||
} | ||
}, sort: sortOrder) | ||
|
||
self._selectInfo = selectInfo | ||
} | ||
|
||
var body: some View { | ||
List(selection: $selectInfo) { | ||
ForEach(infos) { info in | ||
InfoRowView(info: info, selectedInfo: selectInfo) | ||
.tag(info) | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.