Improve the language behaviors around the PWI (#3545)

* Handle leftnav overflow with longer languages' copy

* Update the language dropdown to set ALL language prefs

* Add hackfix to language cachebusting on PWI

* Reset feeds on language change
This commit is contained in:
Paul Frazee 2024-04-13 19:49:52 -07:00 committed by GitHub
parent 23056daa29
commit 0b43d728e4
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 111 additions and 14 deletions

View file

@ -1,6 +1,7 @@
import React from 'react'
import * as persisted from '#/state/persisted'
import {AppLanguage} from '#/locale/languages'
import * as persisted from '#/state/persisted'
type SetStateCb = (
s: persisted.Schema['languagePrefs'],
@ -9,6 +10,7 @@ type StateContext = persisted.Schema['languagePrefs']
type ApiContext = {
setPrimaryLanguage: (code2: string) => void
setPostLanguage: (commaSeparatedLangCodes: string) => void
setContentLanguage: (code2: string) => void
toggleContentLanguage: (code2: string) => void
togglePostLanguage: (code2: string) => void
savePostLanguageToHistory: () => void
@ -21,6 +23,7 @@ const stateContext = React.createContext<StateContext>(
const apiContext = React.createContext<ApiContext>({
setPrimaryLanguage: (_: string) => {},
setPostLanguage: (_: string) => {},
setContentLanguage: (_: string) => {},
toggleContentLanguage: (_: string) => {},
togglePostLanguage: (_: string) => {},
savePostLanguageToHistory: () => {},
@ -53,6 +56,9 @@ export function Provider({children}: React.PropsWithChildren<{}>) {
setPostLanguage(commaSeparatedLangCodes: string) {
setStateWrapped(s => ({...s, postLanguage: commaSeparatedLangCodes}))
},
setContentLanguage(code2: string) {
setStateWrapped(s => ({...s, contentLanguages: [code2]}))
},
toggleContentLanguage(code2: string) {
setStateWrapped(s => {
const exists = s.contentLanguages.includes(code2)