Skip to content

Commit

Permalink
修复书签问题
Browse files Browse the repository at this point in the history
  • Loading branch information
ming1016 committed Nov 19, 2024
1 parent 5139425 commit 241220a
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 45 deletions.
32 changes: 12 additions & 20 deletions SwiftPamphletApp/Guide/Bookmark/View/BookmarkListView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,32 +12,24 @@ struct BookmarkListView: View {
@Environment(\.modelContext) var modelContext
@Query(BookmarkModel.all) var bms: [BookmarkModel]
// var bms: [BookmarkModel] = [BookmarkModel]() // 测试空数据用
@Binding var selectedItem: L?
@State private var limit: Int = 50
@State private var trigger = false
var body: some View {
List {
List(selection: $selectedItem) {
ForEach(bms) { bm in
NavigationLink(
destination: GuideDetailView(
t: bm.name,
icon: bm.icon,
plName: bm.pamphletName,
limit: $limit,
trigger: $trigger
)
) {
HStack {
if bm.icon.isEmpty == false {
Image(systemName: bm.icon)
.foregroundStyle(Color.secondary)
}
Text(bm.name)
Spacer()
Image(systemName: "bookmark")
.foregroundStyle(.secondary)
.font(.footnote)
HStack {
if bm.icon.isEmpty == false {
Image(systemName: bm.icon)
.foregroundStyle(Color.secondary)
}
Text(bm.name)
Spacer()
Image(systemName: "bookmark")
.foregroundStyle(.secondary)
.font(.footnote)
}
.tag(L(t: bm.name, icon: bm.icon))
.contextMenu {
Button("前移") {
bm.updateDate = Date.now
Expand Down
2 changes: 1 addition & 1 deletion SwiftPamphletApp/Guide/View/GuideListView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ struct GuideListView: View {
@Query(BookmarkModel.all) var bookmarks: [BookmarkModel]
@State private var apBookmarks: [String] = [String]()
@State var listModel: GuideListModel
@Binding var selectedItem: L? // 改为 L? 类型
@Binding var selectedItem: L?
@AppStorage(SPC.expandedGuideItems) private var expandedItemsString: String = ""
@State private var expandedItems: Set<String> = []

Expand Down
12 changes: 10 additions & 2 deletions SwiftPamphletApp/HomeUI/DataLink.swift
Original file line number Diff line number Diff line change
Expand Up @@ -128,9 +128,17 @@ struct DataLink: Identifiable {
case "书签":
switch type {
case .content:
BookmarkListView()
BookmarkListView(selectedItem: selectGuideItem)
case .detail:
IntroView()
if let item = selectGuideItemBindable {
GuideDetailView(
t: item.t,
icon: item.icon,
plName: "ap",
limit: limit,
trigger: trigger
)
}
}
default:
switch type {
Expand Down
34 changes: 12 additions & 22 deletions SwiftPamphletApp/HomeUI/HomeView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -52,28 +52,18 @@ struct HomeView: View {
}
} detail: {
if !selectedDataLinkString.isEmpty {
if selectedDataLinkString == "Apple技术", let item = selectedGuideItem {
GuideDetailView(
t: item.t,
icon: item.icon,
plName: "ap",
limit: $limit,
trigger: $trigger
)
} else {
DataLink.viewToShow(
for: selectedDataLinkString,
selectInfo: $selectInfo,
selectDev: $selectDev,
selectInfoBindable: selectInfo,
selectDevBindable: selectDev,
selectGuideItem: $selectedGuideItem,
selectGuideItemBindable: selectedGuideItem,
limit: $limit,
trigger: $trigger,
type: .detail
)
}
DataLink.viewToShow(
for: selectedDataLinkString,
selectInfo: $selectInfo,
selectDev: $selectDev,
selectInfoBindable: selectInfo,
selectDevBindable: selectDev,
selectGuideItem: $selectedGuideItem,
selectGuideItemBindable: selectedGuideItem,
limit: $limit,
trigger: $trigger,
type: .detail
)
} else {
IntroView()
}
Expand Down

0 comments on commit 241220a

Please sign in to comment.