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

adding user feedback after the creation of a share link. #133

Merged
merged 1 commit into from
Jul 30, 2024
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
44 changes: 35 additions & 9 deletions src/components/share/buildlink.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import React, { Fragment, useState } from 'react';
import { Button, TextField, Dialog, DialogActions, DialogContent, DialogContentText, DialogTitle } from '@mui/material';
import { Button, TextField, Dialog, DialogActions,
DialogContent, DialogContentText, DialogTitle,
Typography, Link } from '@mui/material';
import { IconButton } from '@mui/joy';
import ShareRoundedIcon from '@mui/icons-material/ShareRounded';
import { useLayers } from "@context/map-context";
Expand All @@ -14,12 +16,16 @@ export const BuildLink = () => {
// get the layers from state
const { defaultModelLayers, selectedObservations } = useLayers();

// store the result message of the share link building
const [ buildLinkMessage, setBuildLinkMessage ] = useState('');

// used to set the dialog view state
const [open, setOpen] = useState(false);

/**
* create the query string that can be used to share the current view
*/
// storage for the share link
const [shareLink, setShareLink] = useState('');

// create the query string that can be used to share the current view
const createLink = (comment) => {
// get the list of selected layers from state
// this forces the group at the top to be the reproduced in the share line
Expand All @@ -41,12 +47,22 @@ export const BuildLink = () => {

// check to see if there was one or more groups selected
if (run_id !== '') {
// create the link
const theLink = encodeURI(window.location.origin + '/#share=run_id:' + run_id + "~comment=" + comment + '~obs=[' + observations + ']');

// copy the link to the cut/paste buffer
copyTextToClipboard(encodeURI(window.location.origin + '/#share=run_id:' + run_id + "~comment=" + comment + '~obs=[' + observations + ']')).then();
copyTextToClipboard(theLink).then();

// set the user feedback
setBuildLinkMessage(`The Share link is now in your clipboard.`);
setShareLink(theLink);
}
// no layers were selected on the map
else
alert('There were no layers selected.');
else {
// set the error message
setBuildLinkMessage('There are no layers selected. Please try again.');
setShareLink('');
}
};

/**
Expand All @@ -67,6 +83,8 @@ export const BuildLink = () => {

// handles the dialog close event
const handleClose = () => {
setBuildLinkMessage('');
setShareLink('');
setOpen(false);
};

Expand All @@ -86,18 +104,26 @@ export const BuildLink = () => {
const formJson = Object.fromEntries(formData.entries());
const comment = formJson.comment;
createLink(comment);
handleClose();
}}}>
<DialogTitle>Share this view</DialogTitle>

<DialogContent>
<DialogContentText>
Please enter a comment below that describes what you are sharing. When ready, select the &quot;Create&quot; button
and you will have the share link copied into your cut/paste buffer.
</DialogContentText>

{/* output the result of the link building/saving */}
{ ( buildLinkMessage.length ) ? <Typography component={'span'}>{ buildLinkMessage }</Typography> : '' }

{/* output the link */}
{ ( shareLink.length ) ? <Link target="_blank" sx={{ marginLeft: 1 }} href={ shareLink }>Test it!</Link> : '' }

<TextField autoFocus margin="dense" id="comment" name="comment" fullWidth variant="standard"/>
</DialogContent>

<DialogActions>
<Button onClick={handleClose}>Cancel</Button>
<Button onClick={ handleClose }>Cancel</Button>
<Button type="submit">Create</Button>
</DialogActions>
</Dialog>
Expand Down