videogen/apps/mobile/components/me/PresetsSection.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

106 lines
3.1 KiB
TypeScript

/**
* PRESETS section of the Me tab. Lists the caller's saved presets (GET
* /me/presets), creates new ones (POST /me/presets) and deletes them (DELETE
* /me/presets/{id}) with optimistic list updates and a re-sync on failure.
*/
import { useCallback } from "react";
import { StyleSheet, Text, View } from "react-native";
import {
createPreset,
deletePreset,
listMyWorkspaces,
listPresets,
} from "@/lib/api";
import type {
Preset,
PresetCreateRequest,
Workspace,
} from "@/lib/types";
import { PresetCard } from "./PresetCard";
import { PresetCreateForm } from "./PresetCreateForm";
import { Section, SectionState } from "./Section";
import { colors } from "./theme";
import { useResource } from "./use-resource";
interface PresetsSectionProps {
token: string | undefined;
}
export function PresetsSection({ token }: PresetsSectionProps) {
const fetcher = useCallback(() => listPresets({ token }), [token]);
const { status, data, error, reload, setData } = useResource<Preset[]>(fetcher);
// Workspaces the caller can share a brand kit with. A failure here degrades
// gracefully — the "Share to team" picker simply hides and presets stay
// personal (never blocks the presets list or personal preset creation).
const workspacesFetcher = useCallback(
() => listMyWorkspaces({ token }).catch(() => [] as Workspace[]),
[token],
);
const { data: workspacesData } = useResource<Workspace[]>(workspacesFetcher);
const workspaces = workspacesData ?? [];
const presets = data ?? [];
const onCreate = useCallback(
async (body: PresetCreateRequest) => {
const created = await createPreset(body, { token });
// Prepend the new preset (backend returns newest-first).
setData((prev) => [created, ...(prev ?? [])]);
},
[token, setData],
);
const onDelete = useCallback(
async (id: string) => {
const previous = data;
// Optimistically drop the row, then confirm with the backend.
setData((prev) => (prev ?? []).filter((p) => p.id !== id));
try {
await deletePreset(id, { token });
} catch (err) {
// Roll back to the last known-good list on failure.
setData(() => previous);
throw err;
}
},
[token, data, setData],
);
return (
<Section title="PRESETS">
<View style={styles.stack}>
<PresetCreateForm onCreate={onCreate} workspaces={workspaces} />
<SectionState status={status} error={error} onRetry={reload}>
{presets.length === 0 ? (
<Text style={styles.empty}>
No presets yet. Save a favourite avatar / voice / layout combo to
reuse on every new reel.
</Text>
) : (
<View style={styles.list}>
{presets.map((preset) => (
<PresetCard key={preset.id} preset={preset} onDelete={onDelete} />
))}
</View>
)}
</SectionState>
</View>
</Section>
);
}
const styles = StyleSheet.create({
stack: { gap: 12 },
list: { gap: 10 },
empty: {
color: colors.muted,
fontSize: 13,
lineHeight: 18,
paddingVertical: 8,
},
});