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

Bibdk2021 1324 bookmark work part2 #879

Open
wants to merge 34 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 7 commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
817ad3b
in progress - new bookmark svg
pjohans Aug 28, 2023
49c15a7
bookmark with one material only
pjohans Aug 28, 2023
46835a7
no need for async here
pjohans Aug 28, 2023
3769b69
different svgs on dropdown
pjohans Aug 29, 2023
499b5bb
bookmark on editions
pjohans Aug 29, 2023
033f7cc
removed unused css
pjohans Aug 29, 2023
dd0dc4a
removed unused css
pjohans Aug 29, 2023
dae661c
Merge branch 'main' into bibdk2021-1324-bookmark-work-part2
pjohans Aug 29, 2023
eb5e9bc
fixed localstorage
pjohans Aug 29, 2023
a8d720e
fixed a typo
pjohans Aug 29, 2023
008b956
redid pid as id
pjohans Aug 29, 2023
bcc19e5
Merge branch 'bibdk2021-1324-bookmark-work-part2' into feature-bookmark
pjohans Aug 29, 2023
fe35b44
Merge branch 'main' into feature-bookmark
jonaspraem Aug 30, 2023
298887f
fixes from review
pjohans Sep 5, 2023
da87877
in progress - menu nav
pjohans Sep 5, 2023
0499fda
minor css
pjohans Sep 5, 2023
09778e5
Merge branch 'main' into bibdk2021-1324-bookmark-work-part2
pjohans Sep 5, 2023
2ec73e9
Merge branch 'main' into bibdk2021-1324-bookmark-work-part2
pjohans Sep 5, 2023
cbfda29
Bibdk2021 1790 bookmark page (#891)
jonaspraem Sep 5, 2023
cd47b62
Merge branch 'feature-bookmark' of https:/DBCDK/bibliotek…
jonaspraem Sep 5, 2023
a4942dd
in progress - menu nav
pjohans Sep 5, 2023
39e89e7
minor css
pjohans Sep 5, 2023
7778e2e
Bibdk2021 1769 persist data consent (#884)
YousefMohsen Aug 30, 2023
1e0b4a2
fixed refetch bug (#887)
YousefMohsen Aug 31, 2023
da196a1
check if order fails (#867)
pjohans Sep 4, 2023
f733162
fixed a test
pjohans Sep 5, 2023
d99baad
fixed a test
pjohans Sep 6, 2023
136741b
Merge branch 'feature-bookmark' into bibdk2021-1324-bookmark-work-part2
pjohans Sep 6, 2023
63bd438
Merge branch 'main' into bibdk2021-1324-bookmark-work-part2
pjohans Sep 11, 2023
44e5a98
some css fixes from review
pjohans Sep 11, 2023
9b74ae8
correct translation on bookmark
pjohans Sep 12, 2023
0c1b8ca
Merge branch 'main' into bibdk2021-1324-bookmark-work-part2
pjohans Sep 12, 2023
9ac9ca4
fixed a merge conflict
pjohans Sep 14, 2023
9cf62b5
some focus-visible stuff
pjohans Sep 18, 2023
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
File renamed without changes
6 changes: 0 additions & 6 deletions public/icons/bookmark_large.svg

This file was deleted.

4 changes: 4 additions & 0 deletions public/icons/bookmark_medium.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions public/icons/bookmark_small.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
10 changes: 3 additions & 7 deletions src/components/base/bookmark/Bookmark.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import Skeleton from "@/components/base/skeleton";
import Icon from "@/components/base/icon";
import translate from "@/components/base/translate";

import BookmarkSvg from "@/public/icons/bookmark_large.svg";
import BookmarkSvg from "@/public/icons/bookmark_medium.svg";
// import BookmarkSvg from "@/public/icons/bookmark.svg";

import styles from "./Bookmark.module.css";
Expand All @@ -24,6 +24,7 @@ function handleOnBookmarkClick() {
* @returns {component}
*/
function Bookmark({
size = { w: 5, h: 5 },
className = "",
selected = false,
onClick = null,
Expand Down Expand Up @@ -52,12 +53,7 @@ function Bookmark({
className={`${className} ${styles.bookmark} ${selectedClass}`}
onClick={() => (onClick ? onClick() : handleOnBookmarkClick())}
>
<Icon
skeleton={skeleton}
disabled={disabled}
size={{ w: 5, h: 5 }}
alt="bookmark"
>
<Icon skeleton={skeleton} disabled={disabled} size={size} alt="bookmark">
<BookmarkSvg />
</Icon>
</button>
Expand Down
2 changes: 1 addition & 1 deletion src/components/hooks/useBookmarks.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export default function useBookmarks() {
/**
* Set a value in bookmark list
*/
const setBookmark = async (value) => {
const setBookmark = (value) => {
// Find existing
const existingIndex = bookmark?.findIndex((obj) => obj.key === value.key);
// push if not there
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import CheckMarkBlue from "@/public/icons/checkmark_blue.svg";
import Tooltip from "react-bootstrap/Tooltip";
import OverlayTrigger from "react-bootstrap/OverlayTrigger";
import cx from "classnames";
import BookMarkDropDown from "@/components/work/overview/bookmarkDropdown/BookmarkDropdown";

/**
* Column one of full view. Some links and a button.
Expand Down Expand Up @@ -84,13 +85,20 @@ function ColumnOne({ workId, manifestation }) {
/>
)}

<div className={styles.button}>
<ReservationButton
<div className={styles.reservationwrapper}>
<div className={styles.button}>
<ReservationButton
workId={workId}
selectedPids={[manifestation?.pid]}
singleManifestation={true}
buttonType="secondary"
size="small"
/>
</div>
<BookMarkDropDown
workId={workId}
selectedPids={[manifestation?.pid]}
singleManifestation={true}
buttonType="secondary"
size="small"
materialTypes={[[manifestation?.materialTypes?.[0]?.specific]]}
size={{ w: 4, h: 4 }}
/>
</div>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
}

.fullmanifestation .button {
margin-bottom: var(--pt2);
font-family: var(--body-font-semibold);
transition: color 0.5s;
color: var(--blue);
Expand Down Expand Up @@ -58,7 +57,11 @@
}

/** end manifestation parts list **/

.reservationwrapper {
display: flex;
align-items: center;
margin-bottom: var(--pt2);
}
.container {
column-count: 1;
-webkit-column-count: 1;
Expand Down
6 changes: 6 additions & 0 deletions src/components/work/overview/Overview.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import {
import Title from "@/components/base/title/Title";
import { useRouter } from "next/router";
import Breadcrumbs from "@/components/work/overview/breadcrumbs/Breadcrumbs";
import BookMarkDropDown from "@/components/work/overview/bookmarkDropdown/BookmarkDropdown";

function useInitMaterialType(
uniqueMaterialTypes,
Expand Down Expand Up @@ -155,7 +156,12 @@ export function Overview({
workId={workId}
selectedPids={selectedPids}
/>
<BookMarkDropDown
workId={workId}
materialTypes={uniqueMaterialTypes}
/>
</Col>

<OrderButtonTextBelow
workId={workId}
selectedPids={selectedPids}
Expand Down
1 change: 0 additions & 1 deletion src/components/work/overview/Overview.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@
.basket {
padding-top: var(--pt3);
display: flex;
justify-content: space-between;
}

.info {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,38 +3,73 @@

.dropdownitem {
display: block;
border-bottom: 1px solid var(--mine-shaft);
padding: var(--pt1) var(--pt2) var(--pt1) var(--pt2);
border-bottom: 1px solid var(--gray);
padding: var(--pt1) var(--pt05) var(--pt1) var(--pt2);
text-decoration: none;
color: var(--mine-shaft);
text-align: inherit;
white-space: nowrap;
cursor: pointer;
}

.dropdownitem i svg {
display: none;
}

.bookmark {
margin-left: var(--pt2);
}

.active {
color: white;
background-color: green;
background-color: var(--blue);
}

.dropdownitem.active i svg {
display: block;
}

.active i svg path {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nu har vi den opsætning vi nu engang har. Man kan undgå denne lidt grimme css selector hvis man opretter svg'en som et react component, og sætter stroke og path til "currentColor" - så kan farven styres af css "color".

Da vi ikke har gjort dette før, så lad det ligge.

Du kunne evt spare "i" selector ved at give Icon dit classname istedet for at styre det med en parent.

stroke: var(--white);
}

.itemContainer {
display: flex;
justify-content: space-between;
}

.dropdownitem a {
text-decoration: none;
}

.dropdownitem:focus {
background: linear-gradient(to right, var(--blue) 10px, var(--concrete) 10px);
.dropdownitem:hover {
color: var(--blue);
font-weight: var(--body-font-semibold);
}

.dropdownitem:hover {
background: linear-gradient(to right, var(--blue) 10px, var(--concrete) 10px);
.dropdownitem:hover i svg {
display: block;
}

.dropdownitem:hover i svg path {
stroke: var(--blue);
}

.dropdownitem:focus i svg {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Kunne spare nogle linjer ved at duplikere selectore. Fx

.dropdownitem:hover i svg, .dropdownitem:focus i svg { display: block; }

Så længe det er den samme styling der skal applies

display: block;
}

.dropdownitem:focus i svg path {
stroke: var(--blue);
}

.dropdownwrap :global(.dropdown-toggle::after) {
display: none;
}

.dropdownmenu {
border: 1px solid var(--blue);
margin-top: var(--pt1_5);
border: 1px solid var(--gray);
background-color: var(--white);
z-index: 1;
/* bootstrap default styles override */
Expand Down
82 changes: 60 additions & 22 deletions src/components/work/overview/bookmarkDropdown/BookmarkDropdown.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,27 +6,58 @@ import Text from "@/components/base/text/Text";
import React, { useEffect, useState } from "react";
import { cyKey } from "@/utils/trim";
import useBookmarks from "@/components/hooks/useBookmarks";
import Icon from "@/components/base/icon/Icon";
import BookmarkMedium from "@/public/icons/bookmark_small.svg";

export function BookMarkMaterialSelector({ materialTypes, workId }) {
export function BookMarkMaterialSelector({
materialTypes,
workId,
size = { w: 6, h: 6 },
}) {
const bookmarkClick = () => {};

const { bookmark, setBookmark, isLoading } = useBookmarks();

const onSelect = async (material, workId) => {
const item = { key: workId + material, id: workId, materialType: material };
await setBookmark(item);
const onSelect = (material, workId) => {
const item = {
key: workId + material,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Skal key ikke også bruge material[0] ?

id: workId,
materialType: material[0],
};
setBookmark(item);
};

const [active, setActive] = useState(false);
const options = materialTypes.map((mat) => mat);

useEffect(() => {
if (!isLoading) {
const bookmarkIndex = bookmark?.findIndex((bookm) => bookm.id === workId);
let bookmarkIndex = -1;
// this one is used to set the overall button to active or not (if one of the materialtypes is selected)
if (options.length > 1) {
bookmarkIndex = bookmark?.findIndex((bookm) => bookm.id === workId);
} else if (options.length === 1) {
// if we have one material only we look for a specific key
bookmarkIndex = bookmark?.findIndex(
(bookm) => bookm.key === workId + options[0]
);
}
setActive(bookmarkIndex !== -1);
}
}, [bookmark]);

const options = materialTypes.map((mat) => mat);
if (options.length === 1) {
return (
<Bookmark
size={size}
className={styles.bookmark}
selected={active}
onClick={() => {
onSelect(options[0], workId);
}}
/>
);
}

return (
<Dropdown className={`${styles.dropdownwrap} `} align="end">
Expand All @@ -36,7 +67,12 @@ export function BookMarkMaterialSelector({ materialTypes, workId }) {
variant="success"
id="dropdown-basic"
>
<Bookmark onClick={bookmarkClick} selected={active} />
<Bookmark
size={{ w: 7, h: 7 }}
onClick={bookmarkClick}
selected={active}
className={styles.bookmark}
/>
</Dropdown.Toggle>
<Dropdown.Menu
className={styles.dropdownmenu}
Expand All @@ -47,29 +83,27 @@ export function BookMarkMaterialSelector({ materialTypes, workId }) {
})}
>
{options.map((material, index) => {
const activeItem =
bookmark?.findIndex((book) => book.key === workId + material[0]) !==
-1;
return (
<Dropdown.Item
as="div"
tabIndex="-1"
data-cy={`bookmark-${material}-${index}`}
key={`bookmark-${index}`}
className={`${styles.dropdownitem} ${
bookmark?.findIndex(
(book) => book.key === workId + material
) !== -1
? styles.active
: ""
activeItem ? styles.active : ""
}`}
onClick={() => {
onSelect(material, workId);
}}
onKeyDown={(e) => {
if (e.key === "Enter") {
onSelect(material, workId);
}
}}
>
<Text type="text3">{material}</Text>
<div className={styles.itemContainer}>
<Text type="text3">{material}</Text>

<Icon size={{ w: 3, h: 3 }}>
<BookmarkMedium />
</Icon>
</div>
</Dropdown.Item>
);
})}
Expand All @@ -78,8 +112,12 @@ export function BookMarkMaterialSelector({ materialTypes, workId }) {
);
}

export default function wrapper({ materialTypes, workId }) {
export default function wrapper({ materialTypes, workId, size }) {
return (
<BookMarkMaterialSelector materialTypes={materialTypes} workId={workId} />
<BookMarkMaterialSelector
materialTypes={materialTypes}
workId={workId}
size={size}
/>
);
}