Skip to content

Prompt as Code | GPT Image 2 / 2.5 提示词与案例库,530+ 个案例、20+ 套工业级模板与可复用 Skills,新增 2.5 同提示词对比专区,附完整提示词与生成记录,持续更新。

Add user case favorites

freestylefly4e0ab9962d5f
diff --git a/README.md b/README.md
index 5aed35a..ae78c75 100644
--- a/README.md
+++ b/README.md
@@ -318,6 +318,7 @@ Setup checklist:
- Apply [`supabase/migrations/20260509090000_membership_billing.sql`](supabase/migrations/20260509090000_membership_billing.sql) to add membership plans, credit packs, Stripe order records, and credit adjustment RPCs.
- Apply [`supabase/migrations/20260512090000_google_account_center.sql`](supabase/migrations/20260512090000_google_account_center.sql) to add account usage summaries and forced credit charging for super admins.
- Apply [`supabase/migrations/20260512143000_pricing_admin_metrics.sql`](supabase/migrations/20260512143000_pricing_admin_metrics.sql) to update the `$5 / 300 credits` catalog and add admin dashboard metrics.
+- Apply [`supabase/migrations/20260515090000_case_favorites.sql`](supabase/migrations/20260515090000_case_favorites.sql) to add per-user case favorites.
- Add `https://gpt-image2.canghe.ai` and local dev URLs such as `http://127.0.0.1:5173` to Supabase Auth redirect URLs.
- Enable the Google Provider after adding Google OAuth credentials in the Supabase Dashboard.
- To force Google-only sign-in, disable the Email Provider in Supabase Auth settings.
diff --git a/README.zh-CN.md b/README.zh-CN.md
index ce8d154..a3ad057 100644
--- a/README.zh-CN.md
+++ b/README.zh-CN.md
@@ -316,6 +316,7 @@ GOOGLE_ANALYTICS_REFRESH_TOKEN=
- 将 [`supabase/migrations/20260509090000_membership_billing.sql`](supabase/migrations/20260509090000_membership_billing.sql) 应用到 Supabase 项目,添加会员套餐、积分包、Stripe 订单记录和积分调整 RPC。
- 将 [`supabase/migrations/20260512090000_google_account_center.sql`](supabase/migrations/20260512090000_google_account_center.sql) 应用到 Supabase 项目,添加账户用量统计和超级管理员强制扣积分逻辑。
- 将 [`supabase/migrations/20260512143000_pricing_admin_metrics.sql`](supabase/migrations/20260512143000_pricing_admin_metrics.sql) 应用到 Supabase 项目,更新 `$5 / 300 credits` 价格体系,并添加管理员数据看板指标。
+- 将 [`supabase/migrations/20260515090000_case_favorites.sql`](supabase/migrations/20260515090000_case_favorites.sql) 应用到 Supabase 项目,添加用户案例收藏表。
- 在 Supabase Auth Redirect URLs 里加入 `https://gpt-image2.canghe.ai`,以及 `http://127.0.0.1:5173` 等本地开发地址。
- 在 Supabase Dashboard 填入 Google OAuth 凭据并启用 Google Provider。
- 如需强制只允许 Google 登录,可以在 Supabase Auth settings 里关闭 Email Provider。
diff --git a/api/favorites.js b/api/favorites.js
new file mode 100644
index 0000000..79cc5c1
--- /dev/null
+++ b/api/favorites.js
@@ -0,0 +1,137 @@
+import fs from 'node:fs/promises';
+import path from 'node:path';
+import { getAuthContext } from './_lib/supabase.js';
+import { readJsonBody } from './_lib/billing.js';
+
+let validCaseIds;
+
+function json(res, status, payload) {
+ res.status(status).json(payload);
+}
+
+function parseCaseId(value) {
+ const caseId = Number(value);
+ return Number.isInteger(caseId) && caseId > 0 ? caseId : null;
+}
+
+async function getValidCaseIds() {
+ if (validCaseIds) return validCaseIds;
+
+ try {
+ const file = await fs.readFile(path.join(process.cwd(), 'data/cases.json'), 'utf8');
+ const payload = JSON.parse(file);
+ validCaseIds = new Set((payload.cases || []).map((item) => Number(item.id)).filter(Number.isInteger));
+ } catch {
+ validCaseIds = new Set();
+ }
+
+ return validCaseIds;
+}
+
+async function isValidCase(caseId) {
+ const ids = await getValidCaseIds();
+ return ids.size === 0 || ids.has(caseId);
+}
+
+function formatFavorite(row) {
+ return {
+ id: row.id,
+ caseId: Number(row.case_id),
+ createdAt: row.created_at || ''
+ };
+}
+
+export default async function handler(req, res) {
+ if (!['GET', 'POST', 'DELETE'].includes(req.method)) {
+ res.setHeader('Allow', 'GET, POST, DELETE');
+ return json(res, 405, { ok: false, error: 'METHOD_NOT_ALLOWED' });
+ }
+
+ const auth = await getAuthContext(req);
+ if (auth.error) {
+ return json(res, auth.status || 401, {
+ ok: false,
+ error: auth.error,
+ loginRequired: auth.error === 'AUTH_REQUIRED'
+ });
+ }
+
+ if (req.method === 'GET') {
+ const { data, error } = await auth.client
+ .from('case_favorites')
+ .select('id,case_id,created_at')
+ .eq('user_id', auth.user.id)
+ .order('created_at', { ascending: false });
+
+ if (error) {
+ console.warn('Failed to load case favorites', {
+ userId: auth.user.id,
+ message: String(error?.message || 'unknown').slice(0, 240)
+ });
+ return json(res, 500, { ok: false, error: 'FAVORITES_LOAD_FAILED' });
+ }
+
+ const favorites = (data || []).map(formatFavorite);
+ return json(res, 200, {
+ ok: true,
+ favorites,
+ caseIds: favorites.map((favorite) => favorite.caseId)
+ });
+ }
+
+ if (req.method === 'POST') {
+ let body;
+ try {
+ body = await readJsonBody(req);
+ } catch {
+ return json(res, 400, { ok: false, error: 'INVALID_CASE' });
+ }
+
+ const caseId = parseCaseId(body.caseId || body.case_id);
+ if (!caseId || !(await isValidCase(caseId))) {
+ return json(res, 400, { ok: false, error: 'INVALID_CASE' });
+ }
+
+ const { data, error } = await auth.client
+ .from('case_favorites')
+ .upsert(
+ { user_id: auth.user.id, case_id: caseId },
+ { onConflict: 'user_id,case_id', ignoreDuplicates: false }
+ )
+ .select('id,case_id,created_at')
+ .single();
+
+ if (error) {
+ console.warn('Failed to save case favorite', {
+ userId: auth.user.id,
+ caseId,
+ message: String(error?.message || 'unknown').slice(0, 240)
+ });
+ return json(res, 500, { ok: false, error: 'FAVORITE_SAVE_FAILED' });
+ }
+
+ return json(res, 200, { ok: true, favorite: formatFavorite(data) });
+ }
+
+ const caseId = parseCaseId(req.query?.caseId || req.query?.case_id);
+ if (!caseId || !(await isValidCase(caseId))) {
+ return json(res, 400, { ok: false, error: 'INVALID_CASE' });
+ }
+
+ const { error } = await auth.client
+ .from('case_favorites')
+ .delete()
+ .eq('user_id', auth.user.id)
+ .eq('case_id', caseId);
+
+ if (error) {
+ console.warn('Failed to delete case favorite', {
+ userId: auth.user.id,
+ caseId,
+ message: String(error?.message || 'unknown').slice(0, 240)
+ });
+ return json(res, 500, { ok: false, error: 'FAVORITE_DELETE_FAILED' });
+ }
+
+ return json(res, 200, { ok: true, caseId });
+}
diff --git a/src/main.jsx b/src/main.jsx
index 2c4193e..841ead3 100644
--- a/src/main.jsx
+++ b/src/main.jsx
@@ -12,6 +12,7 @@ import {
Crown,
Eye,
Github,
+ Heart,
ImageIcon,
LoaderCircle,
LogIn,
@@ -89,6 +90,15 @@ const copy = {
copied: 'Copied',
copyPrompt: 'Copy Prompt',
copyTemplatePrompt: 'Copy Template',
+ favorite: 'Favorite',
+ favorited: 'Favorited',
+ unfavorite: 'Remove Favorite',
+ myFavorites: 'My Favorites',
+ noFavorites: 'No favorites yet.',
+ signInToFavorite: 'Sign in to save favorite cases.',
+ favoriteSaved: 'Favorite saved.',
+ favoriteRemoved: 'Favorite removed.',
+ favoriteFailed: 'Favorite update failed. Please try again.',
closePreview: 'Close preview',
viewDetails: 'View Details',
generateTest: 'Generate Test',
@@ -284,6 +294,15 @@ const copy = {
copied: '已复制',
copyPrompt: '复制 Prompt',
copyTemplatePrompt: '复制模板',
+ favorite: '收藏',
+ favorited: '已收藏',
+ unfavorite: '取消收藏',
+ myFavorites: '我的收藏',
+ noFavorites: '暂无收藏案例。',
+ signInToFavorite: '登录后即可收藏案例。',
+ favoriteSaved: '已加入收藏。',
+ favoriteRemoved: '已取消收藏。',
+ favoriteFailed: '收藏更新失败,请稍后再试。',
closePreview: '关闭预览',
viewDetails: '查看详情',
generateTest: '生成测试',
@@ -623,6 +642,16 @@ function saveGeneratedTest(caseId, entry) {
}
}
+function normalizeFavoriteRows(favorites = []) {
+ const rows = Array.isArray(favorites) ? favorites : [];
+ return rows
+ .map((favorite) => ({
+ caseId: Number(favorite.caseId || favorite.case_id),
+ createdAt: favorite.createdAt || favorite.created_at || ''
+ }))
+ .filter((favorite) => Number.isInteger(favorite.caseId) && favorite.caseId > 0);
+}
+
function takeDistinctCases(cases, count, excludedIds = new Set()) {
const picked = [];
const seenIds = new Set(excludedIds);
@@ -1128,7 +1157,7 @@ function AuthModal({ open, language, onClose }) {
);
}
-function UserMenu({ language, session, profile, onSignIn, onSignOut, onAdmin, onBilling, onAccount }) {
+function UserMenu({ language, session, profile, onSignIn, onSignOut, onAdmin, onBilling, onAccount, onFavorites }) {
const t = copy[language];
const [open, setOpen] = useState(false);
const ref = useDropdownDismiss(open, setOpen);
@@ -1204,6 +1233,18 @@ function UserMenu({ language, session, profile, onSignIn, onSignOut, onAdmin, on
<Settings size={17} />
{t.accountSettings}
</button>
+ <button
+ className="dropdownAction"
+ type="button"
+ role="menuitem"
+ onClick={() => {
+ setOpen(false);
+ onFavorites();
+ }}
+ >
+ <Heart size={17} />
+ {t.myFavorites}
+ </button>
<button
className="dropdownAction"
type="button"
@@ -1254,6 +1295,7 @@ function AccountPanel({
session,
profile,
casesById,
+ favoriteRows,
onClose,
onBilling,
onProfileChange,
@@ -1278,6 +1320,12 @@ function AccountPanel({
const usage = profile?.usage || {};
const recentTransactions = profile?.recentTransactions || [];
const generationTransactions = recentTransactions.filter((transaction) => transaction.type === 'generation');
+ const favoriteCases = normalizeFavoriteRows(favoriteRows)
+ .map((favorite) => ({
+ ...favorite,
+ caseItem: casesById?.get(favorite.caseId)
+ }))
+ .filter((favorite) => favorite.caseItem);
async function handleSubmit(event) {
event.preventDefault();
@@ -1391,6 +1439,36 @@ function AccountPanel({
</section>
</div>
+ <section className="transactionSection favoritesSection">
+ <h3>
+ <Heart size={18} />
+ {t.myFavorites}
+ </h3>
+ {favoriteCases.length ? (
+ <div className="favoriteGrid">
+ {favoriteCases.map(({ caseId, createdAt, caseItem }) => (
+ <button
+ className="favoriteCard"
+ type="button"
+ onClick={() => onOpenCase?.(caseItem)}
+ key={caseId}
+ >
+ <img src={caseItem.image} alt={caseItem.imageAlt} />
+ <span>#{caseId}</span>
+ <strong>{caseItem.title}</strong>
+ <em>
+ {createdAt
+ ? new Date(createdAt).toLocaleDateString(language === 'zh' ? 'zh-CN' : 'en-US')
+ : localizeLabel(caseItem.category, language, null)}
+ </em>
+ </button>
+ ))}
+ </div>
+ ) : (
+ <p className="emptyTransactions">{t.noFavorites}</p>
+ )}
+ </section>
+
<section className="transactionSection accountTransactions">
<h3>
<ReceiptText size={18} />
@@ -2397,7 +2475,18 @@ function TemplateSection({ language, styleLibrary, onOpenTemplate }) {
);
}
-function PromptCard({ caseItem, copied, language, onCopy, onOpen, onGenerate, styleLibrary }) {
+function PromptCard({
+ caseItem,
+ copied,
+ favorited,
+ favoriteBusy,
+ language,
+ onCopy,
+ onOpen,
+ onGenerate,
+ onToggleFavorite,
+ styleLibrary
+}) {
const t = copy[language];
const tags = [...new Set([...caseItem.styles, ...caseItem.scenes])].slice(0, 4);
@@ -2430,6 +2519,16 @@ function PromptCard({ caseItem, copied, language, onCopy, onOpen, onGenerate, st
))}
</div>
<div className="cardActions caseActions">
+ <button
+ className={cx('favoriteAction', favorited && 'active')}
+ type="button"
+ onClick={() => onToggleFavorite(caseItem)}
+ disabled={favoriteBusy}
+ aria-pressed={Boolean(favorited)}
+ >
+ {favoriteBusy ? <LoaderCircle className="spinIcon" size={17} /> : <Heart size={17} />}
+ {favorited ? t.favorited : t.favorite}
+ </button>
<button type="button" onClick={() => onCopy(caseItem)}>
{copied ? <Check size={17} /> : <Copy size={17} />}
{copied ? t.copied : t.copyPrompt}
@@ -2458,8 +2557,11 @@ function PreviewDialog({
copiedId,
session,
profile,
+ favorite,
+ favoriteBusy,
onClose,
onCopyText,
+ onToggleFavorite,
onAuthRequired,
onBillingRequired,
onProfileChange
@@ -2657,6 +2759,18 @@ function PreviewDialog({
</div>
) : null}
<div className="previewActions">
+ {!isTemplate ? (
+ <button
+ className={cx('favoriteAction', favorite && 'active')}
+ type="button"
+ onClick={() => onToggleFavorite(item)}
+ disabled={favoriteBusy}
+ aria-pressed={Boolean(favorite)}
+ >
+ {favoriteBusy ? <LoaderCircle className="spinIcon" size={17} /> : <Heart size={17} />}
+ {favorite ? t.unfavorite : t.favorite}
+ </button>
+ ) : null}
<button type="button" onClick={() => onCopyText(promptText, copyId)}>
{isCopied ? <Check size={17} /> : <Copy size={17} />}
{isCopied ? t.copied : isTemplate ? t.copyTemplatePrompt : t.copyPrompt}
@@ -2771,6 +2885,9 @@ function App() {
const [preview, setPreview] = useState(null);
const [session, setSession] = useState(null);
const [profile, setProfile] = useState(null);
+ const [favoriteRows, setFavoriteRows] = useState([]);
+ const [favoriteBusyId, setFavoriteBusyId] = useState(null);
+ const [favoriteMessage, setFavoriteMessage] = useState('');
const [authOpen, setAuthOpen] = useState(false);
const [accountOpen, setAccountOpen] = useState(false);
const [adminOpen, setAdminOpen] = useState(false);
@@ -2825,6 +2942,7 @@ function App() {
if (!session?.access_token) {
setProfile(null);
+ setFavoriteRows([]);
return () => {
cancelled = true;
};
@@ -2848,6 +2966,34 @@ function App() {
};
}, [session?.access_token]);
+ useEffect(() => {
+ let cancelled = false;
+
+ if (!session?.access_token) {
+ setFavoriteRows([]);
+ return () => {
+ cancelled = true;
+ };
+ }
+
+ fetch('/api/favorites', {
+ headers: getAuthHeaders(session)
+ })
+ .then((response) => response.json())
+ .then((payload) => {
+ if (!cancelled && payload?.ok) {
+ setFavoriteRows(normalizeFavoriteRows(payload.favorites));
+ }
+ })
+ .catch(() => {
+ if (!cancelled) setFavoriteRows([]);
+ });
+
+ return () => {
+ cancelled = true;
+ };
+ }, [session?.access_token]);
+
useEffect(() => {
if (!siteData || !styleLibrary || !window.location.hash) return;
const target = document.getElementById(window.location.hash.slice(1));
@@ -2921,11 +3067,16 @@ function App() {
const visibleCases = filteredCases.slice(0, 72);
const casesById = useMemo(() => new Map((siteData?.cases || []).map((caseItem) => [caseItem.id, caseItem])), [siteData]);
+ const favoriteCaseIds = useMemo(
+ () => new Set(normalizeFavoriteRows(favoriteRows).map((favorite) => favorite.caseId)),
+ [favoriteRows]
+ );
async function handleSignOut() {
if (supabase) await supabase.auth.signOut();
setSession(null);
setProfile(null);
+ setFavoriteRows([]);
setAccountOpen(false);
setAdminOpen(false);
setBillingOpen(false);
@@ -2946,6 +3097,69 @@ function App() {
setPreview({ type: 'case', item: caseItem });
}
+ function setTimedFavoriteMessage(message) {
+ setFavoriteMessage(message);
+ window.setTimeout(() => {
+ setFavoriteMessage((current) => (current === message ? '' : current));
+ }, 2400);
+ }
+
+ async function handleToggleFavorite(caseItem) {
+ if (!caseItem?.id) return;
+ if (!session?.access_token) {
+ setAuthOpen(true);
+ setTimedFavoriteMessage(t.signInToFavorite);
+ return;
+ }
+
+ const caseId = Number(caseItem.id);
+ const isFavorite = favoriteCaseIds.has(caseId);
+ const previousRows = favoriteRows;
+ setFavoriteBusyId(caseId);
+
+ if (isFavorite) {
+ setFavoriteRows((current) => normalizeFavoriteRows(current).filter((favorite) => favorite.caseId !== caseId));
+ } else {
+ setFavoriteRows((current) => [
+ { caseId, createdAt: new Date().toISOString() },
+ ...normalizeFavoriteRows(current).filter((favorite) => favorite.caseId !== caseId)
+ ]);
+ }
+
+ try {
+ const response = await fetch(isFavorite ? `/api/favorites?caseId=${caseId}` : '/api/favorites', {
+ method: isFavorite ? 'DELETE' : 'POST',
+ headers: {
+ ...(isFavorite ? {} : { 'Content-Type': 'application/json' }),
+ ...getAuthHeaders(session)
+ },
+ body: isFavorite ? undefined : JSON.stringify({ caseId })
+ });
+ const payload = await response.json().catch(() => ({}));
+
+ if (!response.ok || !payload.ok) {
+ if (payload.error === 'AUTH_REQUIRED' || payload.loginRequired) setAuthOpen(true);
+ throw new Error(payload.error || 'FAVORITE_FAILED');
+ }
+
+ if (!isFavorite && payload.favorite) {
+ const favorite = normalizeFavoriteRows([payload.favorite])[0];
+ if (favorite) {
+ setFavoriteRows((current) => [
+ favorite,
+ ...normalizeFavoriteRows(current).filter((item) => item.caseId !== caseId)
+ ]);
+ }
+ }
+ setTimedFavoriteMessage(isFavorite ? t.favoriteRemoved : t.favoriteSaved);
+ } catch {
+ setFavoriteRows(previousRows);
+ setTimedFavoriteMessage(t.favoriteFailed);
+ } finally {
+ setFavoriteBusyId(null);
+ }
+ }
+
if (!siteData || !styleLibrary) {
return (
<main>
@@ -2982,6 +3196,7 @@ function App() {
onSignIn={() => setAuthOpen(true)}
onSignOut={handleSignOut}
onAccount={() => setAccountOpen(true)}
+ onFavorites={() => setAccountOpen(true)}
onAdmin={() => setAdminOpen(true)}
onBilling={() => {
setBillingNotice('');
@@ -2990,6 +3205,7 @@ function App() {
/>
</div>
</header>
+ {favoriteMessage ? <div className="toastNotice">{favoriteMessage}</div> : null}
<Hero
latestCases={heroCases}
@@ -3079,6 +3295,8 @@ function App() {
<PromptCard
caseItem={caseItem}
copied={copiedId === `case-${caseItem.id}`}
+ favorited={favoriteCaseIds.has(caseItem.id)}
+ favoriteBusy={favoriteBusyId === caseItem.id}
language={language}
onCopy={copyPrompt}
onOpen={(item) => setPreview({ type: 'case', item })}
@@ -3086,6 +3304,7 @@ function App() {
setPreview({ type: 'case', item });
if (!session?.access_token) setAuthOpen(true);
}}
+ onToggleFavorite={handleToggleFavorite}
styleLibrary={styleLibrary}
key={caseItem.id}
/>
@@ -3113,8 +3332,11 @@ function App() {
copiedId={copiedId}
session={session}
profile={profile}
+ favorite={preview?.type === 'case' ? favoriteCaseIds.has(preview.item.id) : false}
+ favoriteBusy={preview?.type === 'case' && favoriteBusyId === preview.item.id}
onClose={() => setPreview(null)}
onCopyText={copyText}
+ onToggleFavorite={handleToggleFavorite}
onAuthRequired={() => setAuthOpen(true)}
onBillingRequired={() => {
setBillingNotice(t.creditsRequired);
@@ -3133,6 +3355,7 @@ function App() {
session={session}
profile={profile}
casesById={casesById}
+ favoriteRows={favoriteRows}
onClose={() => setAccountOpen(false)}
onProfileChange={handleProfileChange}
onOpenCase={handleOpenCaseFromAccount}
diff --git a/src/styles.css b/src/styles.css
index 3792dbc..7a2de5e 100644
--- a/src/styles.css
+++ b/src/styles.css
@@ -1345,10 +1345,6 @@ button {
grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) 42px;
}
-.caseActions button:first-child {
- grid-column: 1 / -1;
-}
-
.templateActions {
grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
}
@@ -1376,6 +1372,16 @@ button {
background: rgba(120, 255, 185, 0.14);
}
+.favoriteAction.active {
+ border-color: rgba(255, 113, 161, 0.44);
+ background: rgba(255, 113, 161, 0.13);
+ color: #ffd6e4;
+}
+
+.favoriteAction.active svg {
+ fill: currentColor;
+}
+
.cardActions button:disabled,
.previewActions button:disabled,
.generationPanel button:disabled {
@@ -1581,6 +1587,12 @@ button {
color: #d8ffe4;
}
+.previewActions .favoriteAction.active {
+ border-color: rgba(255, 113, 161, 0.44);
+ background: rgba(255, 113, 161, 0.13);
+ color: #ffd6e4;
+}
+
.previewActions button:hover,
.previewActions a:hover {
border-color: rgba(103, 232, 249, 0.7);
@@ -1591,6 +1603,22 @@ button {
animation: spin 0.9s linear infinite;
}
+.toastNotice {
+ position: fixed;
+ top: 86px;
+ right: max(18px, calc((100vw - 1180px) / 2));
+ z-index: 80;
+ max-width: min(360px, calc(100vw - 32px));
+ border: 1px solid rgba(120, 255, 185, 0.28);
+ border-radius: 8px;
+ padding: 11px 13px;
+ background: rgba(8, 14, 28, 0.94);
+ color: #d8ffe4;
+ font-size: 13px;
+ font-weight: 900;
+ box-shadow: 0 18px 60px rgba(0, 0, 0, 0.34);
+}
+
.previewSection {
margin-top: 22px;
}
@@ -2746,6 +2774,58 @@ button {
gap: 8px;
}
+.favoriteGrid {
+ display: grid;
+ grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
+ gap: 10px;
+}
+
+.favoriteCard {
+ display: grid;
+ gap: 7px;
+ min-width: 0;
+ border: 1px solid rgba(255, 255, 255, 0.11);
+ border-radius: 8px;
+ padding: 8px;
+ background: rgba(3, 7, 15, 0.5);
+ color: #ffffff;
+ text-align: left;
+}
+
+.favoriteCard:hover {
+ border-color: rgba(103, 232, 249, 0.48);
+ background: rgba(103, 232, 249, 0.1);
+}
+
+.favoriteCard img {
+ width: 100%;
+ aspect-ratio: 4 / 3;
+ border-radius: 7px;
+ object-fit: cover;
+}
+
+.favoriteCard span {
+ width: fit-content;
+ border-radius: 999px;
+ padding: 3px 7px;
+ background: rgba(120, 255, 185, 0.1);
+ color: #c8ffb8;
+ font-size: 12px;
+ font-weight: 900;
+}
+
+.favoriteCard strong {
+ color: #eaf3ff;
+ font-size: 13px;
+ line-height: 1.35;
+}
+
+.favoriteCard em {
+ color: #93a4bc;
+ font-size: 12px;
+ font-style: normal;
+}
+
.transactionItem {
display: grid;
grid-template-columns: minmax(0, 1fr) auto auto;
diff --git a/supabase/migrations/20260515090000_case_favorites.sql b/supabase/migrations/20260515090000_case_favorites.sql
new file mode 100644
index 0000000..a9f0473
--- /dev/null
+++ b/supabase/migrations/20260515090000_case_favorites.sql
@@ -0,0 +1,32 @@
+create table if not exists public.case_favorites (
+ id uuid primary key default gen_random_uuid(),
+ user_id uuid not null references auth.users(id) on delete cascade,
+ case_id integer not null check (case_id > 0),
+ created_at timestamptz not null default now(),
+ unique (user_id, case_id)
+);
+
+create index if not exists case_favorites_user_created_idx
+ on public.case_favorites (user_id, created_at desc);
+
+create index if not exists case_favorites_case_id_idx
+ on public.case_favorites (case_id);
+
+alter table public.case_favorites enable row level security;
+
+grant select, insert, delete on public.case_favorites to authenticated;
+
+drop policy if exists "Users can read own case favorites" on public.case_favorites;
+create policy "Users can read own case favorites"
+ on public.case_favorites for select
+ using ((select auth.uid()) = user_id);
+
+drop policy if exists "Users can create own case favorites" on public.case_favorites;
+create policy "Users can create own case favorites"
+ on public.case_favorites for insert
+ with check ((select auth.uid()) = user_id);
+
+drop policy if exists "Users can delete own case favorites" on public.case_favorites;
+create policy "Users can delete own case favorites"
+ on public.case_favorites for delete
+ using ((select auth.uid()) = user_id);