Skip to content

Commit 61f5418

Browse files
committed
Fix emergency banner handling
1 parent 91ada7a commit 61f5418

File tree

3 files changed

+8
-14
lines changed

3 files changed

+8
-14
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@openstax/os-webview",
3-
"version": "2.146.0",
3+
"version": "2.146.1",
44
"description": "OpenStax webview",
55
"scripts": {
66
"test": "jest --coverage ./test/src",

src/app/layouts/default/header/sticky-note/sticky-note.tsx

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,12 @@
11
import React from 'react';
22
import RawHTML from '~/components/jsx-helpers/raw-html';
3-
import {usePutAway} from '../../shared';
3+
import {usePutAway, StickyDataWithBanner} from '../../shared';
44
import './sticky-note.scss';
55

6-
export type StickyNoteProps = {
7-
stickyData: {
8-
mode: 'emergency';
9-
emergency_content: string;
10-
} | object | null;
11-
};
12-
13-
export default function StickyNote({stickyData}: StickyNoteProps) {
6+
export default function StickyNote({stickyData}: {stickyData: StickyDataWithBanner | null}) {
147
const [closed, PutAway] = usePutAway();
158

16-
if (!stickyData || closed || !('emergency_content' in stickyData)) {
9+
if (!stickyData || closed || stickyData.mode !== 'emergency') {
1710
return null;
1811
}
1912

src/app/layouts/default/shared.tsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,12 @@ type BannerInfo = {
1515
type StickyDataRaw = {
1616
start: string;
1717
expires: string;
18-
emergency_expires: string;
18+
emergency_expires: string | null;
19+
emergency_content: string;
1920
show_popup: boolean;
2021
};
2122

22-
type StickyDataWithBanner = StickyDataRaw & {
23+
export type StickyDataWithBanner = StickyDataRaw & {
2324
bannerInfo: BannerInfo;
2425
mode: 'emergency' | 'popup' | 'banner' | null;
2526
};
@@ -62,7 +63,7 @@ function getMode(stickyData: StickyDataRaw | null): 'emergency' | 'popup' | 'ban
6263
return null;
6364
}
6465

65-
const expireDate = new Date(stickyData.emergency_expires);
66+
const expireDate = new Date(stickyData.emergency_expires ?? 0);
6667
const useEmergency = stickyData.emergency_expires && Date.now() < expireDate.getTime();
6768

6869
if (useEmergency) {

0 commit comments

Comments
 (0)