|
1 | | -import React, { useCallback } from 'react'; |
| 1 | +import React, { useCallback, useEffect, useState } from 'react'; |
2 | 2 | import styled from 'styled-components'; |
3 | 3 | import { useTranslation } from 'react-i18next'; |
4 | 4 | import { useDispatch } from 'react-redux'; |
@@ -29,21 +29,51 @@ const VersionPickerButton = styled.button` |
29 | 29 | } |
30 | 30 | `; |
31 | 31 |
|
| 32 | +const NotificationDot = styled.div` |
| 33 | + display: inline-block; |
| 34 | + vertical-align: top; |
| 35 | + border-radius: 50%; |
| 36 | + width: 0.7rem; |
| 37 | + height: 0.7rem; |
| 38 | + background-color: ${prop('colors.dodgerblue')}; |
| 39 | + margin-left: 0.25rem; |
| 40 | +`; |
| 41 | + |
| 42 | +const CLICKED_LIBRARY_VERSION_KEY = 'clickedLibraryVersionIndicator'; |
| 43 | + |
32 | 44 | const VersionIndicator = () => { |
33 | 45 | const { versionInfo } = useP5Version(); |
34 | 46 | const { t } = useTranslation(); |
35 | 47 | const dispatch = useDispatch(); |
| 48 | + const [showNotificationDot, setShowNotificationDot] = useState(false); |
| 49 | + |
| 50 | + useEffect(() => { |
| 51 | + const hasHiddenDot = window.localStorage.getItem( |
| 52 | + CLICKED_LIBRARY_VERSION_KEY |
| 53 | + ); |
| 54 | + setShowNotificationDot(!hasHiddenDot); |
| 55 | + }, []); |
36 | 56 |
|
37 | 57 | const openVersionSettings = useCallback(() => { |
38 | 58 | dispatch(openPreferences()); |
39 | 59 | dispatch(setPreferencesTab(2)); |
| 60 | + setShowNotificationDot(false); |
| 61 | + window.localStorage.setItem(CLICKED_LIBRARY_VERSION_KEY, true); |
40 | 62 | }, []); |
41 | 63 |
|
| 64 | + const label = t('Toolbar.LibraryVersion'); |
| 65 | + const currentVersion = |
| 66 | + versionInfo?.version || t('Toolbar.CustomLibraryVersion'); |
| 67 | + let ariaLabel = `${label}: ${currentVersion}`; |
| 68 | + if (showNotificationDot) { |
| 69 | + ariaLabel = `${t('Toolbar.Notification')} - ${ariaLabel}`; |
| 70 | + } |
| 71 | + |
42 | 72 | return ( |
43 | | - <VersionPickerButton onClick={openVersionSettings}> |
44 | | - {t('Toolbar.LibraryVersion')} |
45 | | - |
46 | | - {versionInfo?.version || t('Toolbar.CustomLibraryVersion')} |
| 73 | + <VersionPickerButton onClick={openVersionSettings} ariaLabel={ariaLabel}> |
| 74 | + {label}: |
| 75 | + {currentVersion} |
| 76 | + {showNotificationDot && <NotificationDot />} |
47 | 77 | <EditIcon focusable="false" aria-hidden="true" /> |
48 | 78 | </VersionPickerButton> |
49 | 79 | ); |
|
0 commit comments