Added story preview and confirmation dialogs to send story

This commit is contained in:
Alvaro 2022-10-12 10:14:35 -06:00 committed by GitHub
parent e80d9d1f30
commit 820eaa50ad
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
12 changed files with 315 additions and 109 deletions

View 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];
}