Added story preview and confirmation dialogs to send story
This commit is contained in:
parent
e80d9d1f30
commit
820eaa50ad
12 changed files with 315 additions and 109 deletions
33
ts/hooks/useConfirmDiscard.tsx
Normal file
33
ts/hooks/useConfirmDiscard.tsx
Normal file
|
@ -0,0 +1,33 @@
|
|||
// Copyright 2022 Signal Messenger, LLC
|
||||
// SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
import React, { useState } from 'react';
|
||||
|
||||
import type { PropsType } from '../components/ConfirmDiscardDialog';
|
||||
|
||||
import { ConfirmDiscardDialog } from '../components/ConfirmDiscardDialog';
|
||||
import type { LocalizerType } from '../types/Util';
|
||||
|
||||
export function useConfirmDiscard(
|
||||
i18n: LocalizerType
|
||||
): [JSX.Element | null, (condition: boolean, callback: () => void) => void] {
|
||||
const [props, setProps] = useState<Omit<PropsType, 'i18n'> | null>(null);
|
||||
const confirmElement = props ? (
|
||||
<ConfirmDiscardDialog i18n={i18n} {...props} />
|
||||
) : null;
|
||||
|
||||
function confirmDiscardIf(condition: boolean, callback: () => void) {
|
||||
if (condition) {
|
||||
setProps({
|
||||
onClose() {
|
||||
setProps(null);
|
||||
},
|
||||
onDiscard: callback,
|
||||
});
|
||||
} else {
|
||||
callback();
|
||||
}
|
||||
}
|
||||
|
||||
return [confirmElement, confirmDiscardIf];
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue