Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: external link url disappears before the closing transition ends #366

Merged
merged 1 commit into from
Nov 6, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions resources/js/Contexts/ExternalLinkContext.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { createContext, useContext, useState } from "react";
import { ExternalLinkConfirmModal } from "@/Components/ExternalLinkConfirmModal";
import { isTruthy } from "@/Utils/is-truthy";

interface ContextProperties {
allowedExternalDomains: string[];
setUrl?: (url: string) => void;
setOpen?: (open: boolean) => void;
}

interface ProviderProperties extends ContextProperties {
Expand All @@ -20,21 +20,23 @@ export const ExternalLinkContextProvider = ({
allowedExternalDomains = [],
}: ProviderProperties): JSX.Element => {
const [url, setUrl] = useState<string | undefined>();
const [open, setOpen] = useState(false);

return (
<ExternalLinkContext.Provider
value={{
allowedExternalDomains,
setUrl,
setOpen,
}}
>
<div>
{children}

<ExternalLinkConfirmModal
isOpen={isTruthy(url)}
isOpen={open}
onClose={() => {
setUrl(undefined);
setOpen(false);
}}
href={url}
hasDisabledLinkWarning={localStorage.getItem("has_disabled_link_warning") === "true"}
Expand All @@ -58,6 +60,7 @@ export const useExternalLinkContext = (): {
isDomainAllowed: (url: string): boolean => context.allowedExternalDomains.includes(new URL(url).hostname),
hasDisabledLinkWarning: localStorage.getItem("has_disabled_link_warning") === "true",
openConfirmationModal: (url: string) => {
context.setOpen?.(true);
context.setUrl?.(url);
},
};
Expand Down
Loading