diff --git a/components/Blocks/Block.tsx b/components/Blocks/Block.tsx index 67f62860..5558ec35 100644 --- a/components/Blocks/Block.tsx +++ b/components/Blocks/Block.tsx @@ -37,6 +37,7 @@ import { DeleteTiny } from "components/Icons/DeleteTiny"; import { ArrowDownTiny } from "components/Icons/ArrowDownTiny"; import { Separator } from "components/Layout"; import { moveBlockUp, moveBlockDown } from "src/utils/moveBlock"; +import { deleteBlock } from "src/utils/deleteBlock"; export type Block = { factID: string; @@ -395,6 +396,8 @@ export const BlockLayout = (props: { hasBackground?: "accent" | "page"; borderOnHover?: boolean; hasAlignment?: boolean; + areYouSure?: boolean; + setAreYouSure?: (value: boolean) => void; }) => { // this is used to wrap non-text blocks in consistent selected styling, spacing, and top level options like delete return ( @@ -417,12 +420,23 @@ export const BlockLayout = (props: { > {props.children} - {props.isSelected && } + {props.isSelected && ( + + )} ); }; -const NonTextBlockOptions = (props: { isCanvas?: boolean }) => { +let debounced: null | number = null; + +const NonTextBlockOptions = (props: { + isCanvas?: boolean; + areYouSure?: boolean; + setAreYouSure?: (value: boolean) => void; +}) => { let { rep } = useReplicache(); let entity_set = useEntitySetContext(); let focusedEntity = useUIState((s) => s.focusedEntity); @@ -443,7 +457,9 @@ const NonTextBlockOptions = (props: { isCanvas?: boolean }) => { {focusedEntityType?.data.value !== "canvas" && ( <> diff --git a/components/Blocks/MailboxBlock.tsx b/components/Blocks/MailboxBlock.tsx index 1bc591cd..670affae 100644 --- a/components/Blocks/MailboxBlock.tsx +++ b/components/Blocks/MailboxBlock.tsx @@ -26,7 +26,12 @@ import { usePageTitle } from "components/utils/UpdateLeafletTitle"; import { ArrowDownTiny } from "components/Icons/ArrowDownTiny"; import { InfoSmall } from "components/Icons/InfoSmall"; -export const MailboxBlock = (props: BlockProps) => { +export const MailboxBlock = ( + props: BlockProps & { + areYouSure?: boolean; + setAreYouSure?: (value: boolean) => void; + }, +) => { let isSubscribed = useSubscriptionStatus(props.entityID); let isSelected = useUIState((s) => s.selectedBlocks.find((b) => b.value === props.entityID), @@ -41,7 +46,10 @@ export const MailboxBlock = (props: BlockProps) => { let subscriber_count = useEntity(props.entityID, "mailbox/subscriber-count"); if (!permission) return ( - + ); return ( @@ -49,6 +57,8 @@ export const MailboxBlock = (props: BlockProps) => { { ); }; -const MailboxReaderView = (props: { entityID: string; parent: string }) => { +const MailboxReaderView = (props: { + entityID: string; + parent: string; + +}) => { let isSubscribed = useSubscriptionStatus(props.entityID); let isSelected = useUIState((s) => s.selectedBlocks.find((b) => b.value === props.entityID), @@ -133,6 +147,7 @@ const MailboxReaderView = (props: { entityID: string; parent: string }) => { {!isSubscribed?.confirmed ? ( diff --git a/components/Blocks/PageLinkBlock.tsx b/components/Blocks/PageLinkBlock.tsx index df27bd24..90474ea4 100644 --- a/components/Blocks/PageLinkBlock.tsx +++ b/components/Blocks/PageLinkBlock.tsx @@ -13,7 +13,13 @@ import { Canvas, CanvasBackground, CanvasContent } from "components/Canvas"; import { CardThemeProvider } from "components/ThemeManager/ThemeProvider"; import { useCardBorderHidden } from "components/Pages/useCardBorderHidden"; -export function PageLinkBlock(props: BlockProps & { preview?: boolean }) { +export function PageLinkBlock( + props: BlockProps & { + preview?: boolean; + areYouSure?: boolean; + setAreYouSure?: (value: boolean) => void; + }, +) { let page = useEntity(props.entityID, "block/card"); let type = useEntity(page?.data.value || null, "page/type")?.data.value || "doc"; @@ -32,6 +38,8 @@ export function PageLinkBlock(props: BlockProps & { preview?: boolean }) { { +export const PollBlock = ( + props: BlockProps & { + areYouSure?: boolean; + setAreYouSure?: (value: boolean) => void; + }, +) => { let { data: pub } = useLeafletPublicationData(); if (!pub) return ; return ; }; -export const LeafletPollBlock = (props: BlockProps) => { +export const LeafletPollBlock = ( + props: BlockProps & { + areYouSure?: boolean; + setAreYouSure?: (value: boolean) => void; + }, +) => { let isSelected = useUIState((s) => s.selectedBlocks.find((b) => b.value === props.entityID), ); @@ -64,6 +74,8 @@ export const LeafletPollBlock = (props: BlockProps) => { {pollState === "editing" ? ( diff --git a/components/Blocks/PublicationPollBlock.tsx b/components/Blocks/PublicationPollBlock.tsx index 002095c5..f0dc52f1 100644 --- a/components/Blocks/PublicationPollBlock.tsx +++ b/components/Blocks/PublicationPollBlock.tsx @@ -21,7 +21,12 @@ import { ids } from "lexicons/api/lexicons"; * It allows adding/editing options when the poll hasn't been published yet, * but disables adding new options once the poll record exists (indicated by pollUri). */ -export const PublicationPollBlock = (props: BlockProps) => { +export const PublicationPollBlock = ( + props: BlockProps & { + areYouSure?: boolean; + setAreYouSure?: (value: boolean) => void; + }, +) => { let { data: publicationData } = useLeafletPublicationData(); let isSelected = useUIState((s) => s.selectedBlocks.find((b) => b.value === props.entityID), @@ -57,6 +62,8 @@ export const PublicationPollBlock = (props: BlockProps) => { className="poll flex flex-col gap-2" hasBackground={"accent"} isSelected={!!isSelected} + areYouSure={props.areYouSure} + setAreYouSure={props.setAreYouSure} > void; + }, +) { let isSelected = useUIState((s) => s.selectedBlocks.find((b) => b.value === props.entityID), ); @@ -32,6 +37,8 @@ export function RSVPBlock(props: BlockProps) { diff --git a/components/Blocks/useBlockKeyboardHandlers.ts b/components/Blocks/useBlockKeyboardHandlers.ts index 18b1f43b..38f678a0 100644 --- a/components/Blocks/useBlockKeyboardHandlers.ts +++ b/components/Blocks/useBlockKeyboardHandlers.ts @@ -154,11 +154,12 @@ async function Backspace({ if ((el as HTMLInputElement).value !== "") return; } - // if the block is a card or mailbox... + // if the block is a card, mailbox, rsvp, or poll... if ( props.type === "card" || props.type === "mailbox" || - props.type === "rsvp" + props.type === "rsvp" || + props.type === "poll" ) { // ...and areYouSure state is false, set it to true if (!areYouSure) {