mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-06-22 06:41:46 +00:00
Convert HEIC trip and journey covers to JPEG before upload (#1085)
HEIC/HEIF covers coming straight off an iPhone could not be rendered in the preview or stored as a usable image. Route both cover pickers through normalizeImageFile, the same conversion the journal entry editor already uses, so the file becomes a JPEG before it leaves the browser.
This commit is contained in:
@@ -10,6 +10,7 @@ import JourneyShareSection from './JourneyShareSection'
|
|||||||
import type { JourneyDetail } from '../../store/journeyStore'
|
import type { JourneyDetail } from '../../store/journeyStore'
|
||||||
import { pickGradient } from '../../pages/journeyDetail/JourneyDetailPage.helpers'
|
import { pickGradient } from '../../pages/journeyDetail/JourneyDetailPage.helpers'
|
||||||
import { AddTripDialog } from './JourneyDetailPageAddTripDialog'
|
import { AddTripDialog } from './JourneyDetailPageAddTripDialog'
|
||||||
|
import { normalizeImageFile } from '../../utils/convertHeic'
|
||||||
|
|
||||||
export function JourneySettingsDialog({ journey, onClose, onSaved, onOpenInvite, onRefresh }: {
|
export function JourneySettingsDialog({ journey, onClose, onSaved, onOpenInvite, onRefresh }: {
|
||||||
journey: JourneyDetail
|
journey: JourneyDetail
|
||||||
@@ -49,7 +50,7 @@ export function JourneySettingsDialog({ journey, onClose, onSaved, onOpenInvite,
|
|||||||
const file = e.target.files?.[0]
|
const file = e.target.files?.[0]
|
||||||
if (!file) return
|
if (!file) return
|
||||||
const formData = new FormData()
|
const formData = new FormData()
|
||||||
formData.append('cover', file)
|
formData.append('cover', await normalizeImageFile(file))
|
||||||
try {
|
try {
|
||||||
await journeyApi.uploadCover(journey.id, formData)
|
await journeyApi.uploadCover(journey.id, formData)
|
||||||
toast.success(t('journey.settings.coverUpdated'))
|
toast.success(t('journey.settings.coverUpdated'))
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ import { useCanDo } from '../../store/permissionsStore'
|
|||||||
import { useToast } from '../shared/Toast'
|
import { useToast } from '../shared/Toast'
|
||||||
import { useTranslation } from '../../i18n'
|
import { useTranslation } from '../../i18n'
|
||||||
import { CustomDatePicker } from '../shared/CustomDateTimePicker'
|
import { CustomDatePicker } from '../shared/CustomDateTimePicker'
|
||||||
|
import { normalizeImageFile } from '../../utils/convertHeic'
|
||||||
import type { Trip } from '../../types'
|
import type { Trip } from '../../types'
|
||||||
import type { TripCreateRequest } from '@trek/shared'
|
import type { TripCreateRequest } from '@trek/shared'
|
||||||
|
|
||||||
@@ -141,15 +142,17 @@ export default function TripFormModal({ isOpen, onClose, onSave, trip, onCoverUp
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const handleCoverSelect = (file) => {
|
const handleCoverSelect = async (file) => {
|
||||||
if (!file) return
|
if (!file) return
|
||||||
|
// HEIC/HEIF from iOS can't be rendered or stored as-is — convert to JPEG first
|
||||||
|
const normalized = await normalizeImageFile(file)
|
||||||
if (isEditing && trip?.id) {
|
if (isEditing && trip?.id) {
|
||||||
// Existing trip: upload immediately
|
// Existing trip: upload immediately
|
||||||
uploadCoverNow(file)
|
uploadCoverNow(normalized)
|
||||||
} else {
|
} else {
|
||||||
// New trip: stage for upload after creation
|
// New trip: stage for upload after creation
|
||||||
setPendingCoverFile(file)
|
setPendingCoverFile(normalized)
|
||||||
setCoverPreview(URL.createObjectURL(file))
|
setCoverPreview(URL.createObjectURL(normalized))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user