Skip to content

Commit

Permalink
添加分类过滤
Browse files Browse the repository at this point in the history
  • Loading branch information
ming1016 committed Mar 12, 2024
1 parent 1a4cb35 commit a4cbe2c
Show file tree
Hide file tree
Showing 13 changed files with 217 additions and 66 deletions.
61 changes: 53 additions & 8 deletions SwiftPamphletApp.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,8 @@
08D107BD278826BB007B7009 /* HTMLEntities in Frameworks */ = {isa = PBXBuildFile; productRef = 08D107BC278826BB007B7009 /* HTMLEntities */; };
08ED80162B9C54DE0069B7EC /* SMNetwork in Frameworks */ = {isa = PBXBuildFile; productRef = 08ED80152B9C54DE0069B7EC /* SMNetwork */; };
08ED801C2B9D1EEC0069B7EC /* SettingView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 08ED801B2B9D1EEC0069B7EC /* SettingView.swift */; };
08F1AB612BA0821900AEA0CA /* CodeEditor in Frameworks */ = {isa = PBXBuildFile; productRef = 08F1AB602BA0821900AEA0CA /* CodeEditor */; };
08F1AB662BA0A7E100AEA0CA /* InfosFilterWithCateView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 08F1AB652BA0A7E100AEA0CA /* InfosFilterWithCateView.swift */; };
08F4BE6028609D8700733F12 /* PlayCharts.swift in Sources */ = {isa = PBXBuildFile; fileRef = 08F4BE5F28609D8600733F12 /* PlayCharts.swift */; };
08F4BE6228616DC100733F12 /* PlayWeatherKit.swift in Sources */ = {isa = PBXBuildFile; fileRef = 08F4BE6128616DC100733F12 /* PlayWeatherKit.swift */; };
08F51BC527A374A500693AB6 /* footer_js.html in Resources */ = {isa = PBXBuildFile; fileRef = 08F51BC427A374A500693AB6 /* footer_js.html */; };
Expand Down Expand Up @@ -520,6 +522,7 @@
08CD61FC27758B8A008C0935 /* Lexer.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Lexer.swift; sourceTree = "<group>"; };
08CD61FD27758B8A008C0935 /* Token.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Token.swift; sourceTree = "<group>"; };
08ED801B2B9D1EEC0069B7EC /* SettingView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SettingView.swift; sourceTree = "<group>"; };
08F1AB652BA0A7E100AEA0CA /* InfosFilterWithCateView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InfosFilterWithCateView.swift; sourceTree = "<group>"; };
08F4BE5F28609D8600733F12 /* PlayCharts.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PlayCharts.swift; sourceTree = "<group>"; };
08F4BE6128616DC100733F12 /* PlayWeatherKit.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PlayWeatherKit.swift; sourceTree = "<group>"; };
08F51BC427A374A500693AB6 /* footer_js.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = footer_js.html; sourceTree = "<group>"; };
Expand All @@ -534,6 +537,7 @@
08BF26D02768A59A0064DDAC /* SQLite in Frameworks */,
08448F4E279E8CA400B61353 /* Ink in Frameworks */,
08BF26D32768A5B40064DDAC /* MarkdownUI in Frameworks */,
08F1AB612BA0821900AEA0CA /* CodeEditor in Frameworks */,
08397E322B9F39C100DFDD02 /* SwiftSoup in Frameworks */,
08ED80162B9C54DE0069B7EC /* SMNetwork in Frameworks */,
08D107BD278826BB007B7009 /* HTMLEntities in Frameworks */,
Expand Down Expand Up @@ -573,14 +577,9 @@
08397E212B9EE83F00DFDD02 /* InfoOrganizer */ = {
isa = PBXGroup;
children = (
08397E222B9EE8F400DFDD02 /* InfoDataModel.swift */,
08397E242B9EEE1300DFDD02 /* InfoListView.swift */,
0871C61C2BA05F44000B620D /* InfosView.swift */,
0871C6182BA040E5000B620D /* InfoRowView.swift */,
08397E2E2B9F353B00DFDD02 /* CategoryListView.swift */,
0871C61A2BA04D23000B620D /* CategoryRowView.swift */,
08397E282B9F0A9100DFDD02 /* EditInfoView.swift */,
08397E2C2B9F10AD00DFDD02 /* EditCategoryView.swift */,
08F1AB642BA0840400AEA0CA /* Category */,
08F1AB632BA083F500AEA0CA /* Info */,
08F1AB622BA083DD00AEA0CA /* Model */,
);
path = InfoOrganizer;
sourceTree = "<group>";
Expand Down Expand Up @@ -1340,6 +1339,36 @@
path = Setting;
sourceTree = "<group>";
};
08F1AB622BA083DD00AEA0CA /* Model */ = {
isa = PBXGroup;
children = (
08397E222B9EE8F400DFDD02 /* InfoDataModel.swift */,
);
path = Model;
sourceTree = "<group>";
};
08F1AB632BA083F500AEA0CA /* Info */ = {
isa = PBXGroup;
children = (
08397E242B9EEE1300DFDD02 /* InfoListView.swift */,
0871C61C2BA05F44000B620D /* InfosView.swift */,
08F1AB652BA0A7E100AEA0CA /* InfosFilterWithCateView.swift */,
0871C6182BA040E5000B620D /* InfoRowView.swift */,
08397E282B9F0A9100DFDD02 /* EditInfoView.swift */,
);
path = Info;
sourceTree = "<group>";
};
08F1AB642BA0840400AEA0CA /* Category */ = {
isa = PBXGroup;
children = (
08397E2E2B9F353B00DFDD02 /* CategoryListView.swift */,
0871C61A2BA04D23000B620D /* CategoryRowView.swift */,
08397E2C2B9F10AD00DFDD02 /* EditCategoryView.swift */,
);
path = Category;
sourceTree = "<group>";
};
/* End PBXGroup section */

/* Begin PBXNativeTarget section */
Expand All @@ -1364,6 +1393,7 @@
08448F4D279E8CA400B61353 /* Ink */,
08ED80152B9C54DE0069B7EC /* SMNetwork */,
08397E312B9F39C100DFDD02 /* SwiftSoup */,
08F1AB602BA0821900AEA0CA /* CodeEditor */,
);
productName = SwiftPamphletApp;
productReference = 086A5F032744E88E00FECE02 /* 戴铭的开发小册子.app */;
Expand Down Expand Up @@ -1402,6 +1432,7 @@
08448F4C279E8CA400B61353 /* XCRemoteSwiftPackageReference "ink" */,
08ED80142B9C54DE0069B7EC /* XCLocalSwiftPackageReference "SwiftPamphletApp/SharePackage/SMNetwork" */,
08397E302B9F39C100DFDD02 /* XCRemoteSwiftPackageReference "SwiftSoup" */,
08F1AB5F2BA0821900AEA0CA /* XCRemoteSwiftPackageReference "CodeEditor" */,
);
productRefGroup = 086A5F042744E88E00FECE02 /* Products */;
projectDirPath = "";
Expand Down Expand Up @@ -1668,6 +1699,7 @@
086A5F3A2744EDA500FECE02 /* APIRequest.swift in Sources */,
086A5F522744EF4C00FECE02 /* ViewComponet.swift in Sources */,
086A5F672754C27900FECE02 /* DBHandler.swift in Sources */,
08F1AB662BA0A7E100AEA0CA /* InfosFilterWithCateView.swift in Sources */,
08BE637927CDCFD9002BC6A8 /* DataSortingListView.swift in Sources */,
08BE636E27C8D6FD002BC6A8 /* PlayLazyVGridAndLazyHGridView.swift in Sources */,
08522BE227CF52ED005FF059 /* PlayColor.swift in Sources */,
Expand Down Expand Up @@ -1958,6 +1990,14 @@
minimumVersion = 4.0.0;
};
};
08F1AB5F2BA0821900AEA0CA /* XCRemoteSwiftPackageReference "CodeEditor" */ = {
isa = XCRemoteSwiftPackageReference;
repositoryURL = "https://github.com/ZeeZide/CodeEditor.git";
requirement = {
kind = upToNextMajorVersion;
minimumVersion = 1.2.2;
};
};
/* End XCRemoteSwiftPackageReference section */

/* Begin XCSwiftPackageProductDependency section */
Expand Down Expand Up @@ -1995,6 +2035,11 @@
isa = XCSwiftPackageProductDependency;
productName = SMNetwork;
};
08F1AB602BA0821900AEA0CA /* CodeEditor */ = {
isa = XCSwiftPackageProductDependency;
package = 08F1AB5F2BA0821900AEA0CA /* XCRemoteSwiftPackageReference "CodeEditor" */;
productName = CodeEditor;
};
/* End XCSwiftPackageProductDependency section */
};
rootObject = 086A5EFB2744E88E00FECE02 /* Project object */;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"originHash" : "eb1bc0d69758f54e9355dfcb786f3dffd822e69deee747fba303fc1467b42e40",
"originHash" : "db2ef4a661890fce166f443fd797e0492fd1c68e7b7be7ed3327c121a2649f2a",
"pins" : [
{
"identity" : "attributedtext",
Expand All @@ -10,6 +10,15 @@
"version" : "1.0.0"
}
},
{
"identity" : "codeeditor",
"kind" : "remoteSourceControl",
"location" : "https://github.com/ZeeZide/CodeEditor.git",
"state" : {
"revision" : "180bde07b44dea839b32873bd8586ba146fa9106",
"version" : "1.2.2"
}
},
{
"identity" : "combine-schedulers",
"kind" : "remoteSourceControl",
Expand All @@ -19,6 +28,15 @@
"version" : "0.5.3"
}
},
{
"identity" : "highlightr",
"kind" : "remoteSourceControl",
"location" : "https://github.com/raspu/Highlightr",
"state" : {
"revision" : "93199b9e434f04bda956a613af8f571933f9f037",
"version" : "2.1.2"
}
},
{
"identity" : "ink",
"kind" : "remoteSourceControl",
Expand Down
7 changes: 7 additions & 0 deletions SwiftPamphletApp/Core/FundationFunction.swift
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,13 @@ func loadFileContent(path: String) -> String {
// decoder
// extension

extension NSPasteboard {
func copyText(_ text: String) {
self.clearContents()
self.setString(text, forType: .string)
}
}

// base64
extension String {
func base64Encoded() -> String? {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import SwiftUI
import SwiftData
import SwiftSoup
import CodeEditor

struct EditInfoView: View {
@Environment(\.modelContext) var modelContext
Expand All @@ -25,12 +26,19 @@ struct EditInfoView: View {
Form {
Section {
TextField("标题", text: $info.name)
TextField("地址", text: $info.url)
.onChange(of: info.url) { oldValue, newValue in
Task {
await fetchTitleFromUrl(urlString:newValue)
HStack {
TextField("地址", text: $info.url)
.onChange(of: info.url) { oldValue, newValue in
Task {
await fetchTitleFromUrl(urlString:newValue)
}
}
}
Button {
gotoWebBrowser(urlStr: info.url)
} label: {
Label("浏览器打开", systemImage: "safari")
} // end Button
}
}

Section("选择分类") {
Expand All @@ -54,8 +62,8 @@ struct EditInfoView: View {
}
}

Section("描述") {
TextField("详细描述", text: $info.des, axis: .vertical)
Section("备注") {
TextEditor(text: $info.des)
}
}
.navigationTitle("编辑资料")
Expand Down
86 changes: 86 additions & 0 deletions SwiftPamphletApp/InfoOrganizer/Info/InfoListView.swift
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
}

}


36 changes: 36 additions & 0 deletions SwiftPamphletApp/InfoOrganizer/Info/InfosFilterWithCateView.swift
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)
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ struct InfosView: View {
} else {
info.name.localizedStandardContains(searchString)
|| info.url.localizedStandardContains(searchString)
|| info.des.localizedStandardContains(searchString)
|| info.des.localizedStandardContains(searchString)
}
}, sort: sortOrder)

Expand All @@ -30,9 +30,6 @@ struct InfosView: View {
var body: some View {
List(selection: $selectInfo) {
ForEach(infos) { info in
// NavigationLink(value: info) {
//
// }
InfoRowView(info: info, selectedInfo: selectInfo)
.tag(info)
}
Expand Down
Loading

0 comments on commit a4cbe2c

Please sign in to comment.