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

206 lines
5.9 KiB
TypeScript

/**
* Route: /repurpose/clipping/ingest — turn a web URL into a reel draft.
*
* NAV MANIFEST:
* { route: "/repurpose/clipping/ingest", title: "Import from URL" }
*
* Paste a product/article URL; the backend fetches + extracts it and returns a
* hook-first reel draft (POST /ingest/url) which is previewed here, ready to be
* submitted to the reel pipeline. Client-side URL validation, plus loading /
* error / result states. No job is created by this screen.
*
* Auth flows through the shared api client (x-api-key). No secrets here.
*/
import { useCallback, useState } from "react";
import {
ActivityIndicator,
Pressable,
ScrollView,
StyleSheet,
Text,
TextInput,
View,
} from "react-native";
import { Stack } from "expo-router";
import { ApiError } from "@/src/shared/api";
import { useSession } from "@/src/shared/auth";
import { colors, radius, spacing, typeScale, weight } from "@/src/shared/theme";
import { ingestUrl, looksLikeUrl, type IngestResult } from "@/lib/repurpose";
import { ReelDraftCard } from "@/src/features/repurpose/components/ReelDraftCard";
export default function IngestUrlScreen() {
const { apiKey } = useSession();
const token = apiKey ?? undefined;
const [url, setUrl] = useState("");
const [busy, setBusy] = useState(false);
const [error, setError] = useState<string | null>(null);
const [result, setResult] = useState<IngestResult | null>(null);
const trimmed = url.trim();
const valid = looksLikeUrl(trimmed);
const canSubmit = valid && !busy;
const onSubmit = useCallback(async () => {
const target = url.trim();
if (!looksLikeUrl(target)) {
setError("Enter a valid http(s) URL.");
return;
}
setBusy(true);
setError(null);
setResult(null);
try {
const ingested = await ingestUrl(target, { token });
setResult(ingested);
} catch (err) {
setError(
err instanceof ApiError ? err.message : "Could not import that URL.",
);
} finally {
setBusy(false);
}
}, [url, token]);
return (
<ScrollView
style={styles.container}
contentContainerStyle={styles.content}
keyboardShouldPersistTaps="handled"
>
<Stack.Screen options={{ title: "Import from URL" }} />
<Text style={styles.intro}>
Paste a product page or article URL. We extract the key points and draft
a hook-first reel you can submit to the pipeline.
</Text>
<Text style={styles.label}>Page URL</Text>
<TextInput
style={styles.input}
value={url}
onChangeText={setUrl}
placeholder="https://example.com/product"
placeholderTextColor={colors.textFaint}
autoCapitalize="none"
autoCorrect={false}
keyboardType="url"
editable={!busy}
/>
{trimmed.length > 0 && !valid ? (
<Text style={styles.warn}>That does not look like an http(s) URL.</Text>
) : null}
<Pressable
style={[styles.submit, !canSubmit && styles.submitDim]}
onPress={onSubmit}
disabled={!canSubmit}
accessibilityRole="button"
accessibilityLabel="Import this URL into a reel draft"
accessibilityState={{ busy, disabled: !canSubmit }}
>
{busy ? (
<ActivityIndicator color={colors.onAccent} />
) : (
<Text style={styles.submitText}>Import & draft</Text>
)}
</Pressable>
{error ? <Text style={styles.error}>{error}</Text> : null}
{result ? (
<View style={styles.resultBlock}>
{result.content.title ? (
<>
<Text style={styles.extractLabel}>EXTRACTED</Text>
<Text style={styles.extractTitle}>{result.content.title}</Text>
{result.content.description ? (
<Text style={styles.extractBody} numberOfLines={4}>
{result.content.description}
</Text>
) : null}
</>
) : null}
<ReelDraftCard draft={result.reel_draft} />
<Text style={styles.hint}>
Head to Create to submit this draft to the reel pipeline.
</Text>
</View>
) : null}
<View style={styles.spacer} />
</ScrollView>
);
}
const styles = StyleSheet.create({
container: { flex: 1, backgroundColor: colors.bg },
content: { padding: spacing.lg, gap: spacing.sm },
intro: {
color: colors.textSecondary,
fontSize: typeScale.caption,
lineHeight: 20,
marginBottom: spacing.sm,
},
label: {
color: colors.textPrimary,
fontSize: typeScale.caption,
fontWeight: weight.semibold,
marginBottom: spacing.xs,
},
input: {
backgroundColor: colors.input,
borderColor: colors.border,
borderWidth: 1,
borderRadius: radius.md,
paddingHorizontal: spacing.md,
paddingVertical: spacing.sm + 2,
color: colors.textPrimary,
fontSize: typeScale.body,
},
warn: { color: colors.danger, fontSize: typeScale.micro, marginTop: spacing.xs },
submit: {
backgroundColor: colors.accent,
borderRadius: radius.md,
paddingVertical: spacing.md,
alignItems: "center",
justifyContent: "center",
minHeight: 48,
marginTop: spacing.md,
},
submitDim: { opacity: 0.45 },
submitText: {
color: colors.onAccent,
fontSize: typeScale.body,
fontWeight: weight.bold,
},
error: { color: colors.danger, fontSize: typeScale.caption, lineHeight: 18 },
resultBlock: { gap: spacing.sm, marginTop: spacing.md },
extractLabel: {
color: colors.textFaint,
fontSize: typeScale.micro,
fontWeight: weight.bold,
letterSpacing: 1,
},
extractTitle: {
color: colors.textPrimary,
fontSize: typeScale.subheading,
fontWeight: weight.bold,
},
extractBody: {
color: colors.textSecondary,
fontSize: typeScale.caption,
lineHeight: 19,
},
hint: {
color: colors.textFaint,
fontSize: typeScale.micro,
lineHeight: 16,
},
spacer: { height: 48 },
});