Skip to content

Commit

Permalink
Merge branch 'staging' into feature/cloudflare-r2-backups
Browse files Browse the repository at this point in the history
  • Loading branch information
pdcp1 committed Nov 13, 2023
2 parents ed463c5 + a2931a5 commit 5d71605
Show file tree
Hide file tree
Showing 6 changed files with 97 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 });
Expand Down Expand Up @@ -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) {
Expand All @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion site/gatsby-site/src/components/discover/Controls.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ const Controls = () => {

return (
<>
<div className="justify-between gap-2 mt-4 hidden md:flex flex-wrap items-center">
<div className="justify-between gap-2 mt-4 flex flex-wrap items-center">
<div className="flex gap-4 items-center flex-wrap">
<div className="flex items-center">
<Stats />
Expand Down
29 changes: 25 additions & 4 deletions site/gatsby-site/src/components/discover/Discover.js
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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,
Expand All @@ -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 (
<InstantSearch
searchClient={searchClient}
Expand Down Expand Up @@ -62,9 +85,7 @@ export default function Discover() {
</Col>
</Row>

<Controls />

<OptionsModal />
{width > 767 ? <Controls /> : <OptionsModal />}

<Hits />

Expand Down
85 changes: 56 additions & 29 deletions site/gatsby-site/src/components/discover/OptionsModal.js
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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 <Component key={list.attribute} attribute={list.attribute} />;
})}
</>
);
}

function OptionsModal() {
const [showModal, setShowModal] = useState(false);

const handleClose = () => setShowModal(false);

const [mounted, setMounted] = useState(false);

useEffect(() => setMounted(true), []);

return (
<div>
<div className="my-4 md:hidden flex justify-between">
Expand All @@ -33,31 +59,32 @@ function OptionsModal() {
</Button>
</div>
</div>
{mounted && (
<Modal show={showModal} onClose={handleClose}>
<Modal.Header>
<Trans>Search Options</Trans>
</Modal.Header>
<Modal.Body>
<div>
<div className="tw-options-modal-hbox">
<DisplayOptions />
<DisplayModeSwitch />
</div>
<Accordion>
{REFINEMENT_LISTS.map((list) => (
<AccordionFilter key={list.attribute} attribute={list.attribute} {...list} />
))}
</Accordion>

<VirtualFilters />

<Modal show={showModal} onClose={handleClose}>
<Modal.Header>
<Trans>Search Options</Trans>
</Modal.Header>
<Modal.Body>
<div>
<div className="tw-options-modal-hbox">
<DisplayOptions />
<DisplayModeSwitch />
</div>
</Modal.Body>
<Modal.Footer>
<Button variant="secondary" onClick={handleClose}>
<Trans>Close</Trans>
</Button>
</Modal.Footer>
</Modal>
)}
<Accordion>
{REFINEMENT_LISTS.map((list) => (
<AccordionFilter key={list.attribute} attribute={list.attribute} {...list} />
))}
</Accordion>
</div>
</Modal.Body>
<Modal.Footer>
<Button variant="secondary" onClick={handleClose}>
<Trans>Close</Trans>
</Button>
</Modal.Footer>
</Modal>
</div>
);
}
Expand Down
1 change: 1 addition & 0 deletions site/gatsby-site/src/templates/citeTemplate.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(', '),
}}
Expand Down
10 changes: 8 additions & 2 deletions site/realm/functions/processNotifications.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit 5d71605

Please sign in to comment.