Skip to content

Commit

Permalink
Fix save path not changing after setting category in add torrent view
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael-128 committed Feb 6, 2025
1 parent b85c54d commit 0713fd4
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 25 deletions.
22 changes: 2 additions & 20 deletions qBitControl/ViewModels/TorrentView/TorrentAddViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,6 @@ class TorrentAddViewModel: ObservableObject {
@Published var ratioLimit = ""
@Published var seedingTimeLimit = ""

@Published var categories: [Category] = [defaultCategory]
@Published var tagsArr: [String] = []

@Published var isAppeared = false

init(torrentUrls: [URL]) {
Expand Down Expand Up @@ -125,6 +122,8 @@ class TorrentAddViewModel: ObservableObject {
}

func getSavePath() {
if(!self.savePath.isEmpty) { return; }

qBittorrent.getPreferences(completionHandler: { preferences in
DispatchQueue.main.async {
self.autoTmmEnabled = preferences.auto_tmm_enabled ?? false
Expand All @@ -136,21 +135,4 @@ class TorrentAddViewModel: ObservableObject {
}
})
}

func getCategories() {
qBittorrent.getCategories(completionHandler: { categories in
DispatchQueue.main.async {
// Append sorted list of Category objects to ensure "Uncategorized" always appears at the top
self.categories = [Self.defaultCategory] + categories.map { $1 }.sorted { $0.name < $1.name }
}
})
}

func getTags() {
qBittorrent.getTags(completionHandler: { tags in
DispatchQueue.main.async {
self.tagsArr = tags
}
})
}
}
13 changes: 8 additions & 5 deletions qBitControl/Views/TorrentViews/TorrentAddView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,6 @@ struct TorrentAddView: View {
}
.onAppear() {
viewModel.getSavePath()
viewModel.getCategories()
viewModel.getTags()

if(!viewModel.isAppeared) {
viewModel.isAppeared.toggle()
Expand Down Expand Up @@ -112,16 +110,21 @@ struct TorrentAddView: View {
Section(header: Text("Info")) {
NavigationLink {
ChangeCategoryView(category: viewModel.category.name, onCategoryChange: { category in
viewModel.category = category
if !viewModel.autoTmmEnabled { viewModel.savePath = category.savePath }
DispatchQueue.main.async {
viewModel.category = category
if !viewModel.autoTmmEnabled { viewModel.savePath = category.savePath }
print(viewModel.savePath)
}
})
} label: {
CustomLabelView(label: "Category", value: viewModel.category.name)
}

NavigationLink {
ChangeTagsView(selectedTags: viewModel.selectedTags, onTagsChange: { selectedTags in
viewModel.selectedTags = selectedTags
DispatchQueue.main.async {
viewModel.selectedTags = selectedTags
}
})
} label: {
CustomLabelView(label: "Tags", value: viewModel.getTag())
Expand Down

0 comments on commit 0713fd4

Please sign in to comment.