Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions DanXi Kit/Entity/ForumEntities.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import Foundation
import Utils

public struct Division: Identifiable, Codable, Hashable {
public let id: Int
Expand Down Expand Up @@ -57,6 +58,10 @@ public struct Tag: Identifiable, Codable, Hashable {
public let id: Int
public let temperature: Int
public let name: String

public var highlight: Bool {
return ConfigurationCenter.configuration.highlightTagIds.contains(id)
}
}

public struct Report: Identifiable, Hashable, Codable {
Expand Down
8 changes: 7 additions & 1 deletion DanXiUI/Forum/Pages/HolePage.swift
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,13 @@ struct HolePage: View {
WrappingHStack(alignment: .leading) {
ForEach(hole.tags) { tag in
ContentLink(value: tag) {
TagView(tag.name)
Group {
if tag.highlight {
HighlightTagView(tag.name)
} else {
TagView(tag.name)
}
}
}
.buttonStyle(.borderless)
}
Expand Down
33 changes: 33 additions & 0 deletions DanXiUI/Forum/Views/HighlightTagView.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import SwiftUI
import ViewUtils

struct HighlightTagView: View {
@Environment(\.colorScheme) private var colorScheme
private let name: String
private let color: Color
private let deletable: Bool

init(_ name: String, color: Color? = nil, deletable: Bool = false) {
self.name = name
self.color = color ?? randomColor(name)
self.deletable = deletable
}

var body: some View {
HStack {
Text(name)
if deletable {
Divider()
Image(systemName: "multiply")
.imageScale(.small)
}
}
.textCase(nil)
.padding(EdgeInsets(top: 3, leading: 8, bottom: 3, trailing: 8))
.background(color.opacity(colorScheme == .light ? 0.1 : 0.2))
.cornerRadius(5)
.foregroundColor(color)
.font(.caption2)
.lineLimit(1)
}
}
8 changes: 7 additions & 1 deletion DanXiUI/Forum/Views/HoleView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,13 @@ struct HoleView: View {
HStack(alignment: .top) {
WrappingHStack(alignment: .leading) {
ForEach(hole.tags) { tag in
TagView(tag.name)
Group {
if tag.highlight {
HighlightTagView(tag.name)
} else {
TagView(tag.name)
}
}
}
}
Spacer()
Expand Down
18 changes: 16 additions & 2 deletions Utils/App/ConfigurationCenter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ public enum ConfigurationCenter {

public static let semesterMapPublisher = PassthroughSubject<[Int: Date], Never>()
public static let bannerPublisher = PassthroughSubject<[Banner], Never>()
public static let highlightTagIdsPublisher = PassthroughSubject<[Int], Never>()

public static func initialFetch() {
if let configuration = try? Disk.retrieve("configuration.json", from: .appGroup, as: AppConfiguration.self) {
Expand Down Expand Up @@ -41,6 +42,7 @@ public enum ConfigurationCenter {
let semesterStartDate: [String: Date]
let banners: [Banner]
let userAgent: String
let highlightTagIds: [Int]

func constructConfiguration() -> AppConfiguration {
var convertedSemsterStartDate: [Int: Date] = [:]
Expand All @@ -50,7 +52,8 @@ public enum ConfigurationCenter {
}
}

return AppConfiguration(semesterStartDate: convertedSemsterStartDate, banners: banners, userAgent: userAgent)

return AppConfiguration(semesterStartDate: convertedSemsterStartDate, banners: banners, userAgent: userAgent, highlightTagIds: highlightTagIds)
}
}

Expand All @@ -68,6 +71,13 @@ public enum ConfigurationCenter {
}
}


if configuration.highlightTagIds != self.configuration.highlightTagIds {
Task { @MainActor in
highlightTagIdsPublisher.send(configuration.highlightTagIds)
}
}

self.configuration = configuration

Task(priority: .background) {
Expand All @@ -87,18 +97,21 @@ public struct AppConfiguration: Codable {
public let semesterStartDate: [Int: Date]
public let banners: [Banner]
public let userAgent: String
public let highlightTagIds: [Int]

/// Initializer that creates an empty configuration
init() {
semesterStartDate = [:]
banners = []
userAgent = "DXSwift"
highlightTagIds = []
}

init(semesterStartDate: [Int: Date], banners: [Banner], userAgent: String) {
init(semesterStartDate: [Int: Date], banners: [Banner], userAgent: String, highlightTagIds: [Int]) {
self.semesterStartDate = semesterStartDate
self.banners = banners
self.userAgent = userAgent
self.highlightTagIds = highlightTagIds
}
}

Expand All @@ -110,3 +123,4 @@ public struct Banner: Codable, Equatable {
/// Text that should be displayed on the button.
public let button: String
}