videogen/apps/mobile/components/performance/LogPerformanceForm.tsx
caelum0x d56639a594
Some checks failed
build-images / web (push) Has been cancelled
vision2026-ci / Python SDK resource tests (push) Has been cancelled
build-images / api (push) Has been cancelled
build-images / worker-gpu (push) Has been cancelled
vision2026-ci / Shared packages (TS≡Python golden parity) (comfy-workflow-schema) (push) Has been cancelled
vision2026-ci / Shared packages (TS≡Python golden parity) (effects-core) (push) Has been cancelled
vision2026-ci / Shared packages (TS≡Python golden parity) (eventbus-types) (push) Has been cancelled
vision2026-ci / Shared packages (TS≡Python golden parity) (growth-analytics) (push) Has been cancelled
vision2026-ci / Shared packages (TS≡Python golden parity) (provider-adapter-kit) (push) Has been cancelled
vision2026-ci / Shared packages (TS≡Python golden parity) (publishing-connectors) (push) Has been cancelled
vision2026-ci / Shared packages (TS≡Python golden parity) (render-core) (push) Has been cancelled
vision2026-ci / Shared packages (TS≡Python golden parity) (shot-template-schema) (push) Has been cancelled
vision2026-ci / Shared packages (TS≡Python golden parity) (trends-schema) (push) Has been cancelled
vision2026-ci / Desktop engine crates (test + clippy + fmt) (push) Has been cancelled
codeql / Analyze (javascript-typescript) (push) Has been cancelled
codeql / Analyze (python) (push) Has been cancelled
perf / API hot-path micro-smoke (budgeted) (push) Has been cancelled
perf / Desktop engine crates (release build check) (push) Has been cancelled
vision2026-ci / API phase modules (ruff + pytest) (push) Has been cancelled
vision2026-ci / Alembic upgrade + drift check (push) Has been cancelled
vision2026-ci / Shared packages (TS≡Python golden parity) (caption-engine) (push) Has been cancelled
Menivor — open source release (MIT), free to use and fork
Paid, hosted product at menivor.com, now retired as a company project.
Fresh squashed history of the cleaned working tree (secret-scanned,
no .env, no customer data, no outreach logs). Built on
MoneyPrinterTurbo (MIT, harry0703) — see NOTICE.
2026-12-04 02:10:26 +03:00

203 lines
6.2 KiB
TypeScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/**
* Metrics-logging form for one selected reel. The creator enters the
* self-reported outcome (platform + counts + watch-through %) and submits.
* Presentational + local input state only — the parent owns the network call
* (`logJobPerformance`) and passes `loading` for the submit affordance and an
* optional `initial` row to pre-fill when the reel was already logged.
*
* All numbers are parsed defensively: counts are non-negative integers,
* retention is clamped to [0,100], and an untouched field is simply omitted from
* the request (the backend then leaves that column at its default).
*/
import { useEffect, useState } from "react";
import {
ActivityIndicator,
Pressable,
StyleSheet,
Text,
TextInput,
View,
} from "react-native";
import {
PERFORMANCE_PLATFORMS,
type JobPerformance,
type LogPerformanceRequest,
type PerformancePlatform,
} from "@/lib/types";
import { colors } from "@/components/me/theme";
import { parseCount, parseRetention } from "./format";
interface LogPerformanceFormProps {
loading: boolean;
/** Existing row for the selected reel, used to pre-fill for an update. */
initial?: JobPerformance | null;
onSubmit: (body: LogPerformanceRequest) => void;
}
/** Blank string for an unset numeric field; a stored 0 shows as "0". */
function numToText(value: number | undefined): string {
return typeof value === "number" && Number.isFinite(value) ? String(value) : "";
}
export function LogPerformanceForm({
loading,
initial,
onSubmit,
}: LogPerformanceFormProps) {
const [platform, setPlatform] = useState<PerformancePlatform>("tiktok");
const [views, setViews] = useState("");
const [likes, setLikes] = useState("");
const [comments, setComments] = useState("");
const [shares, setShares] = useState("");
const [saves, setSaves] = useState("");
const [retention, setRetention] = useState("");
// Pre-fill from the stored row whenever the selected reel changes.
useEffect(() => {
const known = PERFORMANCE_PLATFORMS.find((p) => p === initial?.platform);
setPlatform(known ?? "tiktok");
setViews(numToText(initial?.views));
setLikes(numToText(initial?.likes));
setComments(numToText(initial?.comments));
setShares(numToText(initial?.shares));
setSaves(numToText(initial?.saves));
setRetention(numToText(initial?.retention_pct));
}, [initial]);
const submit = () => {
if (loading) return;
onSubmit({
platform,
views: parseCount(views),
likes: parseCount(likes),
comments: parseCount(comments),
shares: parseCount(shares),
saves: parseCount(saves),
retention_pct: parseRetention(retention),
});
};
const isUpdate = !!initial;
return (
<View style={styles.form}>
<Text style={styles.label}>Platform</Text>
<View style={styles.chips}>
{PERFORMANCE_PLATFORMS.map((p) => {
const active = p === platform;
return (
<Pressable
key={p}
style={[styles.chip, active && styles.chipActive]}
onPress={() => setPlatform(p)}
disabled={loading}
>
<Text style={[styles.chipText, active && styles.chipTextActive]}>
{p}
</Text>
</Pressable>
);
})}
</View>
<View style={styles.grid}>
<NumberField label="Views" value={views} onChange={setViews} disabled={loading} />
<NumberField label="Likes" value={likes} onChange={setLikes} disabled={loading} />
<NumberField label="Comments" value={comments} onChange={setComments} disabled={loading} />
<NumberField label="Shares" value={shares} onChange={setShares} disabled={loading} />
<NumberField label="Saves" value={saves} onChange={setSaves} disabled={loading} />
<NumberField
label="Retention %"
value={retention}
onChange={setRetention}
disabled={loading}
hint="0–100"
/>
</View>
<Pressable
style={[styles.primary, loading && styles.disabled]}
onPress={submit}
disabled={loading}
>
{loading ? (
<ActivityIndicator color={colors.textPrimary} />
) : (
<Text style={styles.primaryText}>
{isUpdate ? "Update metrics" : "Log metrics"}
</Text>
)}
</Pressable>
</View>
);
}
interface NumberFieldProps {
label: string;
value: string;
onChange: (text: string) => void;
disabled: boolean;
hint?: string;
}
function NumberField({ label, value, onChange, disabled, hint }: NumberFieldProps) {
return (
<View style={styles.field}>
<Text style={styles.fieldLabel}>{label}</Text>
<TextInput
style={styles.input}
value={value}
onChangeText={onChange}
placeholder={hint ?? "0"}
placeholderTextColor={colors.muted}
keyboardType="number-pad"
inputMode="numeric"
maxLength={12}
editable={!disabled}
/>
</View>
);
}
const styles = StyleSheet.create({
form: { gap: 12 },
label: { color: colors.textPrimary, fontSize: 15, fontWeight: "700" },
chips: { flexDirection: "row", flexWrap: "wrap", gap: 8 },
chip: {
backgroundColor: colors.card,
borderColor: colors.border,
borderWidth: 1,
borderRadius: 999,
paddingHorizontal: 16,
paddingVertical: 8,
},
chipActive: { backgroundColor: colors.primary, borderColor: colors.primary },
chipText: { color: colors.textSecondary },
chipTextActive: { color: colors.textPrimary, fontWeight: "700" },
grid: { flexDirection: "row", flexWrap: "wrap", gap: 12 },
field: { flexBasis: "47%", flexGrow: 1, gap: 4 },
fieldLabel: { color: colors.muted, fontSize: 12, fontWeight: "600" },
input: {
backgroundColor: colors.card,
borderColor: colors.border,
borderWidth: 1,
borderRadius: 10,
color: colors.textPrimary,
fontSize: 16,
paddingHorizontal: 14,
paddingVertical: 12,
},
primary: {
backgroundColor: colors.primary,
borderRadius: 12,
paddingVertical: 16,
alignItems: "center",
marginTop: 4,
},
disabled: { opacity: 0.5 },
primaryText: { color: colors.textPrimary, fontSize: 16, fontWeight: "700" },
});