@@ -6,33 +6,44 @@ import { AiSummaryModal } from "~/components/ai-summary";
66import { LinkCard } from "~/components/link-card" ;
77import { LinkTable } from "~/components/link-table" ;
88import { TagPicker } from "~/components/tag-picker" ;
9+ import {
10+ featurePermissionsQuery ,
11+ hasFeaturePermission ,
12+ } from "~/data/feature-permissions" ;
913import { linksQuery } from "~/data/links" ;
1014import { tagsQuery } from "~/data/tags" ;
1115import type { Link } from "~/data/types" ;
1216import type { Route } from "./+types/links" ;
1317import { useGenerateAiSummary } from "./ai-summary.$linkId" ;
1418
1519export async function clientLoader ( _ : Route . ClientLoaderArgs ) {
16- const [ links , tags ] = await Promise . all ( [
20+ const [ links , tags , featurePermissions ] = await Promise . all ( [
1721 linksQuery . getData ( ) ,
1822 tagsQuery . getData ( ) ,
23+ featurePermissionsQuery . getData ( ) ,
1924 ] ) ;
2025
21- return { links, tags } ;
26+ return { links, tags, featurePermissions } ;
2227}
2328
2429export default function Links ( ) {
25- const { links, tags } = useLoaderData < typeof clientLoader > ( ) ;
30+ const { links, tags, featurePermissions } =
31+ useLoaderData < typeof clientLoader > ( ) ;
2632 const navigate = useNavigate ( ) ;
2733 const [ viewMode , setViewMode ] = useState < "grid" | "table" > ( "grid" ) ;
2834 const [ searchQuery , setSearchQuery ] = useState ( "" ) ;
2935 const [ selectedTagFilters , setSelectedTagFilters ] = useState < string [ ] > ( [ ] ) ;
3036 const aiSummary = useGenerateAiSummary ( ) ;
3137
32- if ( ! links . ok || ! tags . ok ) {
38+ if ( ! links . ok || ! tags . ok || ! featurePermissions . ok ) {
3339 throw new Error ( "Failed to load data, please try refreshing the page." ) ;
3440 }
3541
42+ const canCreateAiSummary = hasFeaturePermission (
43+ "ai_summary" ,
44+ featurePermissions . value ,
45+ ) ;
46+
3647 const filteredLinks = links . value . filter ( ( link ) => {
3748 const matchesSearch =
3849 link . name . toLowerCase ( ) . includes ( searchQuery . toLowerCase ( ) ) ||
@@ -86,6 +97,7 @@ export default function Links() {
8697 onEdit = { handleEdit }
8798 onDelete = { handleDelete }
8899 aiSummary = { {
100+ enabled : canCreateAiSummary ,
89101 isPending : aiSummary . isPending ( link . id ) ,
90102 handler : ( ) => aiSummary . submit ( link ) ,
91103 } }
0 commit comments