diff --git a/site/gatsby-site/cypress/e2e/unit/functions/processNotifications.cy.js b/site/gatsby-site/cypress/e2e/unit/functions/processNotifications.cy.js index fd4f88bdc4..a6f326f061 100644 --- a/site/gatsby-site/cypress/e2e/unit/functions/processNotifications.cy.js +++ b/site/gatsby-site/cypress/e2e/unit/functions/processNotifications.cy.js @@ -269,9 +269,14 @@ const stubEverything = () => { .returns({ toArray: () => subscriptionsToIncidentUpdates }); } + const incidentIds = pendingNotificationsToPromotedIncidents.map( + (pendingNotification) => pendingNotification.incident_id + ); + stub .withArgs({ type: SUBSCRIPTION_TYPE.submissionPromoted, + incident_id: { $in: incidentIds }, }) .as(`subscriptions.find("${SUBSCRIPTION_TYPE.submissionPromoted}")`) .returns({ toArray: () => subscriptionsToPromotedIncidents }); @@ -450,6 +455,7 @@ describe('Functions', () => { expect(subscriptionsCollection.find.getCall(5).args[0]).to.deep.equal({ type: SUBSCRIPTION_TYPE.submissionPromoted, + incident_id: { $in: [217] }, }); for (const subscription of subscriptionsToPromotedIncidents) { @@ -465,8 +471,6 @@ describe('Functions', () => { incident_id: pendingNotification.incident_id, }); - console.log('subscriptionsToPromotedIncidents', global.context.functions); - const userIds = subscriptionsToPromotedIncidents.map((subscription) => subscription.userId); const incident = incidents.find((i) => i.incident_id == pendingNotification.incident_id); diff --git a/site/gatsby-site/src/components/discover/Controls.js b/site/gatsby-site/src/components/discover/Controls.js index cf2473f413..b0d7b4b740 100644 --- a/site/gatsby-site/src/components/discover/Controls.js +++ b/site/gatsby-site/src/components/discover/Controls.js @@ -27,7 +27,7 @@ const Controls = () => { return ( <> -
+
diff --git a/site/gatsby-site/src/components/discover/Discover.js b/site/gatsby-site/src/components/discover/Discover.js index 41cb910f06..775c008c08 100644 --- a/site/gatsby-site/src/components/discover/Discover.js +++ b/site/gatsby-site/src/components/discover/Discover.js @@ -1,4 +1,4 @@ -import React, { useState } from 'react'; +import React, { useEffect, useRef, useState } from 'react'; import Col from 'elements/Col'; import Row from 'elements/Row'; import Container from 'elements/Container'; @@ -16,6 +16,7 @@ import parseURL from './parseURL'; import { queryConfig } from './queryParams'; import { history } from 'instantsearch.js/es/lib/routers'; import Pagination from './Pagination'; +import debounce from 'lodash/debounce'; const searchClient = algoliasearch( config.header.search.algoliaAppId, @@ -34,6 +35,28 @@ export default function Discover() { const [indexName] = useState(`instant_search-${locale}-featured`); + const [width, setWidth] = useState(0); + + const handleWindowSizeChange = useRef( + debounce(() => { + setWidth(window.innerWidth); + }, 1000) + ).current; + + useEffect(() => { + window.addEventListener('resize', handleWindowSizeChange); + + handleWindowSizeChange(); + + return () => { + window.removeEventListener('resize', handleWindowSizeChange); + }; + }, []); + + if (width == 0) { + return null; + } + return ( - - - + {width > 767 ? : } diff --git a/site/gatsby-site/src/components/discover/OptionsModal.js b/site/gatsby-site/src/components/discover/OptionsModal.js index 7ce454b136..94e984f282 100644 --- a/site/gatsby-site/src/components/discover/OptionsModal.js +++ b/site/gatsby-site/src/components/discover/OptionsModal.js @@ -1,4 +1,4 @@ -import React, { useEffect, useState } from 'react'; +import React, { useState } from 'react'; import REFINEMENT_LISTS from 'components/discover/REFINEMENT_LISTS'; import { AccordionFilter } from './Filter'; import Stats from './Stats'; @@ -8,16 +8,42 @@ import DisplayModeSwitch from './DisplayModeSwitch'; import Button from 'elements/Button'; import DisplayOptions from './DisplayOptions'; import { Accordion, Modal } from 'flowbite-react'; +import { useRange, useRefinementList } from 'react-instantsearch'; + +const VirtualRefinementList = ({ attribute }) => { + useRefinementList({ attribute }); + + return null; +}; + +const VirtualRange = ({ attribute }) => { + useRange({ attribute }); + + return null; +}; + +const componentsMap = { + refinement: VirtualRefinementList, + range: VirtualRange, +}; + +function VirtualFilters() { + return ( + <> + {REFINEMENT_LISTS.map((list) => { + const Component = componentsMap[list.type]; + + return ; + })} + + ); +} function OptionsModal() { const [showModal, setShowModal] = useState(false); const handleClose = () => setShowModal(false); - const [mounted, setMounted] = useState(false); - - useEffect(() => setMounted(true), []); - return (
@@ -33,31 +59,32 @@ function OptionsModal() {
- {mounted && ( - - - Search Options - - -
-
- - -
- - {REFINEMENT_LISTS.map((list) => ( - - ))} - + + + + + + Search Options + + +
+
+ +
- - - - - - )} + + {REFINEMENT_LISTS.map((list) => ( + + ))} + +
+
+ + + +
); } diff --git a/site/gatsby-site/src/templates/citeTemplate.js b/site/gatsby-site/src/templates/citeTemplate.js index 97a9c6fa5f..76641c73a8 100644 --- a/site/gatsby-site/src/templates/citeTemplate.js +++ b/site/gatsby-site/src/templates/citeTemplate.js @@ -248,6 +248,7 @@ function CiteTemplate({ reportCount: sortedReports.length, incidentDate: incident.date, editors: incident.editors + .filter((editor) => editor && editor.first_name && editor.last_name) .map(({ first_name, last_name }) => `${first_name} ${last_name}`) .join(', '), }} diff --git a/site/realm/functions/processNotifications.js b/site/realm/functions/processNotifications.js index 74c795ad97..3af86ef9ec 100644 --- a/site/realm/functions/processNotifications.js +++ b/site/realm/functions/processNotifications.js @@ -4,7 +4,7 @@ const getRecipients = async (userIds) => { for (const userId of userIds) { const userResponse = await context.functions.execute('getUser', { userId }); - if (userResponse.email) { + if (userResponse?.email) { recipients.push({ email: userResponse.email, userId, @@ -262,13 +262,19 @@ exports = async function () { // Notifications to New Promotions try { + + // Finds all pending notifications to New Promotions const pendingNotificationsToNewPromotions = await notificationsCollection.find({ processed: false, type: 'submission-promoted' }).toArray(); + // Gets all incident ids from pending notifications to New Promotions + const pendingNotificationsIncidentIds = pendingNotificationsToNewPromotions.map((notification) => notification.incident_id); + if (pendingNotificationsToNewPromotions.length > 0) { result += pendingNotificationsToNewPromotions.length; - const subscriptionsToNewPromotions = await subscriptionsCollection.find({ type: 'submission-promoted' }).toArray(); + // Finds all subscriptions to New Promotions for those new incidents + const subscriptionsToNewPromotions = await subscriptionsCollection.find({ type: 'submission-promoted', incident_id: { $in: pendingNotificationsIncidentIds } }).toArray(); // Process subscriptions to New Incidents if (subscriptionsToNewPromotions.length > 0) {