a tool for shared writing and social publishing
at main 749 B view raw
1"use client"; 2import { createContext, useContext } from "react"; 3import { useReplicache } from "src/replicache"; 4 5export const EntitySetContext = createContext({ 6 set: "", 7 permissions: { read: false, write: false }, 8}); 9export const useEntitySetContext = () => useContext(EntitySetContext); 10 11export function EntitySetProvider(props: { 12 set: string; 13 children: React.ReactNode; 14}) { 15 let { permission_token } = useReplicache(); 16 return ( 17 <EntitySetContext.Provider 18 value={{ 19 set: props.set, 20 permissions: permission_token.permission_token_rights.find( 21 (r) => r.entity_set === props.set, 22 ) || { read: false, write: false }, 23 }} 24 > 25 {props.children} 26 </EntitySetContext.Provider> 27 ); 28}