Add option to delete poll (#174)

This commit is contained in:
Luke Vella 2022-05-18 17:47:23 +01:00 committed by GitHub
parent 2c4157ea24
commit c170e03b6a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
25 changed files with 271 additions and 104 deletions

View file

@ -8,9 +8,15 @@ export interface ModalProviderProps {
children?: React.ReactNode;
}
type ModalContentProps = { close: () => void };
interface ModalConfig extends ModalProps {
content?: React.ReactNode | ((props: ModalContentProps) => React.ReactNode);
}
const ModalContext =
React.createContext<{
render: (el: ModalProps) => void;
render: (el: ModalConfig) => void;
} | null>(null);
ModalContext.displayName = "<ModalProvider />";
@ -22,7 +28,7 @@ export const useModalContext = () => {
const ModalProvider: React.VoidFunctionComponent<ModalProviderProps> = ({
children,
}) => {
const [modals, { push, removeAt, updateAt }] = useList<ModalProps>([]);
const [modals, { push, removeAt, updateAt }] = useList<ModalConfig>([]);
const removeModalAt = (index: number) => {
updateAt(index, { ...modals[index], visible: false });
@ -44,6 +50,11 @@ const ModalProvider: React.VoidFunctionComponent<ModalProviderProps> = ({
key={i}
visible={true}
{...props}
content={
typeof props.content === "function"
? props.content({ close: () => removeModalAt(i) })
: props.content
}
onOk={() => {
props.onOk?.();
removeModalAt(i);