Skip to content

Commit

Permalink
完善无数据的页面
Browse files Browse the repository at this point in the history
  • Loading branch information
ming1016 committed May 8, 2024
1 parent 62c937c commit 52a7dec
Show file tree
Hide file tree
Showing 14 changed files with 229 additions and 64 deletions.
11 changes: 7 additions & 4 deletions SwiftPamphletApp.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,7 @@
0887A59A2BA28F6D00131359 /* CSGuideView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0887A5992BA28F6D00131359 /* CSGuideView.swift */; };
0896FB9227BA486900676B7F /* Button(ap).md in Resources */ = {isa = PBXBuildFile; fileRef = 0896FB9127BA486900676B7F /* Button(ap).md */; };
08A4FDC227B25A140068E5BC /* @dynamicMemberLookup动态成员查询(ap).md in Resources */ = {isa = PBXBuildFile; fileRef = 08A4FDC127B25A140068E5BC /* @dynamicMemberLookup动态成员查询(ap).md */; };
08A7FF312BEB02EA00E12E5A /* GithubAccessTokenView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 08A7FF302BEB02EA00E12E5A /* GithubAccessTokenView.swift */; };
08A9E1A22BC25D0700A73764 /* ViewComponentMarkdown.swift in Sources */ = {isa = PBXBuildFile; fileRef = 08A9E1A12BC25D0700A73764 /* ViewComponentMarkdown.swift */; };
08AEAEF1277F09D000B969E2 /* IntroView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 08AEAEF0277F09D000B969E2 /* IntroView.swift */; };
08AEAEFA277F3C7400B969E2 /* css.html in Resources */ = {isa = PBXBuildFile; fileRef = 08AEAEF9277F3C7400B969E2 /* css.html */; };
Expand Down Expand Up @@ -391,6 +392,7 @@
0887A5992BA28F6D00131359 /* CSGuideView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CSGuideView.swift; sourceTree = "<group>"; };
0896FB9127BA486900676B7F /* Button(ap).md */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = net.daringfireball.markdown; path = "Button(ap).md"; sourceTree = "<group>"; };
08A4FDC127B25A140068E5BC /* @dynamicMemberLookup动态成员查询(ap).md */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = net.daringfireball.markdown; path = "@dynamicMemberLookup动态成员查询(ap).md"; sourceTree = "<group>"; };
08A7FF302BEB02EA00E12E5A /* GithubAccessTokenView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GithubAccessTokenView.swift; sourceTree = "<group>"; };
08A9E1A12BC25D0700A73764 /* ViewComponentMarkdown.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewComponentMarkdown.swift; sourceTree = "<group>"; };
08AEAEF0277F09D000B969E2 /* IntroView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = IntroView.swift; sourceTree = "<group>"; };
08AEAEF9277F3C7400B969E2 /* css.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = css.html; sourceTree = "<group>"; };
Expand Down Expand Up @@ -1027,6 +1029,7 @@
isa = PBXGroup;
children = (
08ED801B2B9D1EEC0069B7EC /* SettingView.swift */,
08A7FF302BEB02EA00E12E5A /* GithubAccessTokenView.swift */,
);
path = Setting;
sourceTree = "<group>";
Expand Down Expand Up @@ -1380,6 +1383,7 @@
08069CAD2BDE7A6B00D48E24 /* GuideDetailView.swift in Sources */,
08AEAEF1277F09D000B969E2 /* IntroView.swift in Sources */,
08397E292B9F0A9100DFDD02 /* EditInfoView.swift in Sources */,
08A7FF312BEB02EA00E12E5A /* GithubAccessTokenView.swift in Sources */,
086A5F372744ED9600FECE02 /* UserView.swift in Sources */,
086A5F522744EF4C00FECE02 /* ViewComponent.swift in Sources */,
0805F4962BAAABEA0008BB52 /* ViewStyle.swift in Sources */,
Expand Down Expand Up @@ -1519,8 +1523,7 @@
ASSETCATALOG_COMPILER_INCLUDE_ALL_APPICON_ASSETS = YES;
CLANG_ENABLE_MODULES = YES;
CODE_SIGN_ENTITLEMENTS = SwiftPamphletApp/SwiftPamphletAppDebug.entitlements;
CODE_SIGN_IDENTITY = "-";
"CODE_SIGN_IDENTITY[sdk=macosx*]" = "Apple Development";
CODE_SIGN_IDENTITY = "Apple Development";
CODE_SIGN_STYLE = Automatic;
COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = 1;
Expand All @@ -1547,6 +1550,7 @@
OTHER_SWIFT_FLAGS = "";
PRODUCT_BUNDLE_IDENTIFIER = com.starming.SwiftPamphletAppByMing;
PRODUCT_NAME = "戴铭的开发小册子";
PROVISIONING_PROFILE_SPECIFIER = "";
SWIFT_EMIT_LOC_STRINGS = YES;
SWIFT_OBJC_BRIDGING_HEADER = "";
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
Expand All @@ -1562,8 +1566,7 @@
ASSETCATALOG_COMPILER_INCLUDE_ALL_APPICON_ASSETS = YES;
CLANG_ENABLE_MODULES = YES;
CODE_SIGN_ENTITLEMENTS = SwiftPamphletApp/SwiftPamphletApp.entitlements;
CODE_SIGN_IDENTITY = "-";
"CODE_SIGN_IDENTITY[sdk=macosx*]" = "Apple Development";
CODE_SIGN_IDENTITY = "Apple Development";
CODE_SIGN_STYLE = Automatic;
COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = 1;
Expand Down
2 changes: 0 additions & 2 deletions SwiftPamphletApp/App/IntroView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,8 @@ struct IntroView: View {
Text("Swift Pamphlet App").gradientTitle(color: .mint)
}


HStack {
Text("一本活的开发手册")
Link("GitHub 地址", destination: URL(string: "https://github.com/ming1016/SwiftPamphletApp")!)
}
if let version = Bundle.main.infoDictionary?["CFBundleShortVersionString"] as? String {
Text("版本\(version)").font(.footnote)
Expand Down
20 changes: 17 additions & 3 deletions SwiftPamphletApp/GitHubAPIUI/Developer/DeveloperListView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ struct DeveloperListView: View {
@Environment(\.modelContext) var modelContext
@Binding var selectDev: DeveloperModel?
@Query(DeveloperModel.all) var devs: [DeveloperModel]
// 测试无数据用
// @Query(filter: #Predicate<DeveloperModel> { dev in
// dev.name.starts(with: "apple")
// }) var devs: [DeveloperModel]

var body: some View {
List(selection: $selectDev) {
Expand Down Expand Up @@ -61,18 +65,28 @@ struct DeveloperListView: View {
DeveloperModel.delete(dev)
}
}


}
}
.listStyle(.inset)
.alternatingRowBackgrounds()
.toolbar(content: {
ToolbarItem(placement: .navigation) {
Button("添加开发者", systemImage: "plus", action: addDev)
.keyboardShortcut(KeyEquivalent("a"), modifiers: .option)
}
})
.overlay {
if devs.isEmpty {
ContentUnavailableView {
Label("无数据", systemImage: "person.fill.questionmark")
} description: {
Text("点击下方按钮添加开发者或仓库")
} actions: {
Button("新增") {
addDev()
}
}
}
}
}

func addDev() {
Expand Down
55 changes: 37 additions & 18 deletions SwiftPamphletApp/GitHubAPIUI/Developer/EditDeveloper.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,36 +17,34 @@ struct EditDeveloper: View {
@State var repoVM: APIRepoVM
@State var userVM: APIUserVM

@State var needSetGithubAccessToken = false

var body: some View {
Form {
HStack {
TextField("用户名:", text: $dev.name, prompt: Text("输入 Github 用户名 dev 或仓库名 dev/repo"))
.textFieldStyle(RoundedBorderTextFieldStyle())
.onChange(of: dev.name) { oldValue, newValue in
let dn = dev.name.components(separatedBy: "/")
if dn.count > 1 {
repoVM = APIRepoVM(name: dev.name)
Task {
await repoVM.updateAllData()
}

dev.repoName = dn.last ?? ""
dev.repoOwner = dn.first ?? ""
} else {
userVM = APIUserVM(name: dev.name)
Task {
await userVM.updateAllData()
}

dev.repoName = ""
dev.repoOwner = ""
}
updateReq()
}
TextField("描述:", text: $dev.des)
.textFieldStyle(RoundedBorderTextFieldStyle())
}
}
.padding(EdgeInsets(top: 10, leading: 10, bottom: 0, trailing: 10))
.sheet(isPresented: $needSetGithubAccessToken) {
VStack {
GithubAccessTokenView()
Button {
updateReq()
needSetGithubAccessToken = false
} label: {
Text("完成")
}
}
.padding(20)

}

if dev.name.components(separatedBy: "/").count > 1 {
repoEventView()
Expand All @@ -55,6 +53,27 @@ struct EditDeveloper: View {
}
}

func updateReq() {
let dn = dev.name.components(separatedBy: "/")
if dn.count > 1 {
repoVM = APIRepoVM(name: dev.name)
Task {
await repoVM.updateAllData()
}

dev.repoName = dn.last ?? ""
dev.repoOwner = dn.first ?? ""
} else {
userVM = APIUserVM(name: dev.name)
Task {
await userVM.updateAllData()
}

dev.repoName = ""
dev.repoOwner = ""
}
}

@ViewBuilder
func repoEventView() -> some View {
HStack {
Expand Down
4 changes: 3 additions & 1 deletion SwiftPamphletApp/HomeUI/DataLink.swift
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,10 @@ struct DataLink: Identifiable {
if SPC.gitHubAccessToken.isEmpty == false || SPC.githubAccessToken().isEmpty == false {
EditDeveloper(dev: dev, repoVM: APIRepoVM(name: dev.name), userVM: APIUserVM(name: dev.name))
} else {
Text("请在设置里写上 Github 的 access token")
// Text("请在设置里写上 Github 的 access token")
EditDeveloper(dev: dev, repoVM: APIRepoVM(name: dev.name), userVM: APIUserVM(name: dev.name), needSetGithubAccessToken: true)
}

} else {
IntroView()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@
import SwiftUI
import SwiftData
import InfoOrganizer
import SMDate

struct ArchivedInfosView: View {
@Environment(\.modelContext) var modelContext
@Query var infos: [IOInfo]
@Binding var selectInfo: IOInfo?
@Binding var limit: Int
Expand All @@ -18,6 +20,12 @@ struct ArchivedInfosView: View {
var fd = FetchDescriptor<IOInfo>(predicate: #Predicate { info in
info.isArchived == true
}, sortBy: [SortDescriptor(\IOInfo.updateDate, order: .reverse)])

// 测试用
// var fd = FetchDescriptor<IOInfo>(predicate: #Predicate { info in
// info.isArchived == true && info.name.starts(with: "apple")
// }, sortBy: [SortDescriptor(\IOInfo.updateDate, order: .reverse)])

fd.fetchLimit = limit.wrappedValue
_infos = Query(fd)
self._selectInfo = selectInfo
Expand All @@ -37,7 +45,27 @@ struct ArchivedInfosView: View {
}
}
}
}
} // end List
.overlay {
if infos.isEmpty {
ContentUnavailableView {
Label("无归档", systemImage: "archivebox")
} description: {
Text("点击下方按钮添加一个归档资料")
} actions: {
Button("新增") {
addInfo()
}
}
}
} // end overlay
}

func addInfo() {
let info = IOInfo(name: "简单记录 - \(SMDate.nowDateString())", url: "", des: "", relateName: "")
info.isArchived = true
modelContext.insert(info)
selectInfo = info
}
}

26 changes: 26 additions & 0 deletions SwiftPamphletApp/InfoOrganizer/Info/InfosView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import SwiftUI
import SwiftData
import InfoOrganizer
import SMDate

struct InfosView: View {
@Environment(\.modelContext) var modelContext
Expand All @@ -33,6 +34,12 @@ struct InfosView: View {
}

}, sortBy: sortOrder)

// 测试无数据用
// var fd = FetchDescriptor<IOInfo>(predicate: #Predicate { info in
// info.name.starts(with: "apple")
// }, sortBy: sortOrder)

fd.fetchLimit = limit.wrappedValue
_infos = Query(fd)

Expand All @@ -54,6 +61,25 @@ struct InfosView: View {
}
}
} // end List
.overlay {
if infos.isEmpty {
ContentUnavailableView {
Label("无资料", systemImage: "questionmark.square.dashed")
} description: {
Text("点击下方按钮添加一个资料")
} actions: {
Button("新增") {
addInfo()
}
}
}
}
} // end body

func addInfo() {
let info = IOInfo(name: "简单记录 - \(SMDate.nowDateString())", url: "", des: "", relateName: "")
modelContext.insert(info)
selectInfo = info
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@
import SwiftUI
import SwiftData
import InfoOrganizer
import SMDate

struct StarInfosView: View {
@Environment(\.modelContext) var modelContext
@Query var infos: [IOInfo]
@Binding var selectInfo: IOInfo?
@Binding var limit: Int
Expand All @@ -18,6 +20,12 @@ struct StarInfosView: View {
var fd = FetchDescriptor<IOInfo>(predicate: #Predicate { info in
info.star == true && info.isArchived == false
}, sortBy: [SortDescriptor(\IOInfo.updateDate, order: .reverse)])

// 测试用
// var fd = FetchDescriptor<IOInfo>(predicate: #Predicate { info in
// info.star == true && info.name.starts(with: "apple")
// }, sortBy: [SortDescriptor(\IOInfo.updateDate, order: .reverse)])

fd.fetchLimit = limit.wrappedValue
_infos = Query(fd)
self._selectInfo = selectInfo
Expand All @@ -37,7 +45,28 @@ struct StarInfosView: View {
}
}
}
}
} // end List
.overlay {
if infos.isEmpty {
ContentUnavailableView {
Label("无收藏", systemImage: "star.slash")
} description: {
Text("点击下方按钮添加一个收藏资料")
} actions: {
Button("新增") {
addInfo()
}
}
}
} // end overlay

} // end body

func addInfo() {
let info = IOInfo(name: "简单记录 - \(SMDate.nowDateString())", url: "", des: "", relateName: "")
info.star = true
modelContext.insert(info)
selectInfo = info
}
}

Loading

0 comments on commit 52a7dec

Please sign in to comment.