Skip to content

Commit 50cf898

Browse files
committed
NavigationSplit 新三栏结构
1 parent 93e853d commit 50cf898

14 files changed

+225
-87
lines changed

SwiftPamphletApp.xcodeproj/project.pbxproj

+16-4
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,11 @@
2929
083554E327572BB60095E0EE /* AppVM.swift in Sources */ = {isa = PBXBuildFile; fileRef = 083554E227572BB60095E0EE /* AppVM.swift */; };
3030
08397E232B9EE8F400DFDD02 /* InfoDataModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 08397E222B9EE8F400DFDD02 /* InfoDataModel.swift */; };
3131
08397E252B9EEE1300DFDD02 /* InfoListView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 08397E242B9EEE1300DFDD02 /* InfoListView.swift */; };
32-
08397E272B9EF37600DFDD02 /* InfosView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 08397E262B9EF37600DFDD02 /* InfosView.swift */; };
3332
08397E292B9F0A9100DFDD02 /* EditInfoView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 08397E282B9F0A9100DFDD02 /* EditInfoView.swift */; };
3433
08397E2D2B9F10AD00DFDD02 /* EditCategoryView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 08397E2C2B9F10AD00DFDD02 /* EditCategoryView.swift */; };
3534
08397E2F2B9F353B00DFDD02 /* CategoryListView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 08397E2E2B9F353B00DFDD02 /* CategoryListView.swift */; };
3635
08397E322B9F39C100DFDD02 /* SwiftSoup in Frameworks */ = {isa = PBXBuildFile; productRef = 08397E312B9F39C100DFDD02 /* SwiftSoup */; };
36+
08397E342BA0178500DFDD02 /* DetailLink.swift in Sources */ = {isa = PBXBuildFile; fileRef = 08397E332BA0178500DFDD02 /* DetailLink.swift */; };
3737
084417752B99B9060049297D /* HomeView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 084417742B99B9060049297D /* HomeView.swift */; };
3838
084417772B99BA3F0049297D /* SidebarView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 084417762B99BA3F0049297D /* SidebarView.swift */; };
3939
084417792B99BE720049297D /* DataLink.swift in Sources */ = {isa = PBXBuildFile; fileRef = 084417782B99BE720049297D /* DataLink.swift */; };
@@ -191,6 +191,9 @@
191191
086A5F642754C14F00FECE02 /* PlayTextView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 086A5F632754C14F00FECE02 /* PlayTextView.swift */; };
192192
086A5F672754C27900FECE02 /* DBHandler.swift in Sources */ = {isa = PBXBuildFile; fileRef = 086A5F662754C27900FECE02 /* DBHandler.swift */; };
193193
086A5F6A2755F3BE00FECE02 /* repos.json in Resources */ = {isa = PBXBuildFile; fileRef = 086A5F692755F3BE00FECE02 /* repos.json */; };
194+
0871C6192BA040E5000B620D /* InfoRowView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0871C6182BA040E5000B620D /* InfoRowView.swift */; };
195+
0871C61B2BA04D23000B620D /* CategoryRowView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0871C61A2BA04D23000B620D /* CategoryRowView.swift */; };
196+
0871C61D2BA05F44000B620D /* InfosView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0871C61C2BA05F44000B620D /* InfosView.swift */; };
194197
088EE8F527BD24E000764525 /* PlayLinkView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 088EE8F427BD24E000764525 /* PlayLinkView.swift */; };
195198
0896FB9027BA39B100676B7F /* PlayButtonView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0896FB8F27BA39B100676B7F /* PlayButtonView.swift */; };
196199
0896FB9227BA486900676B7F /* 145.md in Resources */ = {isa = PBXBuildFile; fileRef = 0896FB9127BA486900676B7F /* 145.md */; };
@@ -289,10 +292,10 @@
289292
083554E227572BB60095E0EE /* AppVM.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppVM.swift; sourceTree = "<group>"; };
290293
08397E222B9EE8F400DFDD02 /* InfoDataModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InfoDataModel.swift; sourceTree = "<group>"; };
291294
08397E242B9EEE1300DFDD02 /* InfoListView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InfoListView.swift; sourceTree = "<group>"; };
292-
08397E262B9EF37600DFDD02 /* InfosView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InfosView.swift; sourceTree = "<group>"; };
293295
08397E282B9F0A9100DFDD02 /* EditInfoView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EditInfoView.swift; sourceTree = "<group>"; };
294296
08397E2C2B9F10AD00DFDD02 /* EditCategoryView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EditCategoryView.swift; sourceTree = "<group>"; };
295297
08397E2E2B9F353B00DFDD02 /* CategoryListView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CategoryListView.swift; sourceTree = "<group>"; };
298+
08397E332BA0178500DFDD02 /* DetailLink.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DetailLink.swift; sourceTree = "<group>"; };
296299
084417742B99B9060049297D /* HomeView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HomeView.swift; sourceTree = "<group>"; };
297300
084417762B99BA3F0049297D /* SidebarView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SidebarView.swift; sourceTree = "<group>"; };
298301
084417782B99BE720049297D /* DataLink.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DataLink.swift; sourceTree = "<group>"; };
@@ -450,6 +453,9 @@
450453
086A5F632754C14F00FECE02 /* PlayTextView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PlayTextView.swift; sourceTree = "<group>"; };
451454
086A5F662754C27900FECE02 /* DBHandler.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DBHandler.swift; sourceTree = "<group>"; };
452455
086A5F692755F3BE00FECE02 /* repos.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; name = repos.json; path = SwiftPamphletApp/Resource/News/repos.json; sourceTree = SOURCE_ROOT; };
456+
0871C6182BA040E5000B620D /* InfoRowView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InfoRowView.swift; sourceTree = "<group>"; };
457+
0871C61A2BA04D23000B620D /* CategoryRowView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CategoryRowView.swift; sourceTree = "<group>"; };
458+
0871C61C2BA05F44000B620D /* InfosView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InfosView.swift; sourceTree = "<group>"; };
453459
0886702B27F804010001EA81 /* SwiftPamphletApp-Bridging-Header.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "SwiftPamphletApp-Bridging-Header.h"; sourceTree = "<group>"; };
454460
088EE8F427BD24E000764525 /* PlayLinkView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PlayLinkView.swift; sourceTree = "<group>"; };
455461
0896FB8F27BA39B100676B7F /* PlayButtonView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PlayButtonView.swift; sourceTree = "<group>"; };
@@ -571,8 +577,10 @@
571577
children = (
572578
08397E222B9EE8F400DFDD02 /* InfoDataModel.swift */,
573579
08397E242B9EEE1300DFDD02 /* InfoListView.swift */,
580+
0871C61C2BA05F44000B620D /* InfosView.swift */,
581+
0871C6182BA040E5000B620D /* InfoRowView.swift */,
574582
08397E2E2B9F353B00DFDD02 /* CategoryListView.swift */,
575-
08397E262B9EF37600DFDD02 /* InfosView.swift */,
583+
0871C61A2BA04D23000B620D /* CategoryRowView.swift */,
576584
08397E282B9F0A9100DFDD02 /* EditInfoView.swift */,
577585
08397E2C2B9F10AD00DFDD02 /* EditCategoryView.swift */,
578586
);
@@ -594,6 +602,7 @@
594602
084417742B99B9060049297D /* HomeView.swift */,
595603
084417762B99BA3F0049297D /* SidebarView.swift */,
596604
084417782B99BE720049297D /* DataLink.swift */,
605+
08397E332BA0178500DFDD02 /* DetailLink.swift */,
597606
);
598607
path = HomeUI;
599608
sourceTree = "<group>";
@@ -1593,6 +1602,7 @@
15931602
buildActionMask = 2147483647;
15941603
files = (
15951604
08BE633727BF6CBC002BC6A8 /* PlayTextFieldView.swift in Sources */,
1605+
0871C61B2BA04D23000B620D /* CategoryRowView.swift in Sources */,
15961606
08522BF227D1D49B005FF059 /* PlayCanvas.swift in Sources */,
15971607
08BE634827C4B6A2002BC6A8 /* PlayStackView.swift in Sources */,
15981608
08BE636227C878EC002BC6A8 /* PlayLazyVStackAndLazyHStackView.swift in Sources */,
@@ -1606,6 +1616,7 @@
16061616
084417792B99BE720049297D /* DataLink.swift in Sources */,
16071617
08522BEB27CF7744005FF059 /* PlayKeyboard.swift in Sources */,
16081618
08C3BBA427CF1B7B00ACF0FE /* PlayPickerView.swift in Sources */,
1619+
0871C61D2BA05F44000B620D /* InfosView.swift in Sources */,
16091620
08448F4B279E872B00B61353 /* GuideView.swift in Sources */,
16101621
08397E2D2B9F10AD00DFDD02 /* EditCategoryView.swift in Sources */,
16111622
08BE635027C4C0F2002BC6A8 /* PlayFormView.swift in Sources */,
@@ -1623,9 +1634,11 @@
16231634
08AEAEF3277F09FA00B969E2 /* NavView.swift in Sources */,
16241635
086A5F352744ED9600FECE02 /* IssueView.swift in Sources */,
16251636
08522BF027CF9FFA005FF059 /* PlayAnimation.swift in Sources */,
1637+
08397E342BA0178500DFDD02 /* DetailLink.swift in Sources */,
16261638
08AEAEDD277EA64900B969E2 /* DBDevNoti.swift in Sources */,
16271639
08BE635E27C72F50002BC6A8 /* PlayNavigationView.swift in Sources */,
16281640
08448F0D2799035600B61353 /* PlaySecurity.swift in Sources */,
1641+
0871C6192BA040E5000B620D /* InfoRowView.swift in Sources */,
16291642
086A5F442744EE2800FECE02 /* SwiftPamphletAppConfig.swift in Sources */,
16301643
08C411F427951181006FC340 /* PlaySyntax.swift in Sources */,
16311644
083554E12756503B0095E0EE /* AnimateLayout.swift in Sources */,
@@ -1636,7 +1649,6 @@
16361649
08522BD827CF344B005FF059 /* PlaySliderView.swift in Sources */,
16371650
086A5F362744ED9600FECE02 /* RepoView.swift in Sources */,
16381651
086A5F302744ED8600FECE02 /* IssuesListFromCustomView.swift in Sources */,
1639-
08397E272B9EF37600DFDD02 /* InfosView.swift in Sources */,
16401652
08C3BB7E27CE3EBD00ACF0FE /* PlayTabView.swift in Sources */,
16411653
084417752B99B9060049297D /* HomeView.swift in Sources */,
16421654
08449034279F6D0D00B61353 /* RepoWebView.swift in Sources */,

SwiftPamphletApp/HomeUI/DataLink.swift

+6-6
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@ struct DataLink: Identifiable {
1414
var children: [DataLink]?
1515

1616
@ViewBuilder
17-
static func viewToShow(for title: String?) -> some View {
17+
static func viewToShow(for title: String?, selectInfo:Binding<IOInfo?>) -> some View {
1818
switch title {
1919
case "资料整理":
20-
InfoListView()
20+
InfoListView(selectInfo: selectInfo)
2121
case "库动态":
2222
ExploreRepoListView(showAsGroup: false)
2323
case "开发者":
@@ -52,12 +52,12 @@ extension DataLink {
5252
DataLink(title: "动态", imageName: "", children: [
5353
DataLink(title: "资料整理", imageName: "p11")
5454
]),
55-
DataLink(title: "Github", imageName: "", children: [
55+
// DataLink(title: "Github", imageName: "", children: [
5656
// DataLink(title: "库动态", imageName: "p6"),
5757
// DataLink(title: "开发者", imageName: "p5"),
58-
DataLink(title: "探索库", imageName: "p24"),
59-
DataLink(title: "库存档", imageName: "p25")
60-
]),
58+
// DataLink(title: "探索库", imageName: "p24"),
59+
// DataLink(title: "库存档", imageName: "p25")
60+
// ]),
6161
DataLink(title: "Swift指南", imageName: "", children: [
6262
DataLink(title: "语法速查", imageName: "p23"),
6363
DataLink(title: "特性", imageName: "p10"),
+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
//
2+
// DetailLink.swift
3+
// SwiftPamphletApp
4+
//
5+
// Created by Ming Dai on 2024/3/12.
6+
//
7+
8+
import SwiftUI
9+
10+
struct DetailLink {
11+
12+
@ViewBuilder
13+
static func viewToShow(for title: String?, selectInfo:IOInfo) -> some View {
14+
switch title {
15+
case "资料":
16+
EditInfoView(info: selectInfo)
17+
default:
18+
Text("请选择")
19+
}
20+
}
21+
}

SwiftPamphletApp/HomeUI/HomeView.swift

+15-2
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,25 @@ import SwiftUI
1010
struct HomeView: View {
1111
@State var appVM = AppVM()
1212
@State private var selectedDataLinkString: String?
13+
@State private var selectInfo: IOInfo? = nil
1314

1415
var body: some View {
1516
NavigationSplitView {
16-
SidebarView(selectedDataLinkString: $selectedDataLinkString)
17+
SidebarView(selectedDataLinkString: $selectedDataLinkString, selectInfo: $selectInfo)
18+
} content: {
19+
if let link = selectedDataLinkString {
20+
DataLink.viewToShow(for: link, selectInfo: $selectInfo)
21+
} else {
22+
Text("请选择")
23+
}
1724
} detail: {
18-
DataLink.viewToShow(for: selectedDataLinkString)
25+
if let info = selectInfo {
26+
DetailLink.viewToShow(for: "资料", selectInfo: info)
27+
} else {
28+
Text("请选择")
29+
}
30+
// Text("请选择")
31+
// DataLink.viewToShow(for: selectedDataLinkString)
1932
}
2033
.environment(appVM)
2134
}

SwiftPamphletApp/HomeUI/SidebarView.swift

+2-4
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,9 @@ import SwiftUI
1010
struct SidebarView: View {
1111
@Binding var selectedDataLinkString: String?
1212

13+
@Binding var selectInfo: IOInfo?
14+
1315
var body: some View {
14-
// List(DataLink.dataLinks, children: \.children, selection: $selectedDataLinkString) { link in
15-
// SideBarLabel(title: link.title, imageName: link.imageName)
16-
// .tag(link.title)
17-
// }
1816
List(selection: $selectedDataLinkString, content: {
1917
ForEach(DataLink.dataLinks) { link in
2018
Section {

SwiftPamphletApp/InfoOrganizer/CategoryListView.swift

+3-9
Original file line numberDiff line numberDiff line change
@@ -11,21 +11,15 @@ import SwiftData
1111
struct CategoryListView: View {
1212
@Environment(\.modelContext) var modelContext
1313
@Query var cates: [IOCategory]
14+
@State var selectCate: IOCategory?
1415

1516
var body: some View {
16-
List {
17+
List(selection: $selectCate) {
1718
ForEach(cates) { cate in
1819
NavigationLink(value: cate) {
19-
Text(cate.name)
20+
CategoryRowView(cate: cate, selectedCate: selectCate)
2021
}
2122
}
22-
.onDelete(perform: deleteCates(at:))
23-
}
24-
}
25-
func deleteCates(at offsets: IndexSet) {
26-
for offset in offsets {
27-
let cate = cates[offset]
28-
modelContext.delete(cate)
2923
}
3024
}
3125
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
//
2+
// CategoryRowView.swift
3+
// SwiftPamphletApp
4+
//
5+
// Created by Ming Dai on 2024/3/12.
6+
//
7+
8+
import SwiftUI
9+
10+
struct CategoryRowView: View {
11+
@State var cate: IOCategory
12+
let selectedCate: IOCategory?
13+
14+
var cateColor: Color {
15+
selectedCate == cate ? Color.white : Color.accentColor
16+
}
17+
18+
var body: some View {
19+
HStack {
20+
TextField("name", text: $cate.name)
21+
Spacer()
22+
Text("\(cate.infos?.count ?? 0)")
23+
}
24+
.swipeActions {
25+
Button(role: .destructive) {
26+
IOCategory.delete(cate)
27+
} label: {
28+
Label("删除", systemImage: "trash")
29+
}
30+
}
31+
.contextMenu {
32+
Button("删除") {
33+
IOCategory.delete(cate)
34+
}
35+
}
36+
37+
}
38+
}
39+

SwiftPamphletApp/InfoOrganizer/EditCategoryView.swift

+6-4
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,13 @@ struct EditCategoryView: View {
1313

1414
var body: some View {
1515
VStack {
16-
Form {
17-
TextField("分类名", text: $cate.name)
16+
if cate.name != "unavailable.com" {
17+
Form {
18+
TextField("分类名", text: $cate.name)
19+
}
20+
.navigationTitle("编辑分类")
21+
.padding(30)
1822
}
19-
.navigationTitle("编辑分类")
20-
.padding(30)
2123
CategoryListView()
2224
Spacer()
2325
}

SwiftPamphletApp/InfoOrganizer/EditInfoView.swift

+27-10
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,15 @@ import SwiftData
1010
import SwiftSoup
1111

1212
struct EditInfoView: View {
13+
@Environment(\.modelContext) var modelContext
1314
@Bindable var info: IOInfo
14-
@Binding var navigationPath: NavigationPath
1515

1616
@Query(sort: [
17-
SortDescriptor(\IOCategory.updateDate)
17+
SortDescriptor(\IOCategory.updateDate, order: .reverse)
1818
]) var categories: [IOCategory]
1919

20-
@Environment(\.modelContext) var modelContext
20+
@State var isShowInspector = false
21+
@State var cate:IOCategory? = nil
2122

2223
var body: some View {
2324
VStack {
@@ -44,26 +45,42 @@ struct EditInfoView: View {
4445
}
4546
}
4647
}
47-
Button("添加和管理分类", action: addCate)
48+
.onChange(of: info.category) { oldValue, newValue in
49+
info.category?.updateDate = Date.now
50+
}
51+
HStack {
52+
Button("添加分类", action: addCate)
53+
Button("管理分类", action: manageCate)
54+
}
4855
}
4956

5057
Section("描述") {
5158
TextField("详细描述", text: $info.des, axis: .vertical)
5259
}
5360
}
5461
.navigationTitle("编辑资料")
55-
.navigationDestination(for: IOCategory.self) { cate in
56-
EditCategoryView(cate: cate)
57-
}
5862
.padding(30)
63+
.inspector(isPresented: $isShowInspector) {
64+
EditCategoryView(cate: cate ?? IOCategory(name: "unavailable.com", createDate: Date.now, updateDate: Date.now))
65+
}
66+
.toolbar {
67+
Button("关闭", systemImage: "sidebar.right") {
68+
isShowInspector.toggle()
69+
}
70+
71+
}
5972
Spacer()
6073
}
6174
}
6275
func addCate() {
63-
let cate = IOCategory(name: "", createDate: Date.now, updateDate: Date.now)
64-
modelContext.insert(cate)
65-
navigationPath.append(cate)
76+
cate = IOCategory(name: "", createDate: Date.now, updateDate: Date.now)
77+
modelContext.insert(cate!)
78+
isShowInspector = true
6679
}
80+
func manageCate() {
81+
isShowInspector.toggle()
82+
}
83+
6784
func fetchTitleFromUrl(urlString: String) async {
6885
guard let url = URL(string: urlString) else {
6986
return

SwiftPamphletApp/InfoOrganizer/InfoDataModel.swift

+17-5
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,14 @@ import Foundation
99
import SwiftData
1010

1111
@Model
12-
class IOInfo {
12+
final class IOInfo {
1313
var name: String = ""
1414
var url: String = ""
1515
var des: String = ""
1616
var category: IOCategory?
1717

18-
var createDate: Date
19-
var updateDate: Date
18+
var createDate: Date = Date.now
19+
var updateDate: Date = Date.now
2020

2121
init(name: String,
2222
url: String,
@@ -32,15 +32,21 @@ class IOInfo {
3232
self.createDate = createDate
3333
self.updateDate = updateDate
3434
}
35+
36+
static func delete(_ info: IOInfo) {
37+
if let context = info.modelContext {
38+
context.delete(info)
39+
}
40+
}
3541
}
3642

3743
@Model
3844
class IOCategory {
3945
var name: String = ""
4046
var infos: [IOInfo]? = [IOInfo]()
4147

42-
var createDate: Date
43-
var updateDate: Date
48+
var createDate: Date = Date.now
49+
var updateDate: Date = Date.now
4450

4551
init(name: String,
4652
createDate: Date,
@@ -50,4 +56,10 @@ class IOCategory {
5056
self.createDate = createDate
5157
self.updateDate = updateDate
5258
}
59+
60+
static func delete(_ cate: IOCategory) {
61+
if let context = cate.modelContext {
62+
context.delete(cate)
63+
}
64+
}
5365
}

0 commit comments

Comments
 (0)