diff --git a/mobile/app/(app)/story-new.tsx b/mobile/app/(app)/story-new.tsx index 9dd252e..6412c95 100644 --- a/mobile/app/(app)/story-new.tsx +++ b/mobile/app/(app)/story-new.tsx @@ -48,6 +48,8 @@ export default function NewStoryScreen() { const [asset, setAsset] = useState(null); const [error, setError] = useState(null); const [isUploadingFile, setIsUploadingFile] = useState(false); + // Video-Upload in Prozent (0–100), null solange kein Video hochgeladen wird. + const [uploadPercent, setUploadPercent] = useState(null); // expo-image-picker reports `duration` (ms) only for videos, `null`/`undefined` // for photos — more reliable than trusting a MIME-type string (see the @@ -111,7 +113,11 @@ export default function NewStoryScreen() { aiDisclosure: "NONE", }); setIsUploadingFile(true); - await uploadFileToUrl(asset.uri, uploadUrl ?? "", asset.mimeType ?? "video/mp4"); + setUploadPercent(0); + await uploadFileToUrl(asset.uri, uploadUrl ?? "", asset.mimeType ?? "video/mp4", (fraction) => { + const pct = Math.round(fraction * 100); + setUploadPercent((prev) => (prev === pct ? prev : pct)); + }); // Story row already exists (PROCESSING) — story-viewer.tsx polls // getVideoStatus for it, same as web's viewer. Nothing to await here. await queryClient.invalidateQueries(trpc.follows.pathFilter()); @@ -133,6 +139,7 @@ export default function NewStoryScreen() { setError(t("onboarding.uploadError")); } finally { setIsUploadingFile(false); + setUploadPercent(null); } }, [asset, activePetId, isVideo, createVideoUploadMutation, getPresignedUrlMutation, createMutation, queryClient, trpc, router]); @@ -142,7 +149,7 @@ export default function NewStoryScreen() { return ( {asset ? ( - setAsset(null)}> + setAsset(null)} disabled={isSubmitting}> {isVideo ? ( ) : ( @@ -170,7 +177,35 @@ export default function NewStoryScreen() { onPress={handleSubmit} disabled={!asset || isSubmitting} /> - {isSubmitting && } + {isSubmitting && isVideo ? ( + + ) : ( + isSubmitting && + )} + + ); +} + +/** + * Fortschritt beim Video-Upload zu Mux. `percent === null` = Upload wird noch + * vorbereitet (createVideoUpload läuft), dann echter Fortschritt aus + * expo-file-system `onProgress`. + */ +function UploadProgress({ percent, styles }: { percent: number | null; styles: ReturnType }) { + const { t } = useTranslation(); + const label = percent === null ? t("story.preparingUpload") : t("story.uploadingVideo", { percent }); + + return ( + + + + + {label} ); } @@ -213,5 +248,9 @@ function makeStyles(colors: ColorTokens, bottomInset: number) { previewImage: { width: "100%", flex: 1 }, previewHint: { ...typography.label, textTransform: "none", letterSpacing: 0, textAlign: "center", paddingVertical: 6 }, error: { ...typography.body, color: colors.alertRed }, + progressWrap: { gap: 6 }, + progressTrack: { height: 6, borderRadius: 3, backgroundColor: colors.hairlineGray, overflow: "hidden" }, + progressFill: { height: "100%", borderRadius: 3, backgroundColor: colors.marigoldOrange }, + progressLabel: { ...typography.label, textTransform: "none", letterSpacing: 0, textAlign: "center", color: colors.ink }, }); } diff --git a/mobile/src/i18n/locales/de.json b/mobile/src/i18n/locales/de.json index 62dd9f3..5b1dc77 100644 --- a/mobile/src/i18n/locales/de.json +++ b/mobile/src/i18n/locales/de.json @@ -92,7 +92,9 @@ "changePhotoHint": "Antippen, um ein anderes Foto zu wählen", "changeVideoHint": "Antippen, um ein anderes Video zu wählen", "shareButton": "Story teilen", - "videoTooLong": "Videos für Stories dürfen höchstens {{max}} Sekunden lang sein." + "videoTooLong": "Videos für Stories dürfen höchstens {{max}} Sekunden lang sein.", + "preparingUpload": "Upload wird vorbereitet …", + "uploadingVideo": "Video wird hochgeladen … {{percent}} %" }, "milestoneTypes": { "BIRTHDAY": "Geburtstag", diff --git a/mobile/src/i18n/locales/en.json b/mobile/src/i18n/locales/en.json index 8a0e9bc..bde9908 100644 --- a/mobile/src/i18n/locales/en.json +++ b/mobile/src/i18n/locales/en.json @@ -92,7 +92,9 @@ "changePhotoHint": "Tap to choose a different photo", "changeVideoHint": "Tap to choose a different video", "shareButton": "Share story", - "videoTooLong": "Story videos can be at most {{max}} seconds long." + "videoTooLong": "Story videos can be at most {{max}} seconds long.", + "preparingUpload": "Preparing upload …", + "uploadingVideo": "Uploading video … {{percent}}%" }, "milestoneTypes": { "BIRTHDAY": "Birthday", diff --git a/mobile/src/lib/upload.ts b/mobile/src/lib/upload.ts index a3da871..16c967c 100644 --- a/mobile/src/lib/upload.ts +++ b/mobile/src/lib/upload.ts @@ -28,12 +28,22 @@ export async function uploadImageToSupabase(uri: string, presignedUrl: string, m * different destination (Mux, not Supabase) and no signature-matching * requirement on Content-Type, so keeping the working photo path untouched. */ -export async function uploadFileToUrl(uri: string, uploadUrl: string, mimeType: string): Promise { +export async function uploadFileToUrl( + uri: string, + uploadUrl: string, + mimeType: string, + onProgress?: (fraction: number) => void +): Promise { const file = new File(uri); const result = await file.upload(uploadUrl, { httpMethod: "PUT", mimeType, headers: { "Content-Type": mimeType }, + onProgress: onProgress + ? ({ bytesSent, totalBytes }) => { + if (totalBytes > 0) onProgress(Math.min(bytesSent / totalBytes, 1)); + } + : undefined, }); if (result.status < 200 || result.status >= 300) {