Skip to content

Commit

Permalink
fix: fix #66
Browse files Browse the repository at this point in the history
  • Loading branch information
castdrian committed Jun 23, 2024
1 parent dd17244 commit ff1c798
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
18 changes: 10 additions & 8 deletions ishare/Views/HistoryGridView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,21 @@ import Foundation
import SwiftUI
import BezelNotification
import Alamofire
import Defaults

struct HistoryGridView: View {
@State var uploadHistory: [HistoryItem]
@Default(.uploadHistory) var uploadHistory
var body: some View {
ScrollView {
LazyVGrid(columns: [GridItem(.adaptive(minimum: 100, maximum: .infinity), spacing: 3)], spacing: 3) {
ForEach(uploadHistory, id: \.self) { item in
if let urlStr = item.fileUrl, let url = URL(string: urlStr), url.pathExtension.lowercased() == "mp4" || url.pathExtension.lowercased() == "mov" {
ContextMenuWrapper(uploadHistory: $uploadHistory, item: item) {
ContextMenuWrapper(item: item) {
VideoThumbnailView(url: url)
.frame(width: 100, height: 100)
}
} else {
ContextMenuWrapper(uploadHistory: $uploadHistory, item: item) {
ContextMenuWrapper(item: item) {
HistoryItemView(urlString: item.fileUrl ?? "")
.frame(width: 100, height: 100)
}
Expand All @@ -35,12 +36,11 @@ struct HistoryGridView: View {
}

struct ContextMenuWrapper<Content: View>: View {
@Binding var uploadHistory: [HistoryItem]
@Default(.uploadHistory) var uploadHistory
let content: Content
let item: HistoryItem

init(uploadHistory: Binding<[HistoryItem]>, item: HistoryItem, @ViewBuilder content: () -> Content) {
self._uploadHistory = uploadHistory
init(item: HistoryItem, @ViewBuilder content: () -> Content) {
self.item = item
self.content = content()
}
Expand Down Expand Up @@ -72,6 +72,10 @@ struct ContextMenuWrapper<Content: View>: View {
}
case .failure(let error):
print("Deletion error: \(error.localizedDescription)")
if let index = uploadHistory.firstIndex(of: item) {
uploadHistory.remove(at: index)
BezelNotification.show(messageText: "Deleted", icon: ToastIcon)
}
}
}
}
Expand All @@ -81,8 +85,6 @@ struct ContextMenuWrapper<Content: View>: View {
}
}

// ... Rest of your views ...

struct VideoThumbnailView: View {
var url: URL

Expand Down
2 changes: 1 addition & 1 deletion ishare/Views/MainMenuView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class WindowHolder {

func openHistoryWindow(uploadHistory: [HistoryItem]) {
if WindowHolder.shared.historyWindowController == nil {
let historyView = HistoryGridView(uploadHistory: uploadHistory)
let historyView = HistoryGridView()
let hostingController = NSHostingController(rootView: historyView)
let windowController = HistoryWindowController(contentView: hostingController.view)
windowController.window?.title = "History"
Expand Down

0 comments on commit ff1c798

Please sign in to comment.