Skip to content

Commit 0786c69

Browse files
committed
2.4.0
1 parent 79c1a78 commit 0786c69

File tree

18 files changed

+376
-133
lines changed

18 files changed

+376
-133
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,7 @@
144144
"react-helmet-async": "^1.0.3",
145145
"react-hooks": "^1.0.1",
146146
"react-i18next": "^11.12.0",
147+
"react-paginate": "^8.1.0",
147148
"react-router-dom": "^5.1.2",
148149
"react-show-more-text": "^1.4.6",
149150
"react-truncate": "^2.4.0",

server/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -160,13 +160,13 @@ app.use(function forceLiveDomain(req, res, next) {
160160
host === 'www.oppnadata.se' ||
161161
host === 'vidareutnyttjande.se')
162162
) {
163-
return res.redirect(301, 'https://www.dataportal.se/oppnadata');
163+
return res.redirect(301, 'https://www.dataportal.se/');
164164
}
165165
if (
166166
!origUrl.includes('/.well-known/acme-challenge/') &&
167167
host === 'oppnadata.local:3003'
168168
) {
169-
return res.redirect(301, 'http://localhost:3003/oppnadata');
169+
return res.redirect(301, 'http://localhost:3003/');
170170
}
171171
return next();
172172
});

src/assets/Icon_DetailedList.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import React from 'react';
22

33
export const DetailedList: React.FC = () => (
4-
<svg width="15" height="14" viewBox="0 0 15 14" fill="none" xmlns="http://www.w3.org/2000/svg">
4+
<svg width="14" height="14" viewBox="0 0 14 14" fill="none" xmlns="http://www.w3.org/2000/svg">
55
<rect width="9.7108" height="3.5" fill="#2B2A29" />
66
<rect y="5.25" width="9.7108" height="3.5" fill="#2B2A29" />
77
<rect y="10.5" width="9.7108" height="3.5" fill="#2B2A29" />

src/components/ApiExploring/ApiExplorer.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ export const ApiExplorer: React.FC<ApiExplorerProps> = (props) => {
3131
}
3232

3333
return (
34-
<div>
34+
<div lang='en'>
3535
{apiIndexContext.findDetection(props.contextId,props.entryId)
3636
&& (<SwaggerUI url={getAPiDetectionUrl()} />)}
3737
</div>
Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
import React, { Component, useEffect, useState } from 'react';
2+
import i18n from '../../i18n';
3+
import { EnvSettings } from '../../../config/env/EnvSettings';
4+
import { useQuery } from '@apollo/client';
5+
import { gql } from 'apollo-boost';
6+
import { slugify } from 'utilities/urlHelpers';
7+
import { Link } from 'react-router-dom';
8+
import Truncate from 'react-truncate';
9+
import ReactPaginate from 'react-paginate'
10+
let moment = require('moment');
11+
12+
export interface ArticleListProps {
13+
children?: React.ReactNode;
14+
env: EnvSettings;
15+
}
16+
17+
export const ArticleList: React.FC<ArticleListProps> = ({ env }) => {
18+
moment.locale(i18n.languages[0]);
19+
const NEWS = gql`
20+
{
21+
news(siteurl:"${env.CONTENTBACKEND_SITEURL}", lang:"${i18n.languages[0]}", take:50, skip:0, orderby:"startpublish desc"){
22+
id
23+
heading
24+
preambleHTML
25+
published
26+
modified
27+
}
28+
}
29+
`;
30+
31+
const { loading, error, data } = useQuery<{ news: Array<any> }>(NEWS);
32+
const [articleList, setArticleList] = useState<any[]>([]);
33+
34+
useEffect(() => {
35+
if (data?.news && data.news.length > 0) {
36+
setArticleList(data.news);
37+
}
38+
}, [!loading && data]);
39+
40+
const [articlesNumber, setPageNumber] = useState (0);
41+
const articlesPerPage = 2;
42+
const articlesVisited = articlesNumber * articlesPerPage;
43+
44+
const displayArticles = articleList
45+
.slice(articlesVisited, articlesVisited + articlesPerPage);
46+
47+
// console.log(displayArticles, "displayArticles")
48+
// console.log(articleList,"articlelist")
49+
50+
const pageCount = Math.ceil(articleList.length / articlesPerPage);
51+
// console.log(pageCount, "pagecount")
52+
53+
const CurrentPage = articlesVisited / pageCount;
54+
55+
const changePage = ({selected} : {selected:any}) => {
56+
setPageNumber(selected);
57+
};
58+
59+
console.log(changePage);
60+
61+
return (
62+
63+
<div className="news-list">
64+
<ul>
65+
{loading && (
66+
<span className="text-5 loading">{i18n.t('common|loading')}</span>
67+
)}
68+
{!loading && error && (
69+
<span className="loading-msg">
70+
Det finns inga nyheter att visa för tillfället.
71+
</span>
72+
)}
73+
{!loading &&
74+
displayArticles.map((n, index) => {
75+
return (
76+
<li key={index}>
77+
<span className="text-6">
78+
{moment(n.published.toString()).format('D MMM YYYY')}
79+
</span>
80+
<Link
81+
className="text-4"
82+
onClick={() => console.log('hello')}
83+
to={`/${i18n.languages[0]}/${i18n.t('routes|news|path')}/${
84+
n.id
85+
}/${slugify(n.heading)}`}
86+
>
87+
{n.heading}
88+
</Link>
89+
90+
<p className="text-5">
91+
<Truncate lines={2}>{n.preambleHTML}</Truncate>
92+
</p>
93+
</li>
94+
);
95+
})}
96+
</ul>
97+
<div>
98+
{/* Sida av {pageCount} */}
99+
</div>
100+
101+
<ReactPaginate
102+
previousLabel="Föregående"
103+
nextLabel="Nästa"
104+
pageCount={pageCount}
105+
onPageChange={changePage}
106+
containerClassName="pagination-wrapper"
107+
previousLinkClassName="pagination-prev_btn default-button"
108+
nextLinkClassName="pagination-nex_btn default-button"
109+
/>
110+
</div>
111+
);
112+
};

src/components/Articles/ArticleList.tsx

Lines changed: 59 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { gql } from 'apollo-boost';
66
import { slugify } from 'utilities/urlHelpers';
77
import { Link } from 'react-router-dom';
88
import Truncate from 'react-truncate';
9+
import ReactPaginate from 'react-paginate'
910
let moment = require('moment');
1011

1112
export interface ArticleListProps {
@@ -36,8 +37,39 @@ export const ArticleList: React.FC<ArticleListProps> = ({ env }) => {
3637
}
3738
}, [!loading && data]);
3839

40+
const [articlesNumber, setPageNumber] = useState(0);
41+
const articlesPerPage = 10;
42+
const articlesVisited = articlesNumber * articlesPerPage;
43+
const [currentPage, setCurrentPage] = useState(1);
44+
45+
const displayArticles = articleList
46+
.slice(articlesVisited, articlesVisited + articlesPerPage);
47+
48+
const pageCount = Math.ceil(articleList.length / articlesPerPage);
49+
50+
const newsFocus = () => {
51+
let content = document.querySelector('#newsList');
52+
if (!content) return;
53+
54+
const focusable = content.querySelectorAll<HTMLElement>(
55+
'button, [href], input, select, textarea, [tabindex]:not([tabindex="-1"])'
56+
);
57+
58+
const first = focusable[0];
59+
60+
if (first) {
61+
first.focus();
62+
}
63+
};
64+
65+
const changePage = ({ selected }: { selected: any }) => {
66+
let currentPage = selected + 1;
67+
setPageNumber(selected);
68+
setCurrentPage(selected + 1);
69+
};
70+
3971
return (
40-
<div className="news-list">
72+
<div className="news-list" id='newsList'>
4173
<ul>
4274
{loading && (
4375
<span className="text-5 loading">{i18n.t('common|loading')}</span>
@@ -48,7 +80,7 @@ export const ArticleList: React.FC<ArticleListProps> = ({ env }) => {
4880
</span>
4981
)}
5082
{!loading &&
51-
articleList.map((n, index) => {
83+
displayArticles.map((n, index) => {
5284
return (
5385
<li key={index}>
5486
<span className="text-6">
@@ -57,20 +89,41 @@ export const ArticleList: React.FC<ArticleListProps> = ({ env }) => {
5789
<Link
5890
className="text-4"
5991
onClick={() => console.log('hello')}
60-
to={`/${i18n.languages[0]}/${i18n.t('routes|news|path')}/${
61-
n.id
62-
}/${slugify(n.heading)}`}
92+
to={`/${i18n.languages[0]}/${i18n.t('routes|news|path')}/${n.id
93+
}/${slugify(n.heading)}`}
6394
>
6495
{n.heading}
6596
</Link>
6697

67-
<p className="text-5">
98+
<p className="text-6">
6899
<Truncate lines={2}>{n.preambleHTML}</Truncate>
69100
</p>
70101
</li>
71102
);
72103
})}
73104
</ul>
105+
{/* Show pagination only when there is more than one page */}
106+
{(pageCount > 1) && (
107+
<div className='currentpage-tracker'>
108+
<span className='text-6'>
109+
{i18n.t('pages|search|page')} {currentPage} {i18n.t('common|of')} {pageCount}
110+
</span>
111+
</div>
112+
)}
113+
{(pageCount > 1) && (
114+
<ReactPaginate
115+
previousLabel="Föregående"
116+
nextLabel="Nästa"
117+
onClick={newsFocus}
118+
pageCount={pageCount}
119+
onPageChange={changePage}
120+
containerClassName="pagination-wrapper"
121+
previousLinkClassName="pagination-prev_btn default-button"
122+
previousAriaLabel="Föregående sida"
123+
nextLinkClassName="pagination-nex_btn default-button"
124+
nextAriaLabel="Nästa sida"
125+
/>
126+
)}
74127
</div>
75128
);
76129
};

src/components/Header/Header.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,8 @@ export const Header: React.FC<HeaderProps> = ({ env }) => {
5050
return (
5151
<>
5252
<header>
53-
<InnerBox paddingY={0} paddingX={2}>
53+
<div className='main-container'>
54+
<InnerBox>
5455
<Container>
5556
<FocusTrap active={focusTrap}>
5657
<Box className="header-box">
@@ -198,6 +199,7 @@ export const Header: React.FC<HeaderProps> = ({ env }) => {
198199
</FocusTrap>
199200
</Container>
200201
</InnerBox>
202+
</div>
201203
</header>
202204
</>
203205
);

src/components/Search/EntryScape.ts

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -587,20 +587,20 @@ export class EntryScape {
587587
var metaFacets = searchList.getFacets();
588588
}
589589

590-
let hitSpecification:HitSpecification = {
591-
descriptionResource: "blaa",
592-
path: "hmm",
593-
titleResource: "blaa"
594-
};
595-
596590
//construct SearchHit-array
597591
children.forEach(async (child:any) => {
598-
592+
593+
let hitSpecification:HitSpecification = {
594+
descriptionResource: "blaa",
595+
path: "hmm",
596+
titleResource: "blaa"
597+
};
598+
599599
let metaData = child.getMetadata();
600600
let context = child.getContext();
601601
let rdfType = metaData.findFirstValue(child.getResourceURI(), "http://www.w3.org/1999/02/22-rdf-syntax-ns#type");
602602

603-
hitSpecification = this.hitSpecifications[rdfType] || { titleResource:"dcterms:title", path: "/datasets/", descriptionResource: "dcterms:description" }
603+
hitSpecification = this.hitSpecifications[rdfType] || { titleResource:"dcterms:title", path: "/datasets/", descriptionResource: "dcterms:description" }
604604

605605
let hit = {
606606
entryId: child.getId(),
@@ -614,15 +614,16 @@ export class EntryScape {
614614
descriptionLang: getEntryLang(metaData,hitSpecification.descriptionResource || "dcterms:description",lang),
615615
};
616616

617-
618-
if(hitSpecification.pathResolver)
617+
if(hitSpecification.pathResolver){
619618
hit.url = hitSpecification.pathResolver(child);
620-
else
619+
}
620+
else{
621621
hit.url = `${hitSpecification.path || 'datamangd'}${context.getId()}_${hit.entryId}/${slugify(hit.title)}`;
622-
622+
}
623+
623624
hit.description = hit.description && hit.description.length > 250? `${(hit.description + '').substr(0,250)}...` : hit.description;
624625

625-
hits.push(hit);
626+
hits.push(hit);
626627
});
627628

628629
resolve({

src/pages/SearchPage/SearchResults.tsx

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ const SortingOptions: React.FC<{
6767
className="text-6"
6868
id=""
6969
name={i18n.t('pages|search|numberofhits')}
70-
onChange={(event) => {
70+
onChange={(event) => {
7171
event.preventDefault();
7272
clearCurrentScrollPos();
7373
search
@@ -109,13 +109,13 @@ const SortingOptions: React.FC<{
109109
}}
110110
>
111111
<option aria-selected={search.request.take == 20} value="20">
112-
{i18n.t('pages|search|numberofhits-20')}
112+
{i18n.t('pages|search|numberofhits-20')}
113113
</option>
114114
<option aria-selected={search.request.take == 50} value="50">
115-
{i18n.t('pages|search|numberofhits-50')}
115+
{i18n.t('pages|search|numberofhits-50')}
116116
</option>
117117
<option aria-selected={search.request.take == 100} value="100">
118-
{i18n.t('pages|search|numberofhits-100')}
118+
{i18n.t('pages|search|numberofhits-100')}
119119
</option>
120120
</select>
121121
</div>
@@ -221,7 +221,7 @@ export const SearchResults: React.FC<SearchResultsProps> = ({
221221
`${search.result.count} ${i18n.t('pages|search|dataset-hits')}`}
222222
</h2>
223223

224-
{searchType == 'data' && (
224+
{searchType == 'data' && (
225225
<div className={showSorting ? "active sorting-options-wrapper" : "sorting-options-wrapper"}>
226226
<SortingOptions
227227
setCompact={setCompact}
@@ -366,7 +366,12 @@ export const SearchResults: React.FC<SearchResultsProps> = ({
366366
</button>
367367
)}
368368
</div>
369-
369+
<div className='row justify-center current-page'>
370+
<span className='text-6'>
371+
{i18n.t('pages|search|page')} {(search.request.page || 0) + 1}{' '}
372+
{i18n.t('common|of')} {search.result.pages}
373+
</span>
374+
</div>
370375
<div className="prev-next-page">
371376
<button
372377
disabled={(search.request.page || 0) === 0}
@@ -387,10 +392,6 @@ export const SearchResults: React.FC<SearchResultsProps> = ({
387392
>
388393
{i18n.t('pages|search|prev-page')}
389394
</button>
390-
<span>
391-
{i18n.t('pages|search|page')} {(search.request.page || 0) + 1}{' '}
392-
{i18n.t('common|of')} {search.result.pages}
393-
</span>
394395
<button
395396
className=""
396397
disabled={

src/scss/general/general.scss

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,10 @@
4242
align-items: center;
4343
}
4444

45+
.justify-center{
46+
justify-content: center;
47+
}
48+
4549
.col {
4650
display: flex;
4751
flex-direction: column;

0 commit comments

Comments
 (0)