Skip to content

Commit d474710

Browse files
committed
FIx wrong publications on page switch
This patch fixes a bug that happened when switching pages in the events table. Events that had no publication would be displayed as having publications, if the event in its place on the previous page had publications. For example, if the first event on page 1 had publications, and then you would switch to page 2 where the first event did not have publications, the event would be displayed as having publications. This patch fixes that by firstly resetting publication information if the information changes. It also limits enriching to only happen if the publications have changed.
1 parent ffde25b commit d474710

1 file changed

Lines changed: 9 additions & 2 deletions

File tree

src/components/events/partials/PublishedCell.tsx

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ const PublishCell = ({
2626
const [showPopup, setShowPopup] = useState(false);
2727

2828
useEffect(() => {
29-
// Enrich publications every time the row updates
29+
// Enrich publications
3030
const fetchPublications = async() => {
3131
if (!!row.publications && row.publications.length > 0) {
3232
let transformedPublications: Publication[] = [];
@@ -39,8 +39,15 @@ const PublishCell = ({
3939
setPublications(transformedPublications);
4040
}
4141
}
42+
43+
// Reset publications. This is to immediately update the table on page switch.
44+
setPublications(row.publications);
45+
// Enrich publications. It is ok if this is not immediate.
4246
fetchPublications();
43-
}, [dispatch, row]);
47+
// Only update if the publications have actually changed by fake deep checking with JSON.stringify
48+
// This should be acceptable for our simple and small publication objects
49+
// eslint-disable-next-line react-hooks/exhaustive-deps
50+
}, [dispatch, JSON.stringify(row.publications)]);
4451

4552
useEffect(() => {
4653
// Function for handling clicks outside of popup

0 commit comments

Comments
 (0)