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

[MPT-65] Attempt to create shareable link #731

Draft
wants to merge 14 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
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
49 changes: 49 additions & 0 deletions components/ResetButton.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import React, { useState } from "react";
import { withSearch } from "@elastic/react-search-ui";

function ClearFacets({ filters, removeFilter }) {
const handleClearAll = () => {
for (const filter of filters) {
removeFilter(filter.field, filter.value);
}
};

const [isHovered, setIsHovered] = useState(false);

const buttonStyle = {
backgroundColor: "#fff",
color: "#333",
border: "1px solid #ccc",
borderRadius: "4px",
padding: "10px 20px",
fontSize: "14px",
cursor: "pointer",
margin: "10px 0",
transition: "all 0.3s ease",
outline: "none",
width: "100%",
display: "block",
};

const buttonHoverStyle = {
...buttonStyle,
backgroundColor: "#f8f8f8",
borderColor: "#bbb",
};

return (
<button
style={isHovered ? buttonHoverStyle : buttonStyle}
onMouseEnter={() => setIsHovered(true)}
onMouseLeave={() => setIsHovered(false)}
onClick={handleClearAll}
>
Clear All Filters
</button>
);
}

export default withSearch(({ filters, removeFilter }) => ({
filters,
removeFilter,
}))(ClearFacets);
8 changes: 8 additions & 0 deletions components/ResultView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,8 @@ type DisplayResult = {
displaySchool: string | null;
industryColors: Map<string, string>;
thumbnailImageUrl?: string;
uuid: string;
searchName: string | null;
};

const ResultView = ({ result }: { result: SearchResult }) => {
Expand All @@ -108,6 +110,7 @@ const ResultView = ({ result }: { result: SearchResult }) => {
role,
school,
thumbnail_image_url,
id,
} = result;

const displayName =
Expand Down Expand Up @@ -148,6 +151,9 @@ const ResultView = ({ result }: { result: SearchResult }) => {
? fillHighlights(fullBio.snippet, fullBio.raw)
: null;

const uuid = id.raw;
const searchName = name.raw;

const displayResult: DisplayResult = {
displayCourseOfStudy,
displayFullBio,
Expand All @@ -159,6 +165,8 @@ const ResultView = ({ result }: { result: SearchResult }) => {
displayShortBio,
industryColors,
thumbnailImageUrl,
searchName,
uuid,
};

return (
Expand Down
41 changes: 31 additions & 10 deletions components/ResultViewGrid.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,33 +15,54 @@ const ResultViewGrid = ({
}: {
displayResult: DisplayResult;
}) => {
const { displayName, displayOrganisation, displayRole, thumbnailImageUrl } =
displayResult;
const {
displayName,
displayOrganisation,
displayRole,
thumbnailImageUrl,
uuid,
} = displayResult;

const [isModalOpen, setIsModalOpen] = useState(false);

const handleOpen = () => {
window.history.pushState({}, "");
const newUrl = `${window.location.origin}${window.location.pathname}?uid=${uuid}`;
window.history.pushState({ uuid }, "", newUrl);
setIsModalOpen(true);
};

const handleClose = () => {
window.history.back();
window.history.pushState({}, "", window.location.pathname);
setIsModalOpen(false);
};

useEffect(() => {
if (isModalOpen) {
window.onpopstate = () => {
setIsModalOpen(false);
};
const searchParams = new URLSearchParams(window.location.search);
const uidFromUrl = searchParams.get("uid");
if (uidFromUrl === uuid) {
setIsModalOpen(true);
} else {
setIsModalOpen(false);
}
});

const handlePopState = () => {
const searchParams = new URLSearchParams(window.location.search);
const uidFromUrl = searchParams.get("uid");
if (uidFromUrl !== uuid) {
setIsModalOpen(false);
}
};

window.addEventListener("popstate", handlePopState);
return () => {
window.removeEventListener("popstate", handlePopState);
};
}, [uuid]);

return (
<Card
className="sui-resultgrid"
style={{
maxWidth: "165px",
width: "100%",
height: "auto",
padding: "0px",
Expand Down
35 changes: 35 additions & 0 deletions components/ResultViewList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,14 @@ import React, { Fragment, useState } from "react";
import { Chip } from "@mui/material";

import type { DisplayResult } from "./ResultView";
import {
Snackbar,
SpeedDial,
SpeedDialIcon,
SpeedDialAction,
} from "@mui/material";
import ContentCopyIcon from "@mui/icons-material/ContentCopy";
import ShareIcon from "@mui/icons-material/Share";

const ResultViewList = ({
displayResult,
Expand All @@ -19,8 +27,22 @@ const ResultViewList = ({
displaySchool,
industryColors,
thumbnailImageUrl,
uuid,
searchName,
} = displayResult;

const [snackbarOpen, setSnackbarOpen] = useState(false);

const handleCopyLink = () => {
const link = `${window.location.origin}${
window.location.pathname
}?uid=${uuid}&q=${encodeURIComponent(searchName || "")}`;
navigator.clipboard.writeText(link).then(() => {
setSnackbarOpen(true);
setTimeout(() => setSnackbarOpen(false), 1000);
});
};

return (
<div className="sui-result">
<div className="sui-result__image">
Expand All @@ -39,6 +61,19 @@ const ResultViewList = ({
}}
/>
)}
<SpeedDial
ariaLabel="Share options"
icon={<SpeedDialIcon icon={<ShareIcon />} />}
direction="left"
>
<SpeedDialAction
key="copyLink"
icon={<ContentCopyIcon />}
tooltipTitle="Copy link"
onClick={handleCopyLink}
/>
</SpeedDial>
<Snackbar open={snackbarOpen} message="Link copied to clipboard" />
</div>
<ul className="sui-result__details">
<li className="sui-result__industries">
Expand Down
2 changes: 1 addition & 1 deletion next.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
const path = require("path");

const nextConfig = {
output: "export",
reactStrictMode: true,

swcMinify: true,

// Disable css--modules component styling
Expand Down
Loading
Loading