videogen/apps/mobile/app/characters.tsx
caelum0x d56639a594
Some checks are pending
build-images / api (push) Waiting to run
build-images / worker-gpu (push) Waiting to run
build-images / web (push) Waiting to run
codeql / Analyze (javascript-typescript) (push) Waiting to run
codeql / Analyze (python) (push) Waiting to run
perf / API hot-path micro-smoke (budgeted) (push) Waiting to run
perf / Desktop engine crates (release build check) (push) Waiting to run
vision2026-ci / Shared packages (TS≡Python golden parity) (comfy-workflow-schema) (push) Waiting to run
vision2026-ci / Shared packages (TS≡Python golden parity) (effects-core) (push) Waiting to run
vision2026-ci / Shared packages (TS≡Python golden parity) (eventbus-types) (push) Waiting to run
vision2026-ci / Shared packages (TS≡Python golden parity) (growth-analytics) (push) Waiting to run
vision2026-ci / Shared packages (TS≡Python golden parity) (trends-schema) (push) Waiting to run
vision2026-ci / API phase modules (ruff + pytest) (push) Waiting to run
vision2026-ci / Shared packages (TS≡Python golden parity) (provider-adapter-kit) (push) Waiting to run
vision2026-ci / Shared packages (TS≡Python golden parity) (publishing-connectors) (push) Waiting to run
vision2026-ci / Shared packages (TS≡Python golden parity) (render-core) (push) Waiting to run
vision2026-ci / Shared packages (TS≡Python golden parity) (shot-template-schema) (push) Waiting to run
vision2026-ci / Python SDK resource tests (push) Waiting to run
vision2026-ci / Desktop engine crates (test + clippy + fmt) (push) Waiting to run
vision2026-ci / Alembic upgrade + drift check (push) Waiting to run
vision2026-ci / Shared packages (TS≡Python golden parity) (caption-engine) (push) Waiting to run
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

197 lines
6.0 KiB
TypeScript

/**
* Characters screen — browse saved character identities and create new ones on
* mobile. Mirrors the web characters gallery.
*/
import * as React from "react";
import {
ActivityIndicator,
Pressable,
ScrollView,
StyleSheet,
Text,
TextInput,
View,
} from "react-native";
import { colors } from "@/components/me/theme";
import { useSession } from "@/src/shared/auth";
import { createCharacter, listCharacters, type Character } from "@/lib/characters";
export default function CharactersScreen() {
const { apiKey } = useSession();
const token = apiKey ?? undefined;
const [characters, setCharacters] = React.useState<Character[]>([]);
const [loading, setLoading] = React.useState(true);
const [error, setError] = React.useState("");
const [name, setName] = React.useState("");
const [descriptors, setDescriptors] = React.useState("");
const [style, setStyle] = React.useState("");
const [submitting, setSubmitting] = React.useState(false);
const [formError, setFormError] = React.useState("");
React.useEffect(() => {
let active = true;
(async () => {
try {
const res = await listCharacters({ token });
if (active) setCharacters(res.characters);
} catch (err) {
if (active) setError(err instanceof Error ? err.message : "Failed to load characters.");
} finally {
if (active) setLoading(false);
}
})();
return () => {
active = false;
};
}, [token]);
const onCreate = React.useCallback(async () => {
if (!name.trim()) {
setFormError("Name is required.");
return;
}
setSubmitting(true);
setFormError("");
try {
const parsedDescriptors = descriptors
.split(",")
.map((d) => d.trim())
.filter((d) => d.length > 0);
const created = await createCharacter(
{
name: name.trim(),
descriptors: parsedDescriptors.length > 0 ? parsedDescriptors : undefined,
style: style.trim() ? style.trim() : undefined,
},
{ token },
);
setCharacters((prev) => [created, ...prev]);
setName("");
setDescriptors("");
setStyle("");
} catch (err) {
setFormError(err instanceof Error ? err.message : "Failed to create character.");
} finally {
setSubmitting(false);
}
}, [name, descriptors, style, token]);
return (
<ScrollView style={styles.container} contentContainerStyle={styles.content}>
<Text style={styles.intro}>
Reusable character identities keep the same look and voice across every reel.
</Text>
<View style={styles.form}>
<Text style={styles.formTitle}>New character</Text>
<TextInput
style={styles.input}
value={name}
onChangeText={setName}
placeholder="Name"
placeholderTextColor={colors.muted}
/>
<TextInput
style={styles.input}
value={descriptors}
onChangeText={setDescriptors}
placeholder="Descriptors (comma separated)"
placeholderTextColor={colors.muted}
/>
<TextInput
style={styles.input}
value={style}
onChangeText={setStyle}
placeholder="Style"
placeholderTextColor={colors.muted}
/>
{formError ? <Text style={styles.error}>{formError}</Text> : null}
<Pressable
style={[styles.button, submitting && styles.buttonDisabled]}
onPress={onCreate}
disabled={submitting}
>
{submitting ? (
<ActivityIndicator color={colors.bg} />
) : (
<Text style={styles.buttonText}>Create character</Text>
)}
</Pressable>
</View>
<Text style={styles.sectionTitle}>Saved characters</Text>
{loading ? (
<ActivityIndicator color={colors.primary} style={styles.spacer} />
) : error ? (
<Text style={styles.error}>{error}</Text>
) : characters.length === 0 ? (
<Text style={styles.empty}>No characters yet — create your first one above.</Text>
) : (
characters.map((c) => (
<View key={c.id} style={styles.card}>
<Text style={styles.name}>{c.name}</Text>
{c.descriptors.length > 0 ? (
<Text style={styles.desc}>{c.descriptors.join(", ")}</Text>
) : null}
{c.style ? <Text style={styles.meta}>{c.style}</Text> : null}
</View>
))
)}
<View style={styles.spacer} />
</ScrollView>
);
}
const styles = StyleSheet.create({
container: { flex: 1, backgroundColor: colors.bg },
content: { padding: 16 },
intro: { color: colors.textSecondary, fontSize: 14, marginBottom: 16 },
form: {
backgroundColor: colors.card,
borderColor: colors.border,
borderWidth: 1,
borderRadius: 12,
padding: 14,
marginBottom: 20,
},
formTitle: { color: colors.textPrimary, fontSize: 16, fontWeight: "600", marginBottom: 12 },
input: {
backgroundColor: colors.cardAlt,
borderColor: colors.border,
borderWidth: 1,
borderRadius: 8,
paddingHorizontal: 12,
paddingVertical: 10,
color: colors.textPrimary,
fontSize: 14,
marginBottom: 10,
},
button: {
backgroundColor: colors.primary,
borderRadius: 8,
paddingVertical: 12,
alignItems: "center",
marginTop: 4,
},
buttonDisabled: { opacity: 0.6 },
buttonText: { color: colors.bg, fontSize: 14, fontWeight: "600" },
sectionTitle: { color: colors.textPrimary, fontSize: 16, fontWeight: "600", marginBottom: 12 },
card: {
backgroundColor: colors.card,
borderColor: colors.border,
borderWidth: 1,
borderRadius: 12,
padding: 14,
marginBottom: 12,
},
name: { color: colors.textPrimary, fontSize: 16, fontWeight: "600", marginBottom: 4 },
desc: { color: colors.textSecondary, fontSize: 13, marginBottom: 8 },
meta: { color: colors.muted, fontSize: 12 },
empty: { color: colors.muted, fontSize: 14 },
error: { color: colors.error, fontSize: 14, marginBottom: 8 },
spacer: { height: 24 },
});