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
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.
104 lines
3.1 KiB
TypeScript
104 lines
3.1 KiB
TypeScript
/**
|
|
* INSIGHTS section of the Me tab. Fetches GET /me/insights and renders a grid
|
|
* of stat cards derived from the caller-scoped {@link Insights} payload.
|
|
*/
|
|
|
|
import { useCallback } from "react";
|
|
import { StyleSheet, Text, View } from "react-native";
|
|
|
|
import { getInsights } from "@/lib/api";
|
|
import type { Insights } from "@/lib/types";
|
|
|
|
import { Section, SectionState } from "./Section";
|
|
import { StatCard } from "./StatCard";
|
|
import { formatCount, formatDuration, formatStateLabel, formatUsd } from "./format";
|
|
import { colors } from "./theme";
|
|
import { useResource } from "./use-resource";
|
|
|
|
interface InsightsSectionProps {
|
|
token: string | undefined;
|
|
}
|
|
|
|
export function InsightsSection({ token }: InsightsSectionProps) {
|
|
const fetcher = useCallback(() => getInsights({ token }), [token]);
|
|
const { status, data, error, reload } = useResource<Insights>(fetcher);
|
|
|
|
return (
|
|
<Section title="INSIGHTS">
|
|
<SectionState status={status} error={error} onRetry={reload}>
|
|
{data ? <InsightsGrid insights={data} /> : null}
|
|
</SectionState>
|
|
</Section>
|
|
);
|
|
}
|
|
|
|
function InsightsGrid({ insights }: { insights: Insights }) {
|
|
const byState = Object.entries(insights.jobs_by_state ?? {});
|
|
return (
|
|
<View style={styles.grid}>
|
|
<StatCard
|
|
label="Jobs total"
|
|
value={formatCount(insights.jobs_total)}
|
|
accent={colors.accent}
|
|
/>
|
|
<StatCard
|
|
label="Videos generated"
|
|
value={formatCount(insights.videos_generated)}
|
|
hint="Successfully rendered reels"
|
|
accent={colors.success}
|
|
/>
|
|
<StatCard
|
|
label="Credits balance"
|
|
value={formatCount(insights.credits_balance)}
|
|
hint={`${formatCount(insights.credits_spent)} spent to date`}
|
|
/>
|
|
<StatCard
|
|
label="Credits spent"
|
|
value={formatCount(insights.credits_spent)}
|
|
accent={colors.error}
|
|
/>
|
|
<StatCard
|
|
label="Total cost"
|
|
value={formatUsd(insights.total_cost_usd)}
|
|
hint="Cumulative render spend"
|
|
/>
|
|
<StatCard
|
|
label="Avg. render time"
|
|
value={formatDuration(insights.avg_render_ms)}
|
|
hint="Compose stage, per reel"
|
|
accent={colors.accent}
|
|
/>
|
|
{byState.length > 0 ? (
|
|
<View style={styles.breakdown}>
|
|
{byState.map(([state, count]) => (
|
|
<View key={state} style={styles.breakdownRow}>
|
|
<Text style={styles.breakdownLabel}>{formatStateLabel(state)}</Text>
|
|
<Text style={styles.breakdownValue}>{formatCount(Number(count))}</Text>
|
|
</View>
|
|
))}
|
|
</View>
|
|
) : null}
|
|
</View>
|
|
);
|
|
}
|
|
|
|
const styles = StyleSheet.create({
|
|
grid: { flexDirection: "row", flexWrap: "wrap", gap: 12 },
|
|
breakdown: {
|
|
width: "100%",
|
|
backgroundColor: colors.card,
|
|
borderColor: colors.border,
|
|
borderWidth: 1,
|
|
borderRadius: 12,
|
|
padding: 14,
|
|
gap: 8,
|
|
},
|
|
breakdownRow: {
|
|
flexDirection: "row",
|
|
justifyContent: "space-between",
|
|
alignItems: "center",
|
|
},
|
|
breakdownLabel: { color: colors.textSecondary, fontSize: 14 },
|
|
breakdownValue: { color: colors.textPrimary, fontSize: 14, fontWeight: "700" },
|
|
});
|