Skip to content

Commit

Permalink
temp:(banner)
Browse files Browse the repository at this point in the history
  • Loading branch information
esinx committed Oct 14, 2023
1 parent caf576f commit 877551a
Show file tree
Hide file tree
Showing 2 changed files with 224 additions and 0 deletions.
211 changes: 211 additions & 0 deletions frontend/components/Announcement.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,211 @@
import { useEffect, useRef, useState } from 'react'

const issueIcon =
'data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMjUiIGhlaWdodD0iMjQiIHZpZXdCb3g9IjAgMCAyNSAyNCIgZmlsbD0ibm9uZSIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIj4KICAgIDxwYXRoCiAgICAgICAgZD0iTTI0LjY0MjggMTkuMDc2N0wxNC44ODMyIDEuOTQyODFDMTQuNjM5NCAxLjUyMzA0IDE0LjI5MTIgMS4xNzQ5OSAxMy44NzMzIDAuOTMzMTQ5QzEzLjQ1NTMgMC42OTEzMTEgMTIuOTgyMSAwLjU2NDA4NyAxMi41MDA2IDAuNTY0MDg3QzEyLjAxOSAwLjU2NDA4NyAxMS41NDU4IDAuNjkxMzExIDExLjEyNzkgMC45MzMxNDlDMTAuNzA5OSAxLjE3NDk5IDEwLjM2MTcgMS41MjMwNCAxMC4xMTc5IDEuOTQyODFMMC4zNTgzMjIgMTkuMDc2N0MwLjEyMzY2NCAxOS40ODI3IDAgMTkuOTQ0NSAwIDIwLjQxNDdDMCAyMC44ODUgMC4xMjM2NjQgMjEuMzQ2OCAwLjM1ODMyMiAyMS43NTI4QzAuNTk5MDggMjIuMTc1MSAwLjk0NjY1MSAyMi41MjUgMS4zNjUzNyAyMi43NjY3QzEuNzg0MDkgMjMuMDA4NCAyLjI1ODg4IDIzLjEzMzEgMi43NDEwMSAyMy4xMjhIMjIuMjYwMUMyMi43NDE5IDIzLjEzMjcgMjMuMjE2MiAyMy4wMDc4IDIzLjYzNDUgMjIuNzY2MUMyNC4wNTI4IDIyLjUyNDUgMjQuN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CA2LjkwNzgxTDEuNTYwNCAxMC44MjY5QzEuMzg2ODggMTAuOTg4MSAxLjE1NzUyIDExLjA3NTggMC45MjA1MTIgMTEuMDcxN0MwLjY4MzUwNSAxMS4wNjc2IDAuNDU3MzE1IDEwLjk3MiAwLjI4OTQ4MSAxMC44MDVDMC4xMjIwODcgMTAuNjM3NSAwLjAyNjI3MzggMTAuNDExOCAwLjAyMjE3OTcgMTAuMTc1M0MwLjAxODA4NTUgOS45Mzg3OSAwLjEwNjAyOSA5LjcwOTkxIDAuMjY3NTI3IDkuNTM2NzdMNC4xOTQ5MyA1LjYxNzY3TDAuMjY3NTI3IDEuNjk4NTdDMC4wOTYyMjA5IDEuNTI3NDIgMCAxLjI5NTQxIDAgMS4wNTM1QzAgMC44MTE2MDMgMC4wOTYyMjA5IDAuNTc5NTkzIDAuMjY3NTI3IDAuNDA4NDM2WiIKICAgICAgICBmaWxsPSIjQkFCQUJBIiAvPgo8L3N2Zz4KICAgIA=='

export interface AnnouncementProps {
type: 'issue' | 'notice'
title?: string
// message: string
}

const COLORS = {
issue: '#EF4B5F',
notice: '#209CEE',
}

const useDismiss = (key: string) => {
const dismissKey = `dismissed-${key}`
const [dismissed, setDismissed] = useState(() => true)
useEffect(() => {
setDismissed(window.localStorage.getItem(dismissKey) === 'true')
}, [])
const dismiss = () => {
window.localStorage.setItem(dismissKey, 'true')
setDismissed(true)
}
return { dismissed, dismiss }
}

const useIsClamped = (ref: React.RefObject<HTMLElement>) => {
const [isClamped, setIsClamped] = useState(false)

useEffect(() => {
const handleResize = () => {
if (!ref.current) {
return
}
const { clientHeight, scrollHeight } = ref.current
setIsClamped(clientHeight < scrollHeight)
}
handleResize()
window.addEventListener('resize', handleResize)
return () => window.removeEventListener('resize', handleResize)
}, [ref])

return isClamped
}

/**
*
* Temporary hard-coded announcement banner for maintenance (231014)
*/
export const Announcement: React.FC<AnnouncementProps> = ({
type,
title,
// message,
}) => {
const { dismissed, dismiss } = useDismiss(
`org.pennlabs.announcements.outage.231014`,
)
const textRef = useRef<HTMLDivElement>(null)
const isClamped = useIsClamped(textRef)
const [expanded, setExpanded] = useState(false)

const icon = type === 'issue' ? issueIcon : infoIcon

if (dismissed) return null

return (
<>
<style jsx>
{`
.announcement-text {
font-size: 18px;
display: -webkit-box;
overflow: hidden;
}
@media (max-width: 768px) {
.announcement-text {
font-size: 16px;
-webkit-line-clamp: ${expanded ? 'unset' : 2};
-webkit-box-orient: vertical;
}
}
`}
</style>
<div
style={{
fontFamily: `BlinkMacSystemFont, -apple-system, Segoe UI, Roboto, Oxygen, Ubuntu, Cantarell, Fira Sans, Droid Sans, Helvetica Neue, Helvetica, Arial, sans-serif`,
display: `flex`,
overflow: `hidden`,
borderRadius: `8px`,
border: `1px solid ${COLORS[type]}`,
backgroundColor: `#fff`,
}}
>
<div
style={{
display: 'flex',
alignItems: 'center',
justifyContent: 'center',
width: '32px',
backgroundColor: COLORS[type],
}}
>
<img
src={icon}
style={{
width: '20px',
height: '20px',
transform: 'translate3d(0, -3px, 0)',
}}
/>
</div>
<div
style={{
flex: 1,
display: 'flex',
padding: '16px 8px 16px 16px',
boxSizing: 'border-box',
}}
>
<div
style={{
flex: 1,
}}
ref={textRef}
>
{title && (
<div
style={{
fontWeight: 600,
padding: '8px 12px',
color: COLORS[type],
}}
>
{title}
</div>
)}
<div className="announcement-text">
🔧 We're performing essential maintenance over Fall Break weekend.
Please expect possible service interruptions until Sunday. We
greatly appreciate your understanding.{' '}
<a
href="mailto:[email protected]"
style={{
color: COLORS[type],
marginRight: '4px',
}}
>
Contact us
</a>{' '}
for assistance.
</div>
{isClamped && (
<div
style={{
display: 'flex',
alignItems: 'center',
justifyContent: 'flex-end',
padding: '4px 12px',
}}
>
<button
style={{
backgroundColor: 'transparent',
border: 'none',
color: COLORS[type],
cursor: 'pointer',
fontSize: '14px',
fontWeight: 600,
padding: 0,
margin: 0,
textDecoration: 'underline',
}}
onClick={() => setExpanded(true)}
>
Read more
</button>
</div>
)}
</div>
<div>
<button
style={{
backgroundColor: 'transparent',
border: 'none',
cursor: 'pointer',
padding: '8px',
margin: 0,
}}
onClick={dismiss}
>
<img
src={closeIcon}
style={{
width: '16px',
height: '16px',
}}
/>
</button>
</div>
</div>
</div>
</>
)
}
13 changes: 13 additions & 0 deletions frontend/pages/_app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,26 @@ import 'react-toastify/dist/ReactToastify.min.css'
import { AppProps } from 'next/app'
import { ReactElement } from 'react'

import { Announcement } from '~/components/Announcement'
import RouteProgressBar from '~/components/RouteProgressBar'

const App = ({ Component, pageProps }: AppProps): ReactElement => {
return (
<>
<Component {...pageProps} />
<RouteProgressBar />
<div
style={{
zIndex: 10000,
position: 'fixed',
top: 0,
left: 0,
right: 0,
padding: 20,
}}
>
<Announcement type="issue" title="Weekend Maintenance Alert" />
</div>
</>
)
}
Expand Down

0 comments on commit 877551a

Please sign in to comment.