-
-
Notifications
You must be signed in to change notification settings - Fork 213
Feat: implemented Share Modal UI for improved UX #747
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
Open
LaveUI
wants to merge
9
commits into
accordproject:main
Choose a base branch
from
LaveUI:feat_shareModel
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+1,014
−510
Open
Changes from 2 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
514ca4b
Feat: implement Share Modal UI for improved UX and social sharing
vaibhavgupta1612-wq 1fbfc28
test: update e2e tests for new share modal flow
vaibhavgupta1612-wq 1ac8fee
add ShareModal unit tests and removed social sharing
vaibhavgupta1612-wq d2314e3
Merge branch 'main' into feat_shareModel
LaveUI 16a555c
test: fix flaky clipboard read in E2E share tests
vaibhavgupta1612-wq cc1639a
Merge branch 'main' into feat_shareModel
LaveUI 287850b
fix: resolve TypeScript build errors from missing AppState properties
vaibhavgupta1612-wq 5e5f402
Merge branch 'main' into feat_shareModel
vaibhavgupta1612-wq 4560911
fix: resolve esLint errors from latest merge
vaibhavgupta1612-wq File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,153 @@ | ||
| import React, { useState } from "react"; | ||
| import { Modal, Input, Button, message, Tooltip, Space } from "antd"; | ||
| import { CopyOutlined, CheckOutlined, TwitterOutlined, LinkedinOutlined, MailOutlined } from "@ant-design/icons"; | ||
| import useAppStore from "../store/store"; | ||
|
|
||
| const ShareModal: React.FC = () => { | ||
| const { | ||
| isShareModalOpen, | ||
| setShareModalOpen, | ||
| generateShareableLink, | ||
| backgroundColor, | ||
| textColor | ||
| } = useAppStore((state) => ({ | ||
| isShareModalOpen: state.isShareModalOpen, | ||
| setShareModalOpen: state.setShareModalOpen, | ||
| generateShareableLink: state.generateShareableLink, | ||
| backgroundColor: state.backgroundColor, | ||
| textColor: state.textColor, | ||
| })); | ||
|
|
||
| const isDarkMode = backgroundColor === '#121212'; | ||
|
|
||
| const [hasCopied, setHasCopied] = useState(false); | ||
|
|
||
| // We compute this only when the modal opens to avoid unnecessary re-computations | ||
| const [shareLink, setShareLink] = useState(""); | ||
|
|
||
| const handleOpen = () => { | ||
| setShareLink(generateShareableLink()); | ||
| }; | ||
|
|
||
| const handleClose = () => { | ||
| setShareModalOpen(false); | ||
| // Reset copy state when modal closes | ||
| setTimeout(() => setHasCopied(false), 300); | ||
| }; | ||
|
|
||
| const handleCopy = async () => { | ||
| try { | ||
| await navigator.clipboard.writeText(shareLink); | ||
| setHasCopied(true); | ||
| void message.success("Link copied to clipboard!"); | ||
| setTimeout(() => setHasCopied(false), 3000); | ||
| } catch (err) { | ||
| console.error("Failed to copy link: ", err); | ||
| void message.error("Failed to copy link to clipboard."); | ||
| } | ||
| }; | ||
|
|
||
| const shareToTwitter = () => { | ||
| const text = encodeURIComponent("Check out this Accord Project template!"); | ||
| window.open(`https://twitter.com/intent/tweet?url=${encodeURIComponent(shareLink)}&text=${text}`, "_blank"); | ||
| }; | ||
|
|
||
| const shareToLinkedIn = () => { | ||
| window.open(`https://www.linkedin.com/sharing/share-offsite/?url=${encodeURIComponent(shareLink)}`, "_blank"); | ||
LaveUI marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| }; | ||
|
|
||
| const shareViaEmail = () => { | ||
| const subject = encodeURIComponent("Accord Project Template"); | ||
| const body = encodeURIComponent(`Check out this template I built using the Accord Project Template Playground:\n\n${shareLink}`); | ||
| window.location.href = `mailto:?subject=${subject}&body=${body}`; | ||
| }; | ||
|
|
||
| return ( | ||
| <Modal | ||
| title="Share Template" | ||
| open={isShareModalOpen} | ||
| onCancel={handleClose} | ||
| afterOpenChange={(open) => { | ||
| if (open) handleOpen(); | ||
| }} | ||
LaveUI marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| className={isDarkMode ? 'dark-modal' : ''} | ||
LaveUI marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| footer={null} // We manage our own footer/layout to match SettingsModal | ||
| width="90%" | ||
| style={{ maxWidth: 480 }} | ||
| centered | ||
| > | ||
| <div className="space-y-6 py-4"> | ||
|
|
||
| {/* Information Text */} | ||
| <div className="flex flex-col gap-2"> | ||
| <p className={`text-sm ${isDarkMode ? 'text-gray-400' : 'text-gray-500'}`}> | ||
| Anyone with this link will be able to view and edit this template. | ||
| </p> | ||
| </div> | ||
|
|
||
| {/* Link Input & Copy */} | ||
| <div className="flex flex-col sm:flex-row gap-3"> | ||
| <Input | ||
| readOnly | ||
| value={shareLink} | ||
| onFocus={(e) => e.target.select()} | ||
| className={`font-mono text-sm flex-1 ${isDarkMode ? 'bg-[#1e1e1e] text-gray-300 border-gray-600' : ''}`} | ||
| /> | ||
| <Button | ||
| type="primary" | ||
| icon={hasCopied ? <CheckOutlined /> : <CopyOutlined />} | ||
| onClick={() => void handleCopy()} | ||
| className="w-full sm:w-auto" | ||
| > | ||
| {hasCopied ? "Copied!" : "Copy"} | ||
| </Button> | ||
| </div> | ||
|
|
||
| <hr className={isDarkMode ? 'border-gray-600' : 'border-gray-200'} /> | ||
|
|
||
| {/* Social Share */} | ||
| <div className="flex flex-col sm:flex-row sm:items-center sm:justify-between gap-3"> | ||
| <div className="flex-1 min-w-0"> | ||
| <h4 className="font-medium text-sm sm:text-base" style={{ color: textColor }}> | ||
| Share Externally | ||
| </h4> | ||
| <p className={`text-xs sm:text-sm ${isDarkMode ? 'text-gray-400' : 'text-gray-500'}`}> | ||
| Post your template link directly to your social platforms | ||
| </p> | ||
| </div> | ||
| <div className="flex-shrink-0"> | ||
| <Space size="middle"> | ||
| <Tooltip title="Share on Twitter/X"> | ||
| <Button | ||
| shape="circle" | ||
| icon={<TwitterOutlined />} | ||
| onClick={shareToTwitter} | ||
| style={{ color: '#1DA1F2', borderColor: '#1DA1F2', background: 'transparent' }} | ||
| /> | ||
LaveUI marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| </Tooltip> | ||
| <Tooltip title="Share on LinkedIn"> | ||
| <Button | ||
| shape="circle" | ||
| icon={<LinkedinOutlined />} | ||
| onClick={shareToLinkedIn} | ||
| style={{ color: '#0A66C2', borderColor: '#0A66C2', background: 'transparent' }} | ||
| /> | ||
| </Tooltip> | ||
| <Tooltip title="Share via Email"> | ||
| <Button | ||
| shape="circle" | ||
| icon={<MailOutlined />} | ||
| onClick={shareViaEmail} | ||
| style={{ background: 'transparent' }} | ||
| className={isDarkMode ? 'text-gray-300 border-gray-500' : 'text-gray-600'} | ||
| /> | ||
| </Tooltip> | ||
| </Space> | ||
| </div> | ||
| </div> | ||
| </div> | ||
| </Modal> | ||
| ); | ||
| }; | ||
|
|
||
| export default ShareModal; | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.