Commit c31d394b authored by Magnus Westergaard's avatar Magnus Westergaard
Browse files

DEICH-5516: Add popular publications to related content section. Fix seed used...

DEICH-5516: Add popular publications to related content section. Fix seed used for shuffling. Clean up some unused code here and there.
parent a43257f5
......@@ -49,11 +49,11 @@ class DynamicList extends React.Component {
}
async search() {
const { data = {}, router, limited, randomizeHits } = this.props;
const { data = {}, router, randomizeHits } = this.props;
const { listQuery = "https://deichman.no/sok/*" } = data;
// Only fetch 6 items if the list is limited (default is 24) and not randomized
const pageSize = limited && !randomizeHits ? "6" : "";
// if randomizing, fetch more publications to pick randomly from
const pageSize = randomizeHits ? "50" : "";
this.setState({
isLoading: true
......@@ -133,7 +133,6 @@ class DynamicList extends React.Component {
totalCount={totalHits}
favourites={favourites}
onFavourite={this.handleFavourite}
limited={true}
/>
)}
</Block>
......@@ -175,13 +174,13 @@ function mapDispatchToProps(dispatch) {
function mapStateToProps(state, ownProps) {
const { biblioNumbers } = state.favourites;
const { randomSeed } = state.search;
const { seed } = state.random;
const { listQuery } = ownProps.data;
return {
favourites: biblioNumbers,
results: inlineResultsSelector(state, listQuery),
randomSeed
randomSeed: seed
};
}
......
......@@ -141,7 +141,7 @@ function publishedFagDetails({ publicationYear, fictionNonfiction }) {
}
}
function publisherDetails({ publishers }) {
function publisherDetails({ publishers = [] }) {
const primary = publishers[0];
if (primary) {
return {
......
......@@ -107,13 +107,13 @@ function mapDispatchToProps(dispatch) {
function mapStateToProps(state, ownProps) {
const { biblioNumbers } = state.favourites;
const { randomSeed } = state.search;
const { seed } = state.random;
const { query } = ownProps;
return {
favourites: biblioNumbers,
results: inlineResultsSelector(state, query),
randomSeed
randomSeed: seed
};
}
......
......@@ -59,7 +59,6 @@ const InspirationGrid = ({
favourites={favourites}
showFavorite={showFavorite}
onFavourite={onFavourite}
limited={limited}
hideAvatars={hideAvatars}
employeeId={employeeId}
/>
......
import React from "react";
import PropTypes from "prop-types";
import DynamicList from "../DynamicList";
import { translations } from "../../constants/translations";
import { Block } from "@digibib/deichman-ui";
export default function PublicationRelatedContent({ publication }) {
const mediaTypeQuery = `mediaType_${translations[publication.mediaType]}`;
return (
<Block top={8}>
<DynamicList
data={{
listQuery: `*?mediatype=${mediaTypeQuery}&sort=issuesTotal:desc&excludeUnavailable=excludeUnavailable`,
title: "Andre har også lånt"
}}
randomizeHits
/>
</Block>
);
}
PublicationRelatedContent.propTypes = {
publication: PropTypes.object.isRequired
};
import React from "react";
import { Block } from "@digibib/deichman-ui";
export default function WorkRecommendation({}) {
return (
<Block top={8}>
<div>Presentation of recommendation</div>
</Block>
);
}
import React from "react";
import { Block } from "@digibib/deichman-ui";
import WorkRecommendation from "./WorkRecommendations";
export default function WorkRecommendationContainer({}) {
return (
<Block top={8}>
<WorkRecommendation />
</Block>
);
}
......@@ -15,7 +15,7 @@ import WorkDetailsAccordionContainer from "../../components/WorkDetails/WorkDeta
import WorkPartsAccordionContainer from "../../components/WorkParts/WorkPartsAccordionContainer";
import WorkHeroContainer from "../../components/WorkHero/WorkHeroContainer";
import PublicationAccordionContainer from "../../components/PublicationList/PublicationAccordionContainer";
import WorkRecommendationContainer from "../../components/WorkRecommendations/WorkRecommendationsContainer";
import PublicationRelatedContent from "../../components/PublicationRelatedContent/PublicationRelatedContent";
import { useRouter } from "next/router";
class PublicationPage extends React.Component {
......@@ -33,6 +33,12 @@ class PublicationPage extends React.Component {
return { publicationId, showDraftRecommendationById };
};
componentDidMount() {
if (this.props.publication) {
this.setOverride(this.props.publication);
}
}
componentDidUpdate(prevProps) {
if (
prevProps.publication !== this.props.publication &&
......@@ -41,11 +47,7 @@ class PublicationPage extends React.Component {
this.setOverride(this.props.publication);
}
}
componentDidMount() {
if (this.props.publication) {
this.setOverride(this.props.publication);
}
}
setOverride(publication) {
this.setState({
overrides: {
......@@ -108,9 +110,8 @@ class PublicationPage extends React.Component {
<PublicationAccordionContainer />
</Container>
<Container>
<WorkRecommendationContainer />
<PublicationRelatedContent publication={publication} />
</Container>
{/*Should the components below still be included here? Why is the visibility state in redux? */}
</>
</WorkPageWrapper>
</Fragment>
......@@ -128,7 +129,7 @@ function mapStateToProps(state) {
const { publication, resourceApi } = state.resources;
return {
publication: publication,
publication,
resourceApi
};
}
......@@ -194,7 +195,6 @@ function WorkPageWrapper({
})}
</TabPane>
);
} else {
return Children.only(children);
}
return Children.only(children);
}
const initialState = () => {
return {
seed: Math.random() // Prevent diff between server/client-render
};
};
// Reducer
export default function reducer(state = initialState()) {
return state;
}
......@@ -18,6 +18,7 @@ import openingHours from "./openingHours";
import payments from "./payments";
import pages from "./pages";
import profile from "./profile";
import random from "./random";
import reservation from "./reservation";
import resources from "./resources";
import search from "./search";
......@@ -42,6 +43,7 @@ const rootReducer = combineReducers({
pages,
payments,
profile,
random,
reservation,
resources,
search,
......
......@@ -31,7 +31,6 @@ const GET_PUBLICATION_BY_SUBJECT_URIS_SUCCESS =
const GET_PUBLICATION_BY_SUBJECT_URIS_FAILURE =
"resources/GET_PUBLICATION_BY_SUBJECT_URIS_FAILURE";
const initialState = {
randomSeed: Math.random(), // Prevent changing random campaign on second, client-side render
work: {
currentItem: {},
history: []
......@@ -442,6 +441,7 @@ export function getPublicationsByWorkURI({
}
};
}
export function getPublicationsBySubjectURI(uri) {
return async dispatch => {
if (!uri) {
......@@ -470,33 +470,6 @@ export function getPublicationsBySubjectURI(uri) {
};
}
/**
* Selectors
*/
// Return 1 random campaign based on page and type (or no campaign if no matches)
export const randomRecommendationSelector = (
state,
showDraftRecommendationById = false
) => {
const { work = {}, randomSeed } = state.resources;
const { currentItem = {} } = work;
const { recommendations = [] } = currentItem;
// If previewing recommendation, return that one!
if (showDraftRecommendationById) {
return recommendations.find(
r =>
r.id ===
`https://content.deichman.no/recommendation/${showDraftRecommendationById}`
);
}
return (
recommendations[Math.floor(randomSeed * recommendations.length)] || false
);
};
// Return publication based on given recordId
export const publicationByRecordId = (state, recordId) => {
const { work = {} } = state.resources;
......@@ -505,11 +478,3 @@ export const publicationByRecordId = (state, recordId) => {
return publications.find(p => p.recordId === recordId) || {};
};
export const publicationByWorkURI = (state, URI) => {
return state.resources.publications[URI];
};
export const publicationsByWorkURIs = (state, URIs) => {
return URIs.map(URI => publicationByWorkURI(state, URI));
};
......@@ -32,8 +32,7 @@ const initialState = {
inProgress: false,
lastFetch: null,
error: null
},
randomSeed: Math.random() // Prevent diff between server/client-render
}
};
// Reducer
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment