()
| 37 | } |
| 38 | |
| 39 | export const PlatformPicker = () => { |
| 40 | const { defaultPlatform, detectedPlatforms } = useArticleContext() |
| 41 | |
| 42 | const [defaultUA, setDefaultUA] = useState('') |
| 43 | useEffect(() => { |
| 44 | let userAgent = parseUserAgent().os |
| 45 | if (userAgent === 'ios') { |
| 46 | userAgent = 'mac' |
| 47 | } |
| 48 | setDefaultUA(userAgent) |
| 49 | }, []) |
| 50 | |
| 51 | // Defensively, just in case some article happens to have an array |
| 52 | // but for some reasons, it might be empty, let's not have a picker |
| 53 | // at all. |
| 54 | if (!detectedPlatforms.length) return null |
| 55 | |
| 56 | const options = platforms.filter((platform) => detectedPlatforms.includes(platform.value)) |
| 57 | |
| 58 | return ( |
| 59 | <InArticlePicker |
| 60 | defaultValue={defaultPlatform} |
| 61 | fallbackValue={ |
| 62 | detectedPlatforms.includes(defaultUA) |
| 63 | ? defaultUA |
| 64 | : detectedPlatforms[detectedPlatforms.length - 1] |
| 65 | } |
| 66 | cookieKey="osPreferred" |
| 67 | queryStringKey={platformQueryKey} |
| 68 | onValue={showPlatformSpecificContent} |
| 69 | preferenceName="os" |
| 70 | ariaLabel="Platform" |
| 71 | options={options} |
| 72 | /> |
| 73 | ) |
| 74 | } |
nothing calls this directly
no test coverage detected