add copy link

This commit is contained in:
PhilReact 2024-11-10 19:41:39 +02:00
parent 1223847318
commit 3e0d3394e2
2 changed files with 62 additions and 0 deletions

View File

@ -53,6 +53,35 @@ export const AppViewer = React.forwardRef(({ app , hide, isDevMode}, iframeRef)
}; };
}, [app, path, isDevMode]); }, [app, path, isDevMode]);
const removeTrailingSlash = (str) => str.replace(/\/$/, '');
const copyLinkFunc = (e) => {
const {tabId} = e.detail
if(tabId === app?.tabId){
let link = 'qortal://' + app?.service + '/' + app?.name
if(path && path.startsWith('/')){
link = link + removeTrailingSlash(path)
}
if(path && !path.startsWith('/')){
link = link + '/' + removeTrailingSlash(path)
}
navigator.clipboard.writeText(link)
.then(() => {
console.log("Path copied to clipboard:", path);
})
.catch((error) => {
console.error("Failed to copy path:", error);
});
}
};
useEffect(() => {
subscribeToEvent("copyLink", copyLinkFunc);
return () => {
unsubscribeFromEvent("copyLink", copyLinkFunc);
};
}, [app, path]);
// Function to navigate back in iframe // Function to navigate back in iframe
const navigateBackInIframe = async () => { const navigateBackInIframe = async () => {
if (iframeRef.current && iframeRef.current.contentWindow && history?.currentIndex > 0) { if (iframeRef.current && iframeRef.current.contentWindow && history?.currentIndex > 0) {

View File

@ -7,6 +7,7 @@ import {
import NavBack from "../../assets/svgs/NavBack.svg"; import NavBack from "../../assets/svgs/NavBack.svg";
import NavAdd from "../../assets/svgs/NavAdd.svg"; import NavAdd from "../../assets/svgs/NavAdd.svg";
import NavMoreMenu from "../../assets/svgs/NavMoreMenu.svg"; import NavMoreMenu from "../../assets/svgs/NavMoreMenu.svg";
import ContentCopyIcon from '@mui/icons-material/ContentCopy';
import { import {
ButtonBase, ButtonBase,
ListItemIcon, ListItemIcon,
@ -366,6 +367,38 @@ export const AppsNavBarDesktop = () => {
primary="Refresh" primary="Refresh"
/> />
</MenuItem> </MenuItem>
<MenuItem
onClick={() => {
executeEvent("copyLink", {
tabId: selectedTab?.tabId,
});
handleClose();
}}
>
<ListItemIcon
sx={{
minWidth: "24px !important",
marginRight: "5px",
}}
>
<ContentCopyIcon
height={20}
sx={{
color: "rgba(250, 250, 250, 0.5)",
}}
/>
</ListItemIcon>
<ListItemText
sx={{
"& .MuiTypography-root": {
fontSize: "12px",
fontWeight: 600,
color: "rgba(250, 250, 250, 0.5)",
},
}}
primary="Copy link"
/>
</MenuItem>
</Menu> </Menu>
</AppsNavBarParent> </AppsNavBarParent>
); );