Skip to content

Commit

Permalink
simplify the code, somewhat
Browse files Browse the repository at this point in the history
  • Loading branch information
rlamacraft committed Mar 7, 2025
1 parent 9790e8b commit 06cdba2
Showing 1 changed file with 8 additions and 12 deletions.
20 changes: 8 additions & 12 deletions src/main/webapp/ui/src/eln/gallery/components/MainPanel.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ import CloseIcon from "@mui/icons-material/Close";
import SearchIcon from "@mui/icons-material/Search";
import AnalyticsContext from "../../../stores/contexts/Analytics";
import * as StringUtils from "../../../util/StringUtils";
import * as ArrayUtils from "../../../util/ArrayUtils";
import LinkIcon from "@mui/icons-material/Link";
import AlertContext, { mkAlert } from "../../../stores/contexts/Alert";

Expand Down Expand Up @@ -373,17 +374,11 @@ const Path = observer(
title="Copy to clipboard"
onClick={doNotAwait(async () => {
try {
if (path.length === 0) {
await navigator.clipboard.writeText(
`${window.location.origin}/gallery?mediaType=${section}`
);
} else {
await navigator.clipboard.writeText(
`${window.location.origin}/gallery/${idToString(
path[path.length - 1].id
).elseThrow()}`
);
}
await navigator.clipboard.writeText(
`${window.location.origin}/gallery${ArrayUtils.last(path)
.map(({ id }) => `/${idToString(id).elseThrow()}`)
.orElse(`?mediaType=${section}`)}`
);
addAlert(
mkAlert({
message: "Link copied to clipboard successfully!",
Expand All @@ -403,7 +398,8 @@ const Path = observer(
color="standardIcon"
icon={<LinkIcon />}
sx={{
backgroundColor: (theme) => alpha(lighten(theme.palette.primary.main, 0.1), 0.6),
backgroundColor: (theme) =>
alpha(lighten(theme.palette.primary.main, 0.1), 0.6),
"&:hover": {
backgroundColor: (theme) =>
alpha(theme.palette.primary.main, 0.85),
Expand Down

0 comments on commit 06cdba2

Please sign in to comment.