feat(mobile): Fortschrittsbalken beim Video-Story-Upload

Statt nur Spinner: „Upload wird vorbereitet …“, dann Balken + Prozent aus
expo-file-system File.upload onProgress (nativ seit 57.0.7 im 1.0.6-Build,
daher OTA). Vorschau ist während des Uploads nicht mehr antippbar.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
adminandClaude Opus 5.5 committed 2026-10-03 14:44:35 +02:00
1 parent 6979447b6d
commit 5606a81dd2
4 files changed
+59 -6

No files matched your search

+42 -3
View File
@@ -48,6 +48,8 @@ export default function NewStoryScreen() {
const [asset, setAsset] = useState<ImagePicker.ImagePickerAsset | null>(null);
const [error, setError] = useState<string | null>(null);
const [isUploadingFile, setIsUploadingFile] = useState(false);
// Video-Upload in Prozent (0–100), null solange kein Video hochgeladen wird.
const [uploadPercent, setUploadPercent] = useState<number | null>(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 (
<View style={styles.container}>
{asset ? (
<Pressable style={styles.preview} onPress={() => setAsset(null)}>
<Pressable style={styles.preview} onPress={() => setAsset(null)} disabled={isSubmitting}>
{isVideo ? (
<VideoPreview uri={asset.uri} style={styles.previewImage} />
) : (
@@ -170,7 +177,35 @@ export default function NewStoryScreen() {
onPress={handleSubmit}
disabled={!asset || isSubmitting}
/>
{isSubmitting && <ActivityIndicator color={colors.marigoldOrange} />}
{isSubmitting && isVideo ? (
<UploadProgress percent={uploadPercent} styles={styles} />
) : (
isSubmitting && <ActivityIndicator color={colors.marigoldOrange} />
)}
</View>
);
}
/**
* 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<typeof makeStyles> }) {
const { t } = useTranslation();
const label = percent === null ? t("story.preparingUpload") : t("story.uploadingVideo", { percent });
return (
<View
style={styles.progressWrap}
accessibilityRole="progressbar"
accessibilityValue={{ min: 0, max: 100, now: percent ?? 0 }}
accessibilityLabel={label}
>
<View style={styles.progressTrack}>
<View style={[styles.progressFill, { width: `${percent ?? 0}%` }]} />
</View>
<Text style={styles.progressLabel}>{label}</Text>
</View>
);
}
@@ -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 },
});
}
+3 -1
View File
@@ -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",
+3 -1
View File
@@ -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",
+11 -1
View File
@@ -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<void> {
export async function uploadFileToUrl(
uri: string,
uploadUrl: string,
mimeType: string,
onProgress?: (fraction: number) => void
): Promise<void> {
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) {