'init'
This commit is contained in:
30
app/providers/BlacklistProvider/useBlacklist.ts
Normal file
30
app/providers/BlacklistProvider/useBlacklist.ts
Normal file
@@ -0,0 +1,30 @@
|
||||
import { useContext } from "react";
|
||||
import { BlacklistContext } from "./BlacklistProvider";
|
||||
|
||||
export function useBlacklist(publicKey : string) : [
|
||||
boolean,
|
||||
() => void,
|
||||
() => void
|
||||
] {
|
||||
const context = useContext(BlacklistContext);
|
||||
if(!context){
|
||||
throw new Error("useBlacklist must be used within a BlacklistProvider");
|
||||
}
|
||||
|
||||
const {isUserBlocked, blockUser, unblockUser} = context;
|
||||
const blocked = isUserBlocked(publicKey);
|
||||
|
||||
const block = () => {
|
||||
blockUser(publicKey);
|
||||
}
|
||||
|
||||
const unblock = () => {
|
||||
unblockUser(publicKey);
|
||||
}
|
||||
|
||||
return [
|
||||
blocked,
|
||||
block,
|
||||
unblock
|
||||
]
|
||||
}
|
||||
Reference in New Issue
Block a user