Skip to content

Commit

Permalink
增加设置的栏目
Browse files Browse the repository at this point in the history
  • Loading branch information
ming1016 committed Nov 23, 2024
1 parent 174673b commit dc634f7
Show file tree
Hide file tree
Showing 6 changed files with 75 additions and 30 deletions.
4 changes: 4 additions & 0 deletions SwiftPamphletApp.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,7 @@
088F2C482C932A7900DCA64F /* 知识管理-输出(ap).md in Resources */ = {isa = PBXBuildFile; fileRef = 088F2C472C932A7900DCA64F /* 知识管理-输出(ap).md */; };
088F2C4A2C932A8B00DCA64F /* 知识管理-目的导向工作流(ap).md in Resources */ = {isa = PBXBuildFile; fileRef = 088F2C492C932A8B00DCA64F /* 知识管理-目的导向工作流(ap).md */; };
088F2C4C2C932C5800DCA64F /* 知识管理-PKM(ap).md in Resources */ = {isa = PBXBuildFile; fileRef = 088F2C4B2C932C5800DCA64F /* 知识管理-PKM(ap).md */; };
0891EACD2CF1EAC000597974 /* SettingSidebarView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0891EACC2CF1EAC000597974 /* SettingSidebarView.swift */; };
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 */; };
Expand Down Expand Up @@ -732,6 +733,7 @@
088F2C472C932A7900DCA64F /* 知识管理-输出(ap).md */ = {isa = PBXFileReference; lastKnownFileType = net.daringfireball.markdown; path = "知识管理-输出(ap).md"; sourceTree = "<group>"; };
088F2C492C932A8B00DCA64F /* 知识管理-目的导向工作流(ap).md */ = {isa = PBXFileReference; lastKnownFileType = net.daringfireball.markdown; path = "知识管理-目的导向工作流(ap).md"; sourceTree = "<group>"; };
088F2C4B2C932C5800DCA64F /* 知识管理-PKM(ap).md */ = {isa = PBXFileReference; lastKnownFileType = net.daringfireball.markdown; path = "知识管理-PKM(ap).md"; sourceTree = "<group>"; };
0891EACC2CF1EAC000597974 /* SettingSidebarView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SettingSidebarView.swift; 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>"; };
Expand Down Expand Up @@ -2260,6 +2262,7 @@
children = (
08ED801B2B9D1EEC0069B7EC /* SettingView.swift */,
08A7FF302BEB02EA00E12E5A /* GithubAccessTokenView.swift */,
0891EACC2CF1EAC000597974 /* SettingSidebarView.swift */,
);
path = Setting;
sourceTree = "<group>";
Expand Down Expand Up @@ -2968,6 +2971,7 @@
files = (
3A05B7C92CE57A5C00B2B30F /* TaskCaseLoadFile.swift in Sources */,
0871C61B2BA04D23000B620D /* CategoryRowView.swift in Sources */,
0891EACD2CF1EAC000597974 /* SettingSidebarView.swift in Sources */,
08F14B442BBE2865005B46CC /* ViewComponentImage.swift in Sources */,
08069CAB2BDE01E800D48E24 /* GuideListView.swift in Sources */,
084417792B99BE720049297D /* DataLink.swift in Sources */,
Expand Down
19 changes: 19 additions & 0 deletions SwiftPamphletApp/HomeUI/DataLink.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ struct DataLink: Identifiable {
selectDevBindable: DeveloperModel?,
selectGuideItem: Binding<L?>,
selectGuideItemBindable: L?,
selectItem: Binding<String?>,
selectItemBindable: String?,
limit: Binding<Int>,
trigger: Binding<Bool>,
type: ShowType
Expand Down Expand Up @@ -140,6 +142,20 @@ struct DataLink: Identifiable {
)
}
}
case "设置":
switch type {
case .content:
SettingSidebarView(selectedItem: selectItem)
case .detail:
switch selectItemBindable {
case "Github Token 设置":
GithubAccessTokenView()
case "自定义标签":
CustomSearch()
default:
IntroView()
}
}
default:
switch type {
case .content:
Expand All @@ -165,6 +181,9 @@ extension DataLink {
DataLink(title: "未分类", imageName: "p6"),
DataLink(title: "收藏", imageName: "p11"),
DataLink(title: "归档", imageName: "p3")
]),
DataLink(title: "工具", imageName: "", children: [
DataLink(title: "设置", imageName: "p27")
])
]
static func dataLinksWithGithub() -> [DataLink] {
Expand Down
5 changes: 5 additions & 0 deletions SwiftPamphletApp/HomeUI/HomeView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ struct HomeView: View {
@State private var selectedGuideItem: L? = nil // 改为 L? 类型
@State private var limit: Int = 50 // 为 GuideDetailView 添加
@State private var trigger: Bool = false // 为 GuideDetailView 添加
@State private var selectedItem: String? = nil

var body: some View {
#if os(macOS)
Expand All @@ -38,6 +39,8 @@ struct HomeView: View {
selectDevBindable: selectDev,
selectGuideItem: $selectedGuideItem,
selectGuideItemBindable: selectedGuideItem,
selectItem: $selectedItem,
selectItemBindable: selectedItem,
limit: $limit,
trigger: $trigger,
type: .content
Expand All @@ -60,6 +63,8 @@ struct HomeView: View {
selectDevBindable: selectDev,
selectGuideItem: $selectedGuideItem,
selectGuideItemBindable: selectedGuideItem,
selectItem: $selectedItem,
selectItemBindable: selectedItem,
limit: $limit,
trigger: $trigger,
type: .detail
Expand Down
23 changes: 15 additions & 8 deletions SwiftPamphletApp/Setting/GithubAccessTokenView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,24 @@ import SwiftUI
import SMGitHub

struct GithubAccessTokenView: View {
@AppStorage(SPC.isShowGithub) var isShowGithub = false
@State private var tokenString: String = ""
var body: some View {
Form {
Section {
Text("在这里写上 Github 的 access token 来访问内容")
TextField("", text: $tokenString, prompt: Text("输入 access token"))
.padding(10)
.onSubmit {
save()
}
VStack(alignment: .leading) {
Toggle("是否显示 Github", isOn: $isShowGithub)
.toggleStyle(.switch)
.padding(20)
Form {
Section {
Text("在这里写上 Github 的 access token 来访问内容")
TextField("", text: $tokenString, prompt: Text("输入 access token"))
.padding(10)
.onSubmit {
save()
}
}
}
Spacer()
}
.onAppear(perform: {
let ud = UserDefaults.standard
Expand Down
25 changes: 25 additions & 0 deletions SwiftPamphletApp/Setting/SettingSidebarView.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
//
// SettingSidebarView.swift
// SwiftPamphletApp
//
// Created by Ming Dai on 2024/11/23.
//

import SwiftUI

struct SettingSidebarView: View {
@Binding var selectedItem: String?
var body: some View {
List(selection: $selectedItem) {
item(title: "Github Token 设置", icon: "gearshape")
.tag("Github Token 设置")
item(title: "自定义标签", icon: "tag")
.tag("自定义标签")
}
}

@ViewBuilder func item(title:String, icon:String) -> some View {
Label(title, systemImage: icon)
}
}

29 changes: 7 additions & 22 deletions SwiftPamphletApp/Setting/SettingView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,23 +11,24 @@ struct SettingView: View {

var body: some View {
TabView {
accessTokenView()
GithubAccessTokenView()
.tabItem {
Label("设置", systemImage: "gearshape")
}
customSearch()
CustomSearch()
.tabItem {
Label("自定义标签", systemImage: "mail.and.text.magnifyingglass")
}

}
.frame(minHeight: 400)
}

// MARK: custom search

}

struct CustomSearch: View {
@AppStorage(SPC.customSearchTerm) var term = ""
@ViewBuilder
func customSearch() -> some View {
var body: some View {
VStack {
Text("输入自定义的标签,以换行作为间隔")
TextEditor(text: $term)
Expand All @@ -41,20 +42,4 @@ struct SettingView: View {
}
.padding(20)
}

// MARK: 是否显示 Github 内容
@AppStorage(SPC.isShowGithub) var isShowGithub = false

// MARK: token
@State private var tokenString = ""
@ViewBuilder
func accessTokenView() -> some View {
VStack(alignment: .leading) {
Toggle("是否显示 Github", isOn: $isShowGithub)
.toggleStyle(.switch)
.padding(20)
GithubAccessTokenView()
Spacer()
}
}
}

0 comments on commit dc634f7

Please sign in to comment.