import Foundation extension SharingState { static func reducer(state: inout SharingState, action: SharingAction) { switch action { case .showSharing(let shown): state.sharingShown = shown case .setCameraAccess(let granted): state.isCameraAccessGranted = granted case .setGalleryAccess(let granted): state.isGalleryAccessGranted = granted case .cameraCaptured(let media, let type): state.cameraCapturedMedia = media state.cameraCapturedMediaType = type case .flushCameraCaptured: state.cameraCapturedMedia = Data() state.cameraCapturedMediaType = .photo case .galleryFetched(let items): state.galleryItems = items case .thumbnailUpdated(let thumbnailData, let id): guard let index = state.galleryItems.firstIndex(where: { $0.id == id }) else { return } state.galleryItems[index].thumbnail = thumbnailData default: break } } }