mirror of
https://github.com/stoatchat/for-legacy-web.git
synced 2026-03-07 01:15:28 +00:00
feat(modal): port LinkWarning
This commit is contained in:
@@ -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),
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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>
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user