Skip to content

Commit

Permalink
fix: address pr comments
Browse files Browse the repository at this point in the history
  • Loading branch information
hetd54 committed Nov 22, 2023
1 parent dd32d32 commit d73ff7e
Show file tree
Hide file tree
Showing 10 changed files with 181 additions and 253 deletions.
118 changes: 16 additions & 102 deletions packages/gatsby-theme-project-portal/gatsby-node.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const { withDefaults } = require(`./utils/default-options`)
const fs = require("fs")
const { createSearchIndex } = require(`./utils/search`)
const { createSearchIndex, searchQuery } = require(`./utils/search`)
const {
siteMetadataTypeDefs,
projectTypeDefs,
Expand Down Expand Up @@ -35,55 +35,9 @@ exports.createPages = async ({ graphql, actions, reporter }) => {
query {
allProject {
nodes {
title
agency
topics {
title
}
slug
summary
statusOfData
status
startDate
requirement
question
purpose
projectTeam {
name
employer
}
priorResearch
opportunityCloses
mainContact {
name
}
fundingInfo
expertise
faq {
text
title
}
deliverable
emailContent
endDate
slug
}
}
allGeneralPage {
nodes {
slug
lede
faq {
text
title
}
aims {
text
title
}
title
}
}
allCardPage {
nodes {
slug
Expand Down Expand Up @@ -195,61 +149,7 @@ exports.createPages = async ({ graphql, actions, reporter }) => {
}

exports.onPreBuild = async ({ reporter, basePath, pathPrefix, graphql }) => {
const result = await graphql(`
query {
allProject {
nodes {
title
agency
topics {
title
}
slug
summary
statusOfData
status
startDate
requirement
question
purpose
projectTeam {
name
employer
}
priorResearch
opportunityCloses
mainContact {
name
}
fundingInfo
expertise
faq {
text
title
}
deliverable
emailContent
endDate
slug
}
}
allGeneralPage {
nodes {
slug
lede
faq {
text
title
}
aims {
text
title
}
title
}
}
}
`)
const result = await graphql(searchQuery)
const { allProject, allGeneralPage } = result.data

const [index, documents] = createSearchIndex({ allProject, allGeneralPage })
Expand All @@ -263,6 +163,20 @@ exports.onPreBuild = async ({ reporter, basePath, pathPrefix, graphql }) => {
if (err) console.error(err)
}
)
// this is a function which grabs the page from the original documents
// lunr tosses this info for SPEED
const reduceDocuments = documents.reduce(function (page, document) {
page[document.slug] = document
return page
}, {})

await fs.writeFile(
"static/documents-reduced.json",
JSON.stringify(reduceDocuments),
(err) => {
if (err) console.error(err)
}
)

reporter.info(
`Site was built with basePath: ${basePath} & pathPrefix: ${pathPrefix}`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ export const LongTitle: Story = {
faq: [
{ title: "Question 1?", text: "Answer 1!" },
{
title: "This is another question?",
title: "This is another different question?",
text: "Here's an answer for that question! Yay!",
},
],
Expand Down Expand Up @@ -165,6 +165,58 @@ export const Minimum: Story = {
},
}

export const Maximum: Story = {
args: {
question: "Is there a difference between brown sugar and white sugar?",
summary:
"Contrary to common belief, they are nutritionally similar. Nutritionally speaking, all natural sugars have relatively comparable nutritional value with approximately 15 calories per teaspoon (4.2 g).\n",
title: "Sugar Investigations in the US",
mainContact: {
name: "Contact Name",
title: "Title",
employer: "Employer",
email: "[email protected]",
},

status: "open",
opportunityCloses: new Date("2022-03-04"),
startDate: new Date("2022-01-03"),
endDate: new Date("2022-03-04"),
agency: "Sugar Agency",
topics: [
{ slug: "conspiracy", title: "conspiracy" },
{ slug: "investigation", title: "investigation" },
],
lastModified: new Date("2022-05-27T16:34:04.000Z"),
slug: "project/sugar-investigations",
emailContent:
"Dearest community, Are you interested in knowing about sugars? So are we! Join our search!",
deliverable:
"Analysis of existing sugars in the United States. Summary of and detailed recommendations and potential action steps to inform the public about the sugars they are consuming.  \\n* See project summary for additional information.",
purpose:
"Results will be shared with the FDA and whoever else wants these results. We have no oversight and thus may do as we wish.",
expertise:
"While our team does not have previous experience in organic chemistry, we are committed to uncovering the truth.",
requirement: "I do not understand this question. Next.",
keyDates: "Publish data at some point in time.",
priorResearch: "Prior research is published in many reputable journals.",
statusOfData: "Data collection has not begun.",
fundingInfo:
"Our team will evaluate whether or not a project needs money, and we will most likely need the project team to figure out funding.",
openText: "Are you interested in collaborating?",
ongoingText: "This project is ongoing.",
completeText: "This project is complete.",
projectTeam: ProjectTeamStories.Primary.args.contacts,
faq: [
{ title: "Question 1?", text: "Answer 1!" },
{
title: "This is another question?",
text: "Here's an answer for that question! Yay!",
},
],
},
}

export const TailwindXSWindow: Story = {
args: Primary.args,
parameters: { viewport: { defaultViewport: "tailwindXS" } },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,22 +23,23 @@ export const manyProjects = {
{ ...ProjectDetailStories.Open.args },
{ ...ProjectDetailStories.Ongoing.args },
{ ...ProjectDetailStories.Completed.args },
{ ...ProjectDetailStories.Maximum.args },
],
}

export const oneProject = {
nodes: [{ ...ProjectDetailStories.LongTitle.args }],
}

export const twoGeneralPages = {
export const twoGenPages = {
nodes: [
{
slug: "about",
...AboutPageStories.NoImage.args.data.generalPage,
...AboutPageStories.Primary.args.data.generalPage,
},
{
slug: "contact",
...ContactPageStories.NoImage.args.data.generalPage,
...ContactPageStories.Primary.args.data.generalPage,
},
],
}
Expand All @@ -47,18 +48,15 @@ export const oneGeneralPage = {
nodes: [
{
slug: "about",
...AboutPageStories.NoImage.args.data.generalPage,
...AboutPageStories.Primary.args.data.generalPage,
},
],
}

export const noProjectPage = {
nodes: [{}],
}

export const noGeneralPage = {
export const noPage = {
nodes: [],
}

// Valid search function
const validSearches = async ({ canvasElement }) => {
const canvas = within(canvasElement)
Expand Down Expand Up @@ -129,7 +127,7 @@ export const manyData = {

// One general page, no project pages
const [indexOneGen, documentsOneGen] = createSearchIndex({
noProjectPage,
noPage,
oneGeneralPage,
})
const dbOneGen = documentsOneGen.reduce(function (acc, document) {
Expand All @@ -146,7 +144,7 @@ export const oneData = {
// No general pages, one project page
const [indexOneProj, documentsOneProj] = createSearchIndex({
oneProject,
noGeneralPage,
noPage,
})
const dbOneProj = documentsOneProj.reduce(function (acc, document) {
acc[document.slug] = document
Expand All @@ -159,7 +157,6 @@ export const oneProjectData = {
db: dbOneProj,
}

//
export const Primary: Story = {
args: manyData,
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,7 @@ export const SiteSearch: FunctionComponent<SearchProps> = ({
const item = (
<React.Fragment key={result.ref}>
<div className="px-2 py-4 overflow-hidden bg-white border border-gray-200 rounded-md shadow-md h-full flex flex-col md:mx-10 md:py-6 lg:mx-60">
<h2 className="capitalize">
{db[result.ref].question || db[result.ref].slug}
</h2>
<h2 className="capitalize">{db[result.ref].title}</h2>
<ul className="grid grid-rows-1 justify-center md:block">
<h2 className="font-sans text-black text-tag my-2 font-extrabold">
Match found in:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,31 +4,20 @@ import SiteSearch from "./SiteSearch"

export interface SearchWrapperProps {
siteUrl: string
index?: lunr.Index
dataBase?: Function
}

export const SearchWrapper: FunctionComponent<SearchWrapperProps> = ({
export const SiteSearchWrapper: FunctionComponent<SearchWrapperProps> = ({
siteUrl,
index,
dataBase,
}: SearchWrapperProps) => {
const [idx, setIdx] = useState()
const [db, setDb] = useState()
useEffect(() => {
const getIndex = async () => {
const savedIndex = await (await fetch("/lunr-index.json")).json()
const documents = await (await fetch("/documents.json")).json()
const db = await (await fetch("/documents-reduced.json")).json()

setIdx(lunr.Index.load(savedIndex))
// this is a function which grabs the slug from the original documents
// lunr tosses this info for SPEED
setDb(
documents.reduce(function (acc, document) {
acc[document.slug] = document
return acc
}, {})
)
setDb(db)
}

// Because Gatsby runs this on build, we need to say to ignore getting the json files
Expand All @@ -39,4 +28,3 @@ export const SearchWrapper: FunctionComponent<SearchWrapperProps> = ({

return <div>{<SiteSearch siteUrl={siteUrl} index={idx} db={db} />}</div>
}
export default SearchWrapper
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,4 @@ export { Accordion } from "./Accordion"
export { KeyDate } from "./KeyDate"
export { NavbarItem } from "./NavbarItem"
export { PageLayout } from "./PageLayout"
export { SiteSearchWrapper } from "./SiteSearchWrapper"
Loading

0 comments on commit d73ff7e

Please sign in to comment.