From 9737c39774321b00c4aa423fd3e9341a65740e45 Mon Sep 17 00:00:00 2001 From: Manuel S Date: Fri, 10 Sep 2021 03:00:46 +0200 Subject: [PATCH] fix: Fixed index API requests having scoped include parameter (#78) * Order of anime on seasonal pages is now alphabetically. * Added "time since last build" back in using new library, now also with timezone. --- package-lock.json | 14 ++++++++++++++ package.json | 1 + src/components/external-link/ExternalLink.js | 6 ++++-- src/components/listbox/Listbox.js | 2 +- src/lib/search.js | 11 ++++++++--- src/pages/dev.js | 20 ++++++++++++++++---- src/templates/season.js | 4 +++- 7 files changed, 47 insertions(+), 11 deletions(-) diff --git a/package-lock.json b/package-lock.json index efe7f78..fce47bf 100644 --- a/package-lock.json +++ b/package-lock.json @@ -32,6 +32,7 @@ "gatsby-plugin-styled-components": "^4.3.0", "gatsby-source-animethemes": "file:plugins/gatsby-source-animethemes", "gatsby-source-animethemes-db": "file:plugins/gatsby-source-animethemes-db", + "luxon": "^2.0.2", "node-fetch": "^2.6.1", "prismjs": "^1.24.1", "react": "^17.0.1", @@ -11737,6 +11738,14 @@ "es5-ext": "~0.10.2" } }, + "node_modules/luxon": { + "version": "2.0.2", + "resolved": "https://registry.npmjs.org/luxon/-/luxon-2.0.2.tgz", + "integrity": "sha512-ZRioYLCgRHrtTORaZX1mx+jtxKtKuI5ZDvHNAmqpUzGqSrR+tL4FVLn/CUGMA3h0+AKD1MAxGI5GnCqR5txNqg==", + "engines": { + "node": "*" + } + }, "node_modules/make-dir": { "version": "3.1.0", "resolved": "https://registry.npmjs.org/make-dir/-/make-dir-3.1.0.tgz", @@ -27628,6 +27637,11 @@ "es5-ext": "~0.10.2" } }, + "luxon": { + "version": "2.0.2", + "resolved": "https://registry.npmjs.org/luxon/-/luxon-2.0.2.tgz", + "integrity": "sha512-ZRioYLCgRHrtTORaZX1mx+jtxKtKuI5ZDvHNAmqpUzGqSrR+tL4FVLn/CUGMA3h0+AKD1MAxGI5GnCqR5txNqg==" + }, "make-dir": { "version": "3.1.0", "resolved": "https://registry.npmjs.org/make-dir/-/make-dir-3.1.0.tgz", diff --git a/package.json b/package.json index 5c21f59..bdff263 100644 --- a/package.json +++ b/package.json @@ -31,6 +31,7 @@ "gatsby-plugin-styled-components": "^4.3.0", "gatsby-source-animethemes": "file:plugins/gatsby-source-animethemes", "gatsby-source-animethemes-db": "file:plugins/gatsby-source-animethemes-db", + "luxon": "^2.0.2", "node-fetch": "^2.6.1", "prismjs": "^1.24.1", "react": "^17.0.1", diff --git a/src/components/external-link/ExternalLink.js b/src/components/external-link/ExternalLink.js index 1309990..66a9c06 100644 --- a/src/components/external-link/ExternalLink.js +++ b/src/components/external-link/ExternalLink.js @@ -6,8 +6,10 @@ export function ExternalLink({ href, children, ...props }) { return ( {children} -   - + +   + + ); } diff --git a/src/components/listbox/Listbox.js b/src/components/listbox/Listbox.js index adf7baa..1dc81c3 100644 --- a/src/components/listbox/Listbox.js +++ b/src/components/listbox/Listbox.js @@ -84,7 +84,7 @@ export function Listbox({ options, nullLabel, selectedValue, onSelect, noReset, > {selectedValue !== null ? selectedValue : nullLabel} diff --git a/src/lib/search.js b/src/lib/search.js index 421bf3a..e329e04 100644 --- a/src/lib/search.js +++ b/src/lib/search.js @@ -180,19 +180,24 @@ function generateGlobalSearchParameters(entities) { parameters.push( ...entities - .flatMap(generateEntitySearchParameters) + .flatMap((entity) => generateEntitySearchParameters(entity, true)) .filter((parameter, index, parameters) => parameters.indexOf(parameter) === index) ); return parameters; } -function generateEntitySearchParameters(entity) { +function generateEntitySearchParameters(entity, includeScoped = false) { const parameters = []; const config = entityConfigs[entity]; if (config.includes) { - parameters.push(`include[${config.singular || entity}]=${config.includes.join(",")}`); + const includesJoined = config.includes.join(","); + if (includeScoped) { + parameters.push(`include[${config.singular || entity}]=${includesJoined}`); + } else { + parameters.push(`include=${includesJoined}`); + } } if (config.fields) { diff --git a/src/pages/dev.js b/src/pages/dev.js index 4a27ffa..e419b60 100644 --- a/src/pages/dev.js +++ b/src/pages/dev.js @@ -6,7 +6,9 @@ import { FontAwesomeIcon } from "@fortawesome/react-fontawesome"; import { faInfo } from "@fortawesome/free-solid-svg-icons"; import { Box, Flex, Grid } from "components/box"; import { ExternalLink } from "components/external-link"; +import { DateTime } from "luxon"; import theme from "theme"; +import React, { useEffect, useState } from "react"; const StyledAnnouncement = styled(Text)` & a { @@ -23,12 +25,22 @@ const StyledLink = styled(Link)` `; export default function DevelopmentPage({ data: { site, allAnnouncement } }) { + const buildDateTime = DateTime.fromISO(site.buildTime).setLocale("en"); + const [ timeSinceBuild, setTimeSinceBuild ] = useState(); + + useEffect(() => { + setTimeSinceBuild(buildDateTime.toRelative()); + }, [ buildDateTime ]); + return ( Development Hub This site was last updated: - {site.buildTimeFormatted} + {buildDateTime.toLocaleString(DateTime.DATETIME_FULL)} + {!!timeSinceBuild && ( + ({timeSinceBuild}) + )} This page is still actively being worked on. If you are a developer and interested in contributing feel free to contact us on @@ -180,10 +192,10 @@ function PageGridItem({ path, otherPaths = {}, description }) { {description} {Object.entries(otherPaths).map(([path, description]) => ( - <> + {description} - + ))} ); @@ -200,7 +212,7 @@ function PageLink({ path }) { export const query = graphql` query IndexPageQuery { site { - buildTimeFormatted: buildTime(formatString: "LLL") + buildTime } allAnnouncement { nodes { diff --git a/src/templates/season.js b/src/templates/season.js index 833d819..14fe3a6 100644 --- a/src/templates/season.js +++ b/src/templates/season.js @@ -6,7 +6,9 @@ import { Box } from "components/box"; export default function SeasonDetailPage({ data: { allAnime }, pageContext: { year, season } }) { const pageTitle = `${season} ${year} Anime`; - const animeList = allAnime.nodes; + const animeList = allAnime.nodes + .filter((anime) => anime.name) + .sort((a, b) => a.name.localeCompare(b.name)); return (