Move require alt-text to new persistence + context (#1839)
parent
2acc88e78d
commit
3a211017d3
|
@ -83,7 +83,6 @@ export class PreferencesModel {
|
||||||
prioritizeFollowedUsers: true,
|
prioritizeFollowedUsers: true,
|
||||||
lab_treeViewEnabled: false, // experimental
|
lab_treeViewEnabled: false, // experimental
|
||||||
}
|
}
|
||||||
requireAltTextEnabled: boolean = false
|
|
||||||
|
|
||||||
// used to help with transitions from device-stored to server-stored preferences
|
// used to help with transitions from device-stored to server-stored preferences
|
||||||
legacyPreferences: LegacyPreferences | undefined
|
legacyPreferences: LegacyPreferences | undefined
|
||||||
|
@ -111,7 +110,6 @@ export class PreferencesModel {
|
||||||
contentLabels: this.contentLabels,
|
contentLabels: this.contentLabels,
|
||||||
savedFeeds: this.savedFeeds,
|
savedFeeds: this.savedFeeds,
|
||||||
pinnedFeeds: this.pinnedFeeds,
|
pinnedFeeds: this.pinnedFeeds,
|
||||||
requireAltTextEnabled: this.requireAltTextEnabled,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -180,13 +178,6 @@ export class PreferencesModel {
|
||||||
) {
|
) {
|
||||||
this.pinnedFeeds = v.pinnedFeeds
|
this.pinnedFeeds = v.pinnedFeeds
|
||||||
}
|
}
|
||||||
// check if requiring alt text is enabled in preferences, then hydrate
|
|
||||||
if (
|
|
||||||
hasProp(v, 'requireAltTextEnabled') &&
|
|
||||||
typeof v.requireAltTextEnabled === 'boolean'
|
|
||||||
) {
|
|
||||||
this.requireAltTextEnabled = v.requireAltTextEnabled
|
|
||||||
}
|
|
||||||
// grab legacy values
|
// grab legacy values
|
||||||
this.legacyPreferences = getLegacyPreferences(v)
|
this.legacyPreferences = getLegacyPreferences(v)
|
||||||
}
|
}
|
||||||
|
@ -608,10 +599,6 @@ export class PreferencesModel {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
toggleRequireAltTextEnabled() {
|
|
||||||
this.requireAltTextEnabled = !this.requireAltTextEnabled
|
|
||||||
}
|
|
||||||
|
|
||||||
setPrimaryLanguage(lang: string) {
|
setPrimaryLanguage(lang: string) {
|
||||||
this.primaryLanguage = lang
|
this.primaryLanguage = lang
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,7 +6,7 @@ import * as store from '#/state/persisted/store'
|
||||||
import BroadcastChannel from '#/state/persisted/broadcast'
|
import BroadcastChannel from '#/state/persisted/broadcast'
|
||||||
|
|
||||||
export type {Schema} from '#/state/persisted/schema'
|
export type {Schema} from '#/state/persisted/schema'
|
||||||
export {defaults as schema} from '#/state/persisted/schema'
|
export {defaults} from '#/state/persisted/schema'
|
||||||
|
|
||||||
const broadcast = new BroadcastChannel('BSKY_BROADCAST_CHANNEL')
|
const broadcast = new BroadcastChannel('BSKY_BROADCAST_CHANNEL')
|
||||||
const UPDATE_EVENT = 'BSKY_UPDATE'
|
const UPDATE_EVENT = 'BSKY_UPDATE'
|
||||||
|
|
|
@ -0,0 +1,48 @@
|
||||||
|
import React from 'react'
|
||||||
|
import * as persisted from '#/state/persisted'
|
||||||
|
|
||||||
|
type StateContext = persisted.Schema['requireAltTextEnabled']
|
||||||
|
type SetContext = (v: persisted.Schema['requireAltTextEnabled']) => void
|
||||||
|
|
||||||
|
const stateContext = React.createContext<StateContext>(
|
||||||
|
persisted.defaults.requireAltTextEnabled,
|
||||||
|
)
|
||||||
|
const setContext = React.createContext<SetContext>(
|
||||||
|
(_: persisted.Schema['requireAltTextEnabled']) => {},
|
||||||
|
)
|
||||||
|
|
||||||
|
export function Provider({children}: React.PropsWithChildren<{}>) {
|
||||||
|
const [state, setState] = React.useState(
|
||||||
|
persisted.get('requireAltTextEnabled'),
|
||||||
|
)
|
||||||
|
|
||||||
|
const setStateWrapped = React.useCallback(
|
||||||
|
(requireAltTextEnabled: persisted.Schema['requireAltTextEnabled']) => {
|
||||||
|
setState(requireAltTextEnabled)
|
||||||
|
persisted.write('requireAltTextEnabled', requireAltTextEnabled)
|
||||||
|
},
|
||||||
|
[setState],
|
||||||
|
)
|
||||||
|
|
||||||
|
React.useEffect(() => {
|
||||||
|
return persisted.onUpdate(() => {
|
||||||
|
setState(persisted.get('requireAltTextEnabled'))
|
||||||
|
})
|
||||||
|
}, [setStateWrapped])
|
||||||
|
|
||||||
|
return (
|
||||||
|
<stateContext.Provider value={state}>
|
||||||
|
<setContext.Provider value={setStateWrapped}>
|
||||||
|
{children}
|
||||||
|
</setContext.Provider>
|
||||||
|
</stateContext.Provider>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
export function useRequireAltTextEnabled() {
|
||||||
|
return React.useContext(stateContext)
|
||||||
|
}
|
||||||
|
|
||||||
|
export function useSetRequireAltTextEnabled() {
|
||||||
|
return React.useContext(setContext)
|
||||||
|
}
|
|
@ -3,6 +3,7 @@ import {Provider as DrawerOpenProvider} from './drawer-open'
|
||||||
import {Provider as DrawerSwipableProvider} from './drawer-swipe-disabled'
|
import {Provider as DrawerSwipableProvider} from './drawer-swipe-disabled'
|
||||||
import {Provider as MinimalModeProvider} from './minimal-mode'
|
import {Provider as MinimalModeProvider} from './minimal-mode'
|
||||||
import {Provider as ColorModeProvider} from './color-mode'
|
import {Provider as ColorModeProvider} from './color-mode'
|
||||||
|
import {Provider as AltTextRequiredProvider} from './alt-text-required'
|
||||||
|
|
||||||
export {useIsDrawerOpen, useSetDrawerOpen} from './drawer-open'
|
export {useIsDrawerOpen, useSetDrawerOpen} from './drawer-open'
|
||||||
export {
|
export {
|
||||||
|
@ -11,13 +12,19 @@ export {
|
||||||
} from './drawer-swipe-disabled'
|
} from './drawer-swipe-disabled'
|
||||||
export {useMinimalShellMode, useSetMinimalShellMode} from './minimal-mode'
|
export {useMinimalShellMode, useSetMinimalShellMode} from './minimal-mode'
|
||||||
export {useColorMode, useSetColorMode} from './color-mode'
|
export {useColorMode, useSetColorMode} from './color-mode'
|
||||||
|
export {
|
||||||
|
useRequireAltTextEnabled,
|
||||||
|
useSetRequireAltTextEnabled,
|
||||||
|
} from './alt-text-required'
|
||||||
|
|
||||||
export function Provider({children}: React.PropsWithChildren<{}>) {
|
export function Provider({children}: React.PropsWithChildren<{}>) {
|
||||||
return (
|
return (
|
||||||
<DrawerOpenProvider>
|
<DrawerOpenProvider>
|
||||||
<DrawerSwipableProvider>
|
<DrawerSwipableProvider>
|
||||||
<MinimalModeProvider>
|
<MinimalModeProvider>
|
||||||
<ColorModeProvider>{children}</ColorModeProvider>
|
<ColorModeProvider>
|
||||||
|
<AltTextRequiredProvider>{children}</AltTextRequiredProvider>
|
||||||
|
</ColorModeProvider>
|
||||||
</MinimalModeProvider>
|
</MinimalModeProvider>
|
||||||
</DrawerSwipableProvider>
|
</DrawerSwipableProvider>
|
||||||
</DrawerOpenProvider>
|
</DrawerOpenProvider>
|
||||||
|
|
|
@ -49,6 +49,7 @@ import {LabelsBtn} from './labels/LabelsBtn'
|
||||||
import {SelectLangBtn} from './select-language/SelectLangBtn'
|
import {SelectLangBtn} from './select-language/SelectLangBtn'
|
||||||
import {EmojiPickerButton} from './text-input/web/EmojiPicker.web'
|
import {EmojiPickerButton} from './text-input/web/EmojiPicker.web'
|
||||||
import {insertMentionAt} from 'lib/strings/mention-manip'
|
import {insertMentionAt} from 'lib/strings/mention-manip'
|
||||||
|
import {useRequireAltTextEnabled} from '#/state/shell'
|
||||||
|
|
||||||
type Props = ComposerOpts
|
type Props = ComposerOpts
|
||||||
export const ComposePost = observer(function ComposePost({
|
export const ComposePost = observer(function ComposePost({
|
||||||
|
@ -61,6 +62,7 @@ export const ComposePost = observer(function ComposePost({
|
||||||
const pal = usePalette('default')
|
const pal = usePalette('default')
|
||||||
const {isDesktop, isMobile} = useWebMediaQueries()
|
const {isDesktop, isMobile} = useWebMediaQueries()
|
||||||
const store = useStores()
|
const store = useStores()
|
||||||
|
const requireAltTextEnabled = useRequireAltTextEnabled()
|
||||||
const textInput = useRef<TextInputRef>(null)
|
const textInput = useRef<TextInputRef>(null)
|
||||||
const [isKeyboardVisible] = useIsKeyboardVisible({iosUseWillEvents: true})
|
const [isKeyboardVisible] = useIsKeyboardVisible({iosUseWillEvents: true})
|
||||||
const [isProcessing, setIsProcessing] = useState(false)
|
const [isProcessing, setIsProcessing] = useState(false)
|
||||||
|
@ -187,7 +189,7 @@ export const ComposePost = observer(function ComposePost({
|
||||||
if (isProcessing || graphemeLength > MAX_GRAPHEME_LENGTH) {
|
if (isProcessing || graphemeLength > MAX_GRAPHEME_LENGTH) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if (store.preferences.requireAltTextEnabled && gallery.needsAltText) {
|
if (requireAltTextEnabled && gallery.needsAltText) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -241,12 +243,8 @@ export const ComposePost = observer(function ComposePost({
|
||||||
const canPost = useMemo(
|
const canPost = useMemo(
|
||||||
() =>
|
() =>
|
||||||
graphemeLength <= MAX_GRAPHEME_LENGTH &&
|
graphemeLength <= MAX_GRAPHEME_LENGTH &&
|
||||||
(!store.preferences.requireAltTextEnabled || !gallery.needsAltText),
|
(!requireAltTextEnabled || !gallery.needsAltText),
|
||||||
[
|
[graphemeLength, requireAltTextEnabled, gallery.needsAltText],
|
||||||
graphemeLength,
|
|
||||||
store.preferences.requireAltTextEnabled,
|
|
||||||
gallery.needsAltText,
|
|
||||||
],
|
|
||||||
)
|
)
|
||||||
const selectTextInputPlaceholder = replyTo ? 'Write your reply' : `What's up?`
|
const selectTextInputPlaceholder = replyTo ? 'Write your reply' : `What's up?`
|
||||||
|
|
||||||
|
@ -314,7 +312,7 @@ export const ComposePost = observer(function ComposePost({
|
||||||
</>
|
</>
|
||||||
)}
|
)}
|
||||||
</View>
|
</View>
|
||||||
{store.preferences.requireAltTextEnabled && gallery.needsAltText && (
|
{requireAltTextEnabled && gallery.needsAltText && (
|
||||||
<View style={[styles.reminderLine, pal.viewLight]}>
|
<View style={[styles.reminderLine, pal.viewLight]}>
|
||||||
<View style={styles.errorIcon}>
|
<View style={styles.errorIcon}>
|
||||||
<FontAwesomeIcon
|
<FontAwesomeIcon
|
||||||
|
|
|
@ -50,6 +50,8 @@ import {
|
||||||
useSetMinimalShellMode,
|
useSetMinimalShellMode,
|
||||||
useColorMode,
|
useColorMode,
|
||||||
useSetColorMode,
|
useSetColorMode,
|
||||||
|
useRequireAltTextEnabled,
|
||||||
|
useSetRequireAltTextEnabled,
|
||||||
} from '#/state/shell'
|
} from '#/state/shell'
|
||||||
|
|
||||||
// TEMPORARY (APP-700)
|
// TEMPORARY (APP-700)
|
||||||
|
@ -66,6 +68,8 @@ export const SettingsScreen = withAuthRequired(
|
||||||
const pal = usePalette('default')
|
const pal = usePalette('default')
|
||||||
const store = useStores()
|
const store = useStores()
|
||||||
const setMinimalShellMode = useSetMinimalShellMode()
|
const setMinimalShellMode = useSetMinimalShellMode()
|
||||||
|
const requireAltTextEnabled = useRequireAltTextEnabled()
|
||||||
|
const setRequireAltTextEnabled = useSetRequireAltTextEnabled()
|
||||||
const navigation = useNavigation<NavigationProp>()
|
const navigation = useNavigation<NavigationProp>()
|
||||||
const {isMobile} = useWebMediaQueries()
|
const {isMobile} = useWebMediaQueries()
|
||||||
const {screen, track} = useAnalytics()
|
const {screen, track} = useAnalytics()
|
||||||
|
@ -372,8 +376,8 @@ export const SettingsScreen = withAuthRequired(
|
||||||
type="default-light"
|
type="default-light"
|
||||||
label="Require alt text before posting"
|
label="Require alt text before posting"
|
||||||
labelType="lg"
|
labelType="lg"
|
||||||
isSelected={store.preferences.requireAltTextEnabled}
|
isSelected={requireAltTextEnabled}
|
||||||
onPress={store.preferences.toggleRequireAltTextEnabled}
|
onPress={() => setRequireAltTextEnabled(!requireAltTextEnabled)}
|
||||||
/>
|
/>
|
||||||
</View>
|
</View>
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue