Skip to content

Commit

Permalink
add 自定义检索
Browse files Browse the repository at this point in the history
  • Loading branch information
ming1016 committed Apr 10, 2024
1 parent c87bcd9 commit 3505b76
Show file tree
Hide file tree
Showing 6 changed files with 105 additions and 37 deletions.
11 changes: 0 additions & 11 deletions SwiftPamphletApp/App/SwiftPamphletAppApp.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,6 @@ struct SwiftPamphletAppApp: App {
}
}

struct Demo: View {
var body: some View {
Group {
// PlayCanvas()
}
.frame(minWidth:300, maxWidth: .infinity, minHeight: 550, maxHeight: .infinity)
.onAppear {

}
}
}



Expand Down
2 changes: 1 addition & 1 deletion SwiftPamphletApp/GitHubAPI/Developer/EditDeveloper.swift
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ struct EditDeveloper: View {
dev.updateDate = formatter.date(from: iso8601String) ?? Date.now
}
})
.padding(EdgeInsets(top: 20, leading: 10, bottom: 0, trailing: 10))
.padding(EdgeInsets(top: 0, leading: 10, bottom: 0, trailing: 10))
.onAppear {
Task {
await repoVM.updateAllData()
Expand Down
6 changes: 6 additions & 0 deletions SwiftPamphletApp/HomeUI/HomeView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -51,5 +51,11 @@ struct HomeView: View {
IntroView()
}
}
.task {
#if DEBUG
let sandboxDirectory = FileManager.default.urls(for: .applicationSupportDirectory, in: .userDomainMask).first!
print(sandboxDirectory.debugDescription)
#endif
}
}
}
16 changes: 10 additions & 6 deletions SwiftPamphletApp/InfoOrganizer/Info/EditInfoView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -135,12 +135,16 @@ struct EditInfoView: View {
.tabItem { Label("预览", systemImage: "circle") }
.tag(2)
if let url = URL(string: info.url) {
WebUIViewWithSave(
urlStr: url.absoluteString,
savingDataTrigger: $savingDataTrigger,
savingData: $info.webArchive,
isStop: $isStopLoadingWeb
)
VStack {
WebUIViewWithSave(
urlStr: url.absoluteString,
savingDataTrigger: $savingDataTrigger,
savingData: $info.webArchive,
isStop: $isStopLoadingWeb
)
TextField(text: $info.des, prompt: Text("输入文本进行记录"), axis: .vertical) {}
.padding(5)
}
.tabItem { Label("网页", systemImage: "circle") }
.tag(4)
}
Expand Down
40 changes: 39 additions & 1 deletion SwiftPamphletApp/InfoOrganizer/Info/InfoListView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,11 @@ struct InfoListView: View {
}
}
}
if searchTerms.isEmpty == false {
ToolbarItem(placement: .navigation) {
customSearchView()
}
}
if filterCate.isEmpty {
ToolbarItem(placement: .navigation) {
Toggle(isOn: $filterStar) {
Expand Down Expand Up @@ -82,10 +87,43 @@ struct InfoListView: View {
}
}
.searchable(text: $searchText)
.onAppear {
parseSearchTerms()
}
.onChange(of: term) { oldValue, newValue in
parseSearchTerms()
}
}


// MARK: 自定义搜索
@ViewBuilder
func customSearchView() -> some View {
Picker("自定检索", selection: $searchText) {
Text("自定检索")
.tag("")
ForEach(searchTerms, id: \.self) { term in
Text(term)
.tag(term)
}
}
}

@AppStorage("customSearchTerm") var term = ""
@State private var searchTerms: [String] = [String]()
func parseSearchTerms() {
let terms = term.trimmingCharacters(in: .whitespacesAndNewlines).split(separator: "\n")
searchTerms = [String]()
for t in terms {
if t.isEmpty == false {
searchTerms.append(String(t))
}
}
}

// MARK: 资料整理数据方面
func addInfo() {
let info = IOInfo(name: "简单记录 - \(nowDateString())", url: "", coverImage: nil, imageUrls: [String](), imgs: [IOImg](), des: "\n", star: false, webArchive: nil , createDate: Date.now, updateDate: Date.now)
let info = IOInfo(name: "简单记录 - \(nowDateString())", url: "", coverImage: nil, imageUrls: [String](), imgs: [IOImg](), des: "", star: false, webArchive: nil , createDate: Date.now, updateDate: Date.now)
for cate in cates {
if cate.name == filterCate {
info.category = cate
Expand Down
67 changes: 49 additions & 18 deletions SwiftPamphletApp/Setting/SettingView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,31 +8,62 @@
import SwiftUI

struct SettingView: View {
@State private var tokenString = ""

var body: some View {
TabView {
Form {
Section {
Text("在这里写上 Github 的 access token")
TextField("", text: $tokenString)
.padding(10)
.onSubmit {
save()
}
Button("保存") {
accessTokenView()
.tabItem {
Label("设置", systemImage: "gearshape")
}
customSearch()
.tabItem {
Label("自定义搜索", systemImage: "mail.and.text.magnifyingglass")
}

}
.frame(minHeight: 400)
}

// MARK: custom search
@AppStorage("customSearchTerm") var term = ""
@ViewBuilder
func customSearch() -> some View {
VStack {
Text("输入自定义的搜索关键字,以换行作为间隔")
TextEditor(text: $term)
.overlay {
Rectangle()
.stroke(.secondary, lineWidth: 1)
.opacity(0.5)
.disableAutocorrection(true)

}
}
.padding(20)
}

// MARK: token
@State private var tokenString = ""
@ViewBuilder
func accessTokenView() -> some View {
Form {
Section {
Text("在这里写上 Github 的 access token")
TextField("", text: $tokenString)
.padding(10)
.onSubmit {
save()
}
Button("保存") {
save()
}
.onAppear(perform: {
let ud = UserDefaults.standard
tokenString = ud.string(forKey: SPC.githubUDTokenKey) ?? ""
})
}
.padding(20)
.tabItem {
Label("设置", systemImage: "gearshape")
}
.onAppear(perform: {
let ud = UserDefaults.standard
tokenString = ud.string(forKey: SPC.githubUDTokenKey) ?? ""
})
}
.padding(20)
}

func save() {
Expand Down

0 comments on commit 3505b76

Please sign in to comment.