All files / packages/app/features/receipt-components hooks.ts

100% Statements 12/12
100% Branches 4/4
100% Functions 4/4
100% Lines 12/12

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23    88x 38882x 38882x 36785x   2097x 2856x         88x 30325x 30325x     88x 8557x 8557x    
import { useReceiptContext } from "./context";
 
const useSelfRole = () => {
	const { participants, selfPeerId, ownerPeerId } = useReceiptContext();
	if (selfPeerId === ownerPeerId) {
		return "owner";
	}
	return (
		participants.find((participant) => participant.peerId === selfPeerId)
			?.role ?? "viewer"
	);
};
 
export const useCanEdit = () => {
	const selfRole = useSelfRole();
	return selfRole !== "viewer";
};
 
export const useIsOwner = () => {
	const selfRole = useSelfRole();
	return selfRole === "owner";
};