Skip to content

Commit

Permalink
Re-enable outdated version warning, remove warning when version is ch…
Browse files Browse the repository at this point in the history
…anged back to latest
  • Loading branch information
reglim committed Sep 6, 2023
1 parent 76b3e23 commit 04cdd19
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 1 deletion.
18 changes: 17 additions & 1 deletion web/src/data-providers/MessageBannerProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,15 @@ export interface Message {

interface MessageBannerState {
showMessage: (message: Message) => void
clearMessages: () => void
}

export const Context = React.createContext<MessageBannerState>({
showMessage: (): void => {
console.warn('MessageBannerProvider not initialized')
},
clearMessages: (): void => {
console.warn('MessageBannerProvider not initialized')
}
})

Expand Down Expand Up @@ -59,8 +63,20 @@ export function MessageBannerProvider ({ children }: any): JSX.Element {
setLastTimeout(newTimeout)
}, [])

const clearMessages = useCallback(() => {
if (lastTimeout !== undefined) {
clearTimeout(lastTimeout)
}

setMessage({
content: undefined,
type: 'success',
showMs: 6000
})
}, [])

return (
<Context.Provider value={{ showMessage }}>
<Context.Provider value={{ showMessage, clearMessages }}>
<Banner message={message} />
{children}
</Context.Provider>
Expand Down
22 changes: 22 additions & 0 deletions web/src/pages/Docs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@ import NotFound from './NotFound'
import DocumentControlButtons from '../components/DocumentControlButtons'
import IFrame from '../components/IFrame'
import { useLocation, useParams, useSearchParams } from 'react-router-dom'
import { useMessageBanner } from '../data-providers/MessageBannerProvider'

export default function Docs (): JSX.Element {
const params = useParams()
const searchParams = useSearchParams()[0]
const location = useLocation()
const { showMessage, clearMessages } = useMessageBanner()

const [versions, setVersions] = useState<ProjectDetails[]>([])
const [loadingFailed, setLoadingFailed] = useState<boolean>(false)
Expand Down Expand Up @@ -149,6 +151,26 @@ export default function Docs (): JSX.Element {
}
}, [location])

useEffect(() => {
// check every time the version changes whether the version
// is the latest version and if not, show a banner
if (versions.length === 0) {
return
}

const latestVersion = ProjectRepository.getLatestVersion(versions).name
if (version === latestVersion) {
clearMessages()
return
}

showMessage({
content: 'You are viewing an outdated version of the documentation.',
type: 'warning',
showMs: null
})
}, [version, versions])

if (loadingFailed || project.current === '') {
return <NotFound />
}
Expand Down

0 comments on commit 04cdd19

Please sign in to comment.