diff --git a/components/core/Application.js b/components/core/Application.js
index 69718281..384eee49 100644
--- a/components/core/Application.js
+++ b/components/core/Application.js
@@ -57,6 +57,7 @@ import CTATransition from "~/components/core/CTATransition";
import { GlobalModal } from "~/components/system/components/GlobalModal";
import { OnboardingModal } from "~/components/core/OnboardingModal";
import { SearchModal } from "~/components/core/SearchModal";
+import { CollectionSharingModal } from "~/components/core/ShareModals/CollectionSharingModal";
import { Alert } from "~/components/core/Alert";
import { announcements } from "~/components/core/OnboardingModal";
import { Logo } from "~/common/logo";
@@ -663,6 +664,7 @@ export default class ApplicationPage extends React.Component {
onAction={this._handleAction}
isMobile={this.props.isMobile}
/>
+
{/* {!this.state.loaded ? (
css`
+ ${Styles.BUTTON_RESET};
+ background-color: ${theme.system.white};
+ width: 100%;
+ padding: 9px 12px 11px;
+`;
+
+const formatDataSafely = ({ collection, user }) => {
+ if (typeof window === "undefined" || !collection || !user) return {};
+ const rootUrl = window?.location?.origin;
+ return {
+ id: collection.id,
+ title: collection?.data?.name || collection?.slatename,
+ link: `${rootUrl}/${user.username}/${collection.slatename}`,
+ };
+};
+
+export const CollectionSharingModal = () => {
+ const [state, handlers] = useModalState();
+ const { open, user, collection, view } = state;
+ const { closeModal, changeView, handleModalVisibility } = handlers;
+
+ const { id, title, link } = React.useMemo(
+ () => formatDataSafely({ collection, user }),
+ [user, collection]
+ );
+
+ useEventListener("collection-sharing-modal", handleModalVisibility, []);
+
+ const handleTwitterSharing = () =>
+ // TODO(amine): change twitter copy
+ window.open(`https://twitter.com/intent/tweet?text=${title}:%0D&url=${link}`, "_blank");
+
+ const handleEmailSharing = () => {
+ const email = prompt("Please enter your email");
+ if (!email) return;
+ //TODO(amine): change email copy
+ window.open(`mailto:${email}?subject=Check out this collection&body=${link}`, "_b");
+ };
+
+ const handleLinkCopy = () => (Utilities.copyToClipboard(link), changeView("LINK_COPIED"));
+ const handleIdCopy = () => (Utilities.copyToClipboard(id), changeView("ID_COPIED"));
+
+ return (
+
+ {view === "initial" ? (
+
+
+
+
+
+ ) : (
+
+ {view === "LINK_COPIED" ? "Link copied to clipboard" : "ID copied to clipboard"}
+
+ )}
+
+ );
+};
+
+const LinkCopiedScene = ({ closeModal, children }) => {
+ useTimeout(closeModal, 3000);
+ return (
+
+
+
+ {children}
+
+
+ );
+};
+
+const useModalState = () => {
+ const [state, setState] = React.useState({
+ open: false,
+ // NOTE(amine): INITIAL || LINK_COPIED || ID_COPIED
+ view: "initial",
+ user: {},
+ data: {},
+ });
+
+ const handlers = React.useMemo(
+ () => ({
+ closeModal: () => setState((prev) => ({ ...prev, open: false })),
+ changeView: (view) => setState((prev) => ({ ...prev, view })),
+ handleModalVisibility: (e) =>
+ setState(() => ({
+ view: "initial",
+ open: e.detail.open,
+ user: e.detail.user,
+ collection: e.detail.collection,
+ })),
+ }),
+ []
+ );
+ return [state, handlers];
+};
+
+export const useCollectionSharingModal = () => {
+ const openModal = ({ user, collection }) =>
+ Events.dispatchCustomEvent({
+ name: "collection-sharing-modal",
+ detail: { open: true, user, collection },
+ });
+ const closeModal = () =>
+ Events.dispatchCustomEvent({
+ name: "collection-sharing-modal",
+ detail: { open: false },
+ });
+ return { openModal, closeModal };
+};