Skip to content

Commit

Permalink
fix: external link url disappears before the closing transition ends (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
crnkovic authored Nov 6, 2023
1 parent b4bb188 commit 2a8c343
Showing 1 changed file with 6 additions and 3 deletions.
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

0 comments on commit 2a8c343

Please sign in to comment.