feat(modal): port LinkWarning

This commit is contained in:
Paul Makles
2022-06-18 14:19:31 +01:00
parent 241b9cd27b
commit b7be9f8c03
11 changed files with 84 additions and 51 deletions

View File

@@ -141,35 +141,7 @@ export default function Intermediate(props: Props) {
const actions = useMemo(() => {
return {
openLink: (href?: string, trusted?: boolean) => {
const link = determineLink(href);
switch (link.type) {
case "profile": {
openScreen({ id: "profile", user_id: link.id });
return true;
}
case "navigate": {
history.push(link.path);
return true;
}
case "external": {
if (
!trusted &&
!settings.security.isTrustedOrigin(
link.url.hostname,
)
) {
openScreen({
id: "external_link_prompt",
link: link.href,
});
} else {
window.open(link.href, "_blank", "noreferrer");
}
}
}
return true;
return modalController.openLink(href, trusted);
},
openScreen: (screen: Screen) => openScreen(screen),
writeClipboard: (a: string) => modalController.writeText(a),

View File

@@ -1,6 +1,5 @@
//import { isModalClosing } from "../../components/ui/Modal";
import { Screen } from "./Intermediate";
import { ExternalLinkModal } from "./modals/ExternalLinkPrompt";
import { InputModal } from "./modals/Input";
import { OnboardingModal } from "./modals/Onboarding";
import { PromptModal } from "./modals/Prompt";
@@ -23,8 +22,6 @@ export default function Modals({ screen, openScreen }: Props) {
return <InputModal onClose={onClose} {...screen} />;
case "onboarding":
return <OnboardingModal onClose={onClose} {...screen} />;
case "external_link_prompt":
return <ExternalLinkModal onClose={onClose} {...screen} />;
}
return null;

View File

@@ -1,57 +0,0 @@
import { Text } from "preact-i18n";
import { Modal } from "@revoltchat/ui";
import { useApplicationState } from "../../../mobx/State";
import { useIntermediate } from "../Intermediate";
interface Props {
onClose: () => void;
link: string;
}
export function ExternalLinkModal({ onClose, link }: Props) {
const { openLink } = useIntermediate();
const settings = useApplicationState().settings;
return (
<Modal
onClose={onClose}
title={<Text id={"app.special.modals.external_links.title"} />}
actions={[
{
onClick: () => {
openLink(link, true);
onClose();
},
confirmation: true,
palette: "accent",
children: "Continue",
},
{
onClick: onClose,
confirmation: false,
children: "Cancel",
},
{
onClick: () => {
try {
const url = new URL(link);
settings.security.addTrustedOrigin(url.hostname);
} catch (e) {}
openLink(link, true);
onClose();
},
palette: "plain",
children: (
<Text id="app.special.modals.external_links.trust_domain" />
),
},
]}>
<Text id="app.special.modals.external_links.short" /> <br />
<a>{link}</a>
</Modal>
);
}