feat: enhance user limits

This commit is contained in:
gosangam
2026-06-23 14:21:59 +05:30
parent f92b41384e
commit 7b81bbc791
4 changed files with 27 additions and 11 deletions
+3 -4
View File
@@ -8,9 +8,6 @@ import { useAuth } from "@/components/auth/auth-provider";
import { appendHighlight, hasHighlight } from "@/lib/text-highlight";
import { displaySourceLabel } from "@/lib/source-reference";
const FREE_LIMIT = 1;
const PREMIUM_LIMIT = 5;
export default function MyBookmarksPage() {
const { user } = useAuth();
const [list, setList] = useState<Bookmark[]>([]);
@@ -40,7 +37,9 @@ export default function MyBookmarksPage() {
}
}
const limit = user?.role === "admin" || user?.plan === "premium" ? PREMIUM_LIMIT : FREE_LIMIT;
// Effective cap from the server (plan default merged with any admin
// override). -1 would mean unlimited (bookmarks aren't, today).
const limit = user?.limits?.bookmarks ?? 1;
if (loading) return <p className="text-sm text-muted-foreground">Loading…</p>;
+11 -5
View File
@@ -54,7 +54,11 @@ export default function MyCollectionsPage() {
}
}
const isPremium = user?.plan === "premium";
// Effective per-visibility caps from the server (plan default merged with any
// admin override). -1 means unlimited (premium default).
const pubLimit = user?.limits?.public_collections ?? 5;
const privLimit = user?.limits?.private_collections ?? 5;
const unlimited = pubLimit < 0 && privLimit < 0;
const publicCount = list.filter((c) => c.is_public).length;
const privateCount = list.filter((c) => !c.is_public).length;
@@ -62,12 +66,14 @@ export default function MyCollectionsPage() {
<div className="space-y-5">
<div className="flex items-center justify-between">
<p className="text-sm text-muted-foreground">
{isPremium ? (
<>Premium — unlimited collections.</>
{unlimited ? (
<>Unlimited collections.</>
) : (
<>
<span className="tabular-nums">{publicCount}</span> / 5 public ·{" "}
<span className="tabular-nums">{privateCount}</span> / 5 private
<span className="tabular-nums">{publicCount}</span> / {pubLimit}{" "}
public ·{" "}
<span className="tabular-nums">{privateCount}</span> / {privLimit}{" "}
private
</>
)}
</p>
+5 -2
View File
@@ -73,8 +73,11 @@ export function TextSelectionToolbar() {
};
}, [user]);
const bookmarkLimit = user?.plan === "premium" ? 5 : 1;
const limitReached = !!user && bookmarkCount >= bookmarkLimit;
// Effective bookmark cap from the server (plan default merged with any admin
// override). -1 would mean unlimited (never reached).
const bookmarkLimit = user?.limits?.bookmarks ?? 1;
const limitReached =
!!user && bookmarkLimit >= 0 && bookmarkCount >= bookmarkLimit;
// Track whether the user is interacting with our toolbar/popovers
const interactingRef = useRef(false);
+8
View File
@@ -49,6 +49,14 @@ export type User = {
* later — surfaced here for completeness, no UI edits them today. */
preferred_chanting_time: string | null;
peak_active_time: string | null;
/** Effective save limits in force for this user (plan default merged with
* any admin override). -1 means unlimited. Drives the "X / Y used" displays
* and the create-action gates. */
limits: {
bookmarks: number;
public_collections: number;
private_collections: number;
};
created_at: string;
updated_at: string;
};