Skip to content

Commit

Permalink
Add a tags column
Browse files Browse the repository at this point in the history
  • Loading branch information
Hamuko committed May 26, 2024
1 parent 5224c2a commit 392c823
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 4 deletions.
3 changes: 3 additions & 0 deletions Dreadnought/ClientData.swift
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ struct TorrentData: Decodable {
let category: String?
let addedOn: Int?
let state: String?
let tags: String?

enum CodingKeys: String, CodingKey {
case name
Expand All @@ -55,6 +56,7 @@ struct TorrentData: Decodable {
case category
case addedOn = "added_on"
case state
case tags
}

init(from decoder: any Decoder) throws {
Expand All @@ -68,6 +70,7 @@ struct TorrentData: Decodable {
category = (try? values.decode(String.self, forKey: .category))
addedOn = try? values.decode(Int.self, forKey: .addedOn)
state = try? values.decode(String.self, forKey: .state)
tags = try? values.decode(String.self, forKey: .tags)
}
}

Expand Down
15 changes: 12 additions & 3 deletions Dreadnought/ContentView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,12 @@ struct TorrentList: View {
.width(min: 1)
.customizationID("category")

TableColumn("Tags") { torrent in
Text(torrent.tags.joined(separator: ", "))
}
.width(min: 1)
.customizationID("tags")

TableColumn("Added on", value: \.addedOn) { torrent in
Text(torrent.addedOn, format: .dateTime)
.help(torrent.addedOn.formatted(.relative(presentation: .numeric, unitsStyle: .wide)))
Expand Down Expand Up @@ -552,7 +558,8 @@ struct LoginView: View {
speedUp: 1490124,
category: "Linux",
addedOn: Date(timeIntervalSince1970: 1710550279),
state: .uploading
state: .uploading,
tags: []
),
"2aa4f5a7e209e54b32803d43670971c4c8caaa05": Torrent(
hash: "2aa4f5a7e209e54b32803d43670971c4c8caaa05",
Expand All @@ -564,7 +571,8 @@ struct LoginView: View {
speedUp: 198453,
category: "Linux",
addedOn: Date(timeIntervalSince1970: 1715512279),
state: .downloading
state: .downloading,
tags: []
),
"0852ef544a4694995fcbef7132477c688ded7d9a": Torrent(
hash: "0852ef544a4694995fcbef7132477c688ded7d9a",
Expand All @@ -576,7 +584,8 @@ struct LoginView: View {
speedUp: 0,
category: "Not Linux",
addedOn: Date(timeIntervalSince1970: 1715514390),
state: .stalledDL
state: .stalledDL,
tags: []
),
]
client.connectionStatus = .connected
Expand Down
9 changes: 8 additions & 1 deletion Dreadnought/Data.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ struct Torrent: Identifiable {
var category: String
var addedOn: Date
var state: TorrentState
var tags: [String]

var id: String { hash }

Expand All @@ -24,7 +25,8 @@ struct Torrent: Identifiable {
speedUp:Int64,
category: String,
addedOn: Date,
state: TorrentState
state: TorrentState,
tags: [String]
) {
self.hash = hash
self.name = name
Expand All @@ -36,6 +38,7 @@ struct Torrent: Identifiable {
self.category = category
self.addedOn = addedOn
self.state = state
self.tags = tags
}

init(hash: String, data: TorrentData) {
Expand All @@ -49,6 +52,7 @@ struct Torrent: Identifiable {
self.category = data.category!
self.addedOn = Date(timeIntervalSince1970: TimeInterval(data.addedOn!))
self.state = TorrentState.from(data.state!)
self.tags = data.tags!.split(separator: ", ").map { String($0) }
}

mutating func update(data: TorrentData) {
Expand All @@ -73,6 +77,9 @@ struct Torrent: Identifiable {
if let state = data.state {
self.state = TorrentState.from(state)
}
if let tags = data.tags {
self.tags = tags.split(separator: ", ").map { String($0) }
}
}
}

Expand Down

0 comments on commit 392c823

Please sign in to comment.