main

mattermost/focalboard

Last updated at: 29/12/2023 09:40

newVersionBanner.tsx

TLDR

This file, newVersionBanner.tsx, is a React component that displays a banner to notify users when a new version of the application is available. It uses websockets to listen for changes in the application version and triggers a reload of the page when the user clicks a link in the banner.

Methods

This file does not contain any custom methods.

Classes

This file does not contain any custom classes.

// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
import React, {useState, useEffect} from 'react'
import {FormattedMessage} from 'react-intl'

import wsClient from '../wsclient'

import './newVersionBanner.scss'

const NewVersionBanner = () => {
    const [appVersionChanged, setAppVersionChanged] = useState(false)
    useEffect(() => {
        wsClient.onAppVersionChangeHandler = setAppVersionChanged
    }, [])

    if (!appVersionChanged) {
        return null
    }

    const newVersionReload = (e: any) => {
        e.preventDefault()
        location.reload()
    }

    return (
        <div className='NewVersionBanner'>
            <a
                target='_blank'
                rel='noreferrer'
                onClick={newVersionReload}
            >
                <FormattedMessage
                    id='BoardPage.newVersion'
                    defaultMessage='A new version of Boards is available, click here to reload.'
                />
            </a>
        </div>
    )
}

export default NewVersionBanner