Skip to content

Commit

Permalink
Adds deletion of conversations and related audio files
Browse files Browse the repository at this point in the history
- Added `deleteConversation` function in `DownloadedAudioStore.swift` to delete a conversation and all its related audio files.
- Enhanced `DownloadedAudiosListView.swift` to allow conversation deletion from the download list.
- Updated `EditConversationView.swift` with a confirmation alert for deletion and a button to initiate the deletion process.
- Added a new image to `README.md` to display the updated interface.
- This change improves the user interface by allowing users to remove unnecessary conversations and associated files.
  • Loading branch information
Viktor Kushnerov authored and Viktor Kushnerov committed Oct 28, 2024
1 parent 5a1e207 commit 3f147b8
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 11 deletions.
Binary file added Assets/downloaded-view-2.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
16 changes: 16 additions & 0 deletions AudioFetchGPT/AudioModels/DownloadedAudioStore.swift
Original file line number Diff line number Diff line change
Expand Up @@ -170,4 +170,20 @@ class DownloadedAudioStore: ObservableObject {
.filter { $0.conversationId == conversationId }
.map { $0.messageId }
}

func deleteConversation(conversationId: UUID) {
// Filter audio files that do not belong to the specified conversation
let audiosToDelete = items.filter { UUID(uuidString: $0.conversationId) == conversationId }

// Delete files from the file system
for audio in audiosToDelete {
deleteAudio(audio)
}

// Remove audio files from the list
items.removeAll { UUID(uuidString: $0.conversationId) == conversationId }

// Save changes
saveDownloadedAudios()
}
}
33 changes: 23 additions & 10 deletions AudioFetchGPT/Views/DownloadedAudios/DownloadedAudiosListView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@ struct DownloadedAudiosListView: View {
List {
ForEach(groupedAudios.keys.sorted(), id: \.self) { conversationId in
Section(header: SectionHeaderView(conversationId: conversationId,
conversationName: downloadedAudios.getConversationName(by: conversationId),
onEdit: { startEditing(conversationId) },
onToggle: { downloadedAudios.toggleSection(conversationId) },
isCollapsed: downloadedAudios.collapsedSections.contains(conversationId))
conversationName: downloadedAudios.getConversationName(by: conversationId),
onEdit: { startEditing(conversationId) },
onToggle: { downloadedAudios.toggleSection(conversationId) },
isCollapsed: downloadedAudios.collapsedSections.contains(conversationId))
) {
if !downloadedAudios.collapsedSections.contains(conversationId) {
AudioListView(audios: groupedAudios[conversationId] ?? [],
Expand All @@ -60,12 +60,21 @@ struct DownloadedAudiosListView: View {
)) {
if let conversationId = editingConversationId {
// Extracted view for editing conversation name
EditConversationView(conversationId: conversationId, newConversationName: $newConversationName, onCancel: {
editingConversationId = nil
}, onSave: {
saveNewConversationName(conversationId: conversationId, newName: newConversationName)
editingConversationId = nil
})
EditConversationView(
conversationId: conversationId,
newConversationName: $newConversationName,
onCancel: {
editingConversationId = nil
},
onSave: {
saveNewConversationName(conversationId: conversationId, newName: newConversationName)
editingConversationId = nil
},
onDelete: {
deleteConversation(conversationId)
editingConversationId = nil
}
)
}
}
.alert(isPresented: $showErrorAlert) {
Expand Down Expand Up @@ -110,4 +119,8 @@ struct DownloadedAudiosListView: View {
private func moveAudio(conversationId: UUID, indices: IndexSet, newOffset: Int) {
downloadedAudios.moveAudio(conversationId: conversationId, indices: indices, newOffset: newOffset)
}

private func deleteConversation(_ conversationId: UUID) {
downloadedAudios.deleteConversation(conversationId: conversationId)
}
}
19 changes: 18 additions & 1 deletion AudioFetchGPT/Views/DownloadedAudios/EditConversationView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ struct EditConversationView: View {
@Binding var newConversationName: String
var onCancel: () -> Void
var onSave: () -> Void
var onDelete: () -> Void // Параметр для удаления

@State private var showDeleteConfirmation = false // Состояние для показа алерта

var body: some View {
VStack {
Expand All @@ -29,14 +32,27 @@ struct EditConversationView: View {
Image(systemName: "doc.on.clipboard")
.foregroundColor(.blue)
}
.buttonStyle(BorderlessButtonStyle()) // Чтобы избежать лишнего фона
.buttonStyle(BorderlessButtonStyle())
.padding(.leading, 8)
}
.padding()

HStack {
Button("Cancel", action: onCancel)
Spacer()
Button("Delete", action: {
showDeleteConfirmation = true // Показываем алерт
})
.foregroundColor(.red)
.alert(isPresented: $showDeleteConfirmation) { // Настраиваем алерт
Alert(
title: Text("Confirm Deletion"),
message: Text("Are you sure you want to delete this conversation and all related audio files?"),
primaryButton: .destructive(Text("Delete"), action: onDelete), // Подтверждение удаления
secondaryButton: .cancel() // Кнопка отмены
)
}
Spacer()
Button("Save", action: onSave)
.disabled(newConversationName.isEmpty)
}
Expand All @@ -47,3 +63,4 @@ struct EditConversationView: View {
}
}


1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
<img src="./Assets/showRetrySkipDialog.jpeg" width="200" />
<img src="./Assets/NotificationBanner.jpeg" width="200" />
<img src="./Assets/downloaded-view.jpeg" width="200" />
<img src="./Assets/downloaded-view-2.jpeg" width="200" />
<img src="./Assets/texteditor-view.jpeg" width="200" />
<img src="./Assets/lockscreen.jpg" width="200" />
</p>
Expand Down

0 comments on commit 3f147b8

Please sign in to comment.