From 5279704af1ed3347ada0600fa08065a1876944ae Mon Sep 17 00:00:00 2001 From: Stephan Ullmann Date: Thu, 20 Apr 2023 12:00:16 +0200 Subject: [PATCH] added item count to articles --- src/App.css | 39 ++++++++++++++-------------- src/components/Article.jsx | 6 ++++- src/components/Pagination.jsx | 49 +++++++++++++++++++---------------- 3 files changed, 52 insertions(+), 42 deletions(-) diff --git a/src/App.css b/src/App.css index b799da9..a114ef6 100644 --- a/src/App.css +++ b/src/App.css @@ -180,7 +180,7 @@ nav ul li a:hover { background-color: var(--article_bg); color: var(--text); text-indent: 15px; - outline:none; + outline: none; } @media (max-width: 800px) { @@ -240,21 +240,24 @@ nav ul li a:hover { border-radius: 1.5rem; position: relative; list-style: none; + display: flex; + align-items: center; } .Article { - padding: 0.75rem 1rem; - margin: 0.25rem 3.5rem; - position: relative; + padding: 0.75rem 0rem; + /* max-width: 1080px; */ + min-width: 1000px; + display: inline-block; } -.Article::before { - content: counter(list-item) "."; +.Article__num { + display: inline-block; font-size: 2rem; font-weight: 900; - position: absolute; - inset: 1rem auto 1rem -2rem; + margin: 0 0.75rem 0 1rem; color: var(--text); + text-align: center; } .Article__btn-up { @@ -355,26 +358,24 @@ nav ul li a:hover { #root > div > div.Body > div.pagination > ul { display: flex; - justify-content: flex-start; - align-items: center; - gap: 50px; - list-style: none; - flex-direction: row; - cursor: pointer; - - width: fit-content; + justify-content: flex-start; + align-items: center; + gap: 50px; + list-style: none; + flex-direction: row; + cursor: pointer; + + width: fit-content; min-height: 15px; border: none; border-radius: 10px 10px 10px 10px; background-color: var(--article_bg); color: var(--text); - outline:none; + outline: none; margin: 40px; padding: 10px; } - - /* ============================== Footer ============================== */ diff --git a/src/components/Article.jsx b/src/components/Article.jsx index dcdb75d..3dd851c 100644 --- a/src/components/Article.jsx +++ b/src/components/Article.jsx @@ -3,6 +3,7 @@ import ReactTimeAgo from "react-time-ago"; export default function Article({ title, + articleNum, url, points, author, @@ -39,10 +40,13 @@ export default function Article({ }); }; + const slicedTitle = title.length > 60 ? `${title.slice(0, 60)} ...` : title; + const urlText = url?.split("/")[2]; return (
  • + {articleNum}.
    -

    {title ? title : "Article is removed :("}

    +

    {title ? slicedTitle : "Article is removed :("}

    - {currentItems && - currentItems.map((item) => ( -
    -

    Item #{item}

    -
    - ))} - - ); - } - - -export default function Pagination({ itemsPerPage, fetchedData, setFetchedData, hits, setHitsPerPage, setPageNum, setHits }) { + return ( + <> + {currentItems && + currentItems.map((item) => ( +
    +

    Item #{item}

    +
    + ))} + + ); +} - const items = hits +export default function Pagination({ + itemsPerPage, + fetchedData, + setFetchedData, + hits, + setHitsPerPage, + setPageNum, + setHits, +}) { + const items = hits; -function Items({ currentItems }) { + function Items({ currentItems }) { return ( <> {currentItems && @@ -59,8 +65,9 @@ function Items({ currentItems }) { <> {/* */}
      - {currentItems.map((item) => ( + {currentItems.map((item, index) => (