diff --git a/www/app/all/page.tsx b/www/app/all/page.tsx index 49577f4e5..4afdfe2fd 100644 --- a/www/app/all/page.tsx +++ b/www/app/all/page.tsx @@ -17,7 +17,6 @@ const AllPage = async () => { const entriesArr = await Promise.all(entriesPromisesArr) return (
-
{entriesArr.map((item, index) => (
    diff --git a/www/app/page.tsx b/www/app/page.tsx index c43e5ea64..a77050219 100644 --- a/www/app/page.tsx +++ b/www/app/page.tsx @@ -16,15 +16,20 @@ const getData = async ( } }; -const Home = async () => { +const Home = async ({ + searchParams, +}: { + searchParams: { [key: string]: string | string[] | undefined }; +}) => { + const searchTerms: string = searchParams.searchterms as string; const { commitList }: any = await getData(); // Workaround from Next.JS GitHub // https://github.com/vercel/next.js/issues/42292#issuecomment-1464048350 - const listContainer: JSX.Element = await ListContainer({ commitList }) + const listContainer: JSX.Element = await ListContainer({ commitList, searchTerms }) return (
    - +
    {listContainer}
    diff --git a/www/components/EntryTile.tsx b/www/components/EntryTile.tsx index 36b74c73a..c334f7ec3 100644 --- a/www/components/EntryTile.tsx +++ b/www/components/EntryTile.tsx @@ -2,7 +2,7 @@ import React from "react"; import EntryTileVew from "./EntryTileView"; const fs = require('fs'); -const EntryTile: any = async ({ entryID, version }: any) => { +const EntryTile: any = async ({ entryID, version, searchTerms }: any) => { if (version.match(/v\d{4}\.json/) === null) return (
    Invalid version
    ) // List files in data/versions/{entryID} folder const versionsFolderPath = `../data/versions/${entryID}`; @@ -10,6 +10,8 @@ const EntryTile: any = async ({ entryID, version }: any) => { const afterData = await fs.promises.readFile(`${versionsFolderPath}/${version}`); const afterObj = JSON.parse(afterData) + if (searchTerms && searchTerms !== '' && JSON.stringify(afterObj).toLowerCase().indexOf(searchTerms.toLowerCase()) === -1) return (<>) + const getBeforeVersion = (afterVersion: string) => { if (afterVersion === 'v0001.json') return '' const afterVersionNum: number = parseInt(afterVersion.replace(/^v/,'').replace(/\.json$/, '')) diff --git a/www/components/ListContainer.tsx b/www/components/ListContainer.tsx index 41fecbe61..91c6bf5c4 100644 --- a/www/components/ListContainer.tsx +++ b/www/components/ListContainer.tsx @@ -6,7 +6,7 @@ interface Props { commitList: string[]; } -const ListContainer = async ({ commitList } : {commitList: string[]}) => { +const ListContainer = async ({ commitList, searchTerms } : {commitList: string[], searchTerms: string}) => { const getCommitData = async (sha: string) => await octokit.rest.repos.getCommit({ owner: owner, repo: repo, @@ -51,7 +51,7 @@ const ListContainer = async ({ commitList } : {commitList: string[]}) => {
      {groupedData[item].map((entry: any) => { return ( - + ) })}
    diff --git a/www/components/Search.tsx b/www/components/Search.tsx index 63ec9693e..0fe571d27 100644 --- a/www/components/Search.tsx +++ b/www/components/Search.tsx @@ -2,8 +2,8 @@ import React, { useEffect, useState } from 'react'; import useDebounce from '../libs/useDebounce' -const Search = () => { - const [search, setSearch] = useState(''); +const Search = ({searchTerms} : {searchTerms?: string | undefined}) => { + const [search, setSearch] = useState(searchTerms || ''); // Debouncing taken from // https://hackernoon.com/how-to-use-debounce-in-nextjs const debouncedSearch = useDebounce(search, 500) @@ -14,20 +14,7 @@ const Search = () => { const updateView = (inputValue: string) => { - // Entries can be found as li with id='li-container-*' - const entries = document.querySelectorAll('li[id^="li-container-"]'); - entries.forEach((entry) => { - const entryHTMLElement = entry as HTMLElement; - if (inputValue === '') { - entryHTMLElement.style.display = 'block'; - } - if (!entryHTMLElement.innerHTML.toLowerCase().includes(inputValue.toLowerCase())) { - entryHTMLElement.style.display = 'none'; - } - else { - entryHTMLElement.style.display = 'block'; - } - }) + window.history.replaceState({}, '', `/?searchterms=${inputValue}`) } return ( diff --git a/www/next.config.js b/www/next.config.js index 00c71a4de..1858c513d 100644 --- a/www/next.config.js +++ b/www/next.config.js @@ -9,7 +9,6 @@ const nextConfig = { }, ], }, - output: "export" }; module.exports = nextConfig;