GeezerVison is showing github.com — fix(mobile): a settings row an older environment left mixed can be se… · pingdotgg/t3code@7085c47
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboard +55Lines changed: 55 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| | 1 | +import { act, type ReactNode } from "react"; | | 2 | +import { createRoot } from "react-dom/client"; | | 3 | +import { expect, it, vi } from "vite-plus/test"; | | 4 | + | | 5 | +vi.mock("react-native", () => ({ | | 6 | + Pressable: (props: { | | 7 | + readonly children?: ReactNode; | | 8 | + readonly accessibilityLabel?: string; | | 9 | + readonly onPress: () => void; | | 10 | + }) => ( | | 11 | + <button aria-label={props.accessibilityLabel} onClick={props.onPress}> | | 12 | + {props.children} | | 13 | + </button> | | 14 | + ), | | 15 | +})); | | 16 | +vi.mock("./AppText", () => ({ AppText: (props: { children?: ReactNode }) => props.children })); | | 17 | +vi.mock("./ListRowLayout", () => ({ | | 18 | + ListRowLayout: (props: { accessory?: ReactNode }) => props.accessory, | | 19 | +})); | | 20 | +vi.mock("./ThemedSwitch", () => ({ ThemedSwitch: () => null })); | | 21 | + | | 22 | +import { ListToggleRow } from "./ListToggleRow"; | | 23 | + | | 24 | +it("sets a mixed row on, then off when an older environment drops it", () => { | | 25 | + vi.stubGlobal("IS_REACT_ACT_ENVIRONMENT", true); | | 26 | + const container = document.createElement("div"); | | 27 | + const root = createRoot(container); | | 28 | + const saves: boolean[] = []; | | 29 | + try { | | 30 | + // The older environment dropped the unknown key, so the row stays mixed after every save. | | 31 | + act(() => | | 32 | + root.render( | | 33 | + <ListToggleRow | | 34 | + label="Clone into host folders" | | 35 | + value={null} | | 36 | + onValueChange={(value) => saves.push(value)} | | 37 | + />, | | 38 | + ), | | 39 | + ); | | 40 | + const button = () => container.querySelector("button")!; | | 41 | + | | 42 | + act(() => button().click()); | | 43 | + const offer = { text: button().textContent, label: button().getAttribute("aria-label") }; | | 44 | + act(() => button().click()); | | 45 | + | | 46 | + expect(saves).toEqual([true, false]); | | 47 | + expect(offer).toEqual({ | | 48 | + text: "Mixed · Set off", | | 49 | + label: "Set Clone into host folders off for selected environments", | | 50 | + }); | | 51 | + } finally { | | 52 | + act(() => root.unmount()); | | 53 | + vi.unstubAllGlobals(); | | 54 | + } | | 55 | +}); |
Collapse file Copy file name to clipboardExpand all lines: apps/mobile/src/components/ui/ListToggleRow.tsx +18-6Lines changed: 18 additions & 6 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 1 | 1 | import { T, useGT } from "gt-react-native"; | | 2 | +import { useState } from "react"; | 2 | 3 | import { Pressable } from "react-native"; | 3 | 4 |
| 4 | 5 | import { AppText } from "./AppText"; | 5 | 6 | import { ListRowLayout, type ListRowContentProps } from "./ListRowLayout"; | 6 | 7 | import { ThemedSwitch } from "./ThemedSwitch"; | 7 | 8 |
| | 9 | +/** | | 10 | + * A mixed row flips the value last picked on it, so a pick that some environments dropped can be | | 11 | + * undone. Before any pick, it sets the value on everywhere. | | 12 | + */ | 8 | 13 | export function ListToggleRow( | 9 | 14 | props: Omit<ListRowContentProps, "detail"> & { | 10 | 15 | readonly value: boolean | null; | 11 | 16 | readonly onValueChange: (value: boolean) => void; | 12 | 17 | }, | 13 | 18 | ) { | 14 | 19 | const gt = useGT(); | | 20 | + const [picked, setPicked] = useState(false); | | 21 | + const pick = (value: boolean) => { | | 22 | + setPicked(value); | | 23 | + props.onValueChange(value); | | 24 | + }; | 15 | 25 | return ( | 16 | 26 | <ListRowLayout | 17 | 27 | icon={props.icon} | @@ -21,26 +31,28 @@ export function ListToggleRow( | 21 | 31 | accessory={ | 22 | 32 | props.value === null ? ( | 23 | 33 | <Pressable | 24 | | - accessibilityLabel={gt("Set {label} on for selected environments", { | 25 | | - label: props.label, | 26 | | - })} | | 34 | + accessibilityLabel={ | | 35 | + picked | | 36 | + ? gt("Set {label} off for selected environments", { label: props.label }) | | 37 | + : gt("Set {label} on for selected environments", { label: props.label }) | | 38 | + } | 27 | 39 | accessibilityRole="button" | 28 | 40 | accessibilityHint={props.description} | 29 | 41 | accessibilityState={{ disabled: Boolean(props.disabled) }} | 30 | 42 | disabled={props.disabled} | 31 | 43 | className="rounded-full bg-subtle px-3 py-2 active:opacity-70" | 32 | | - onPress={() => props.onValueChange(true)} | | 44 | + onPress={() => pick(!picked)} | 33 | 45 | > | 34 | 46 | <AppText className="text-sm font-t3-medium text-foreground"> | 35 | | - <T>Mixed · Set on</T> | | 47 | + {picked ? <T>Mixed · Set off</T> : <T>Mixed · Set on</T>} | 36 | 48 | </AppText> | 37 | 49 | </Pressable> | 38 | 50 | ) : ( | 39 | 51 | <ThemedSwitch | 40 | 52 | accessibilityLabel={props.label} | 41 | 53 | accessibilityHint={props.description} | 42 | 54 | disabled={props.disabled} | 43 | | - onValueChange={props.onValueChange} | | 55 | + onValueChange={pick} | 44 | 56 | value={props.value} | 45 | 57 | /> | 46 | 58 | ) | |
Collapse file Copy file name to clipboardExpand all lines: apps/mobile/src/i18n/translations/de.json +2Lines changed: 2 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 1712 | 1712 | "0efe7ba6d7f681f1": "Verbinde dich erneut mit dieser Umgebung und versuch es noch einmal. Die Datei wurde möglicherweise verschoben oder gelöscht.", | 1713 | 1713 | "2b29584d2bcea749": "Die Datei wurde unter {path} nicht gefunden.", | 1714 | 1714 | "61026d122846876c": "Hänge die Datei erneut an und versuch es noch einmal.", | | 1715 | + "d0872cb98b34eae8": "{label} für ausgewählte Umgebungen ausschalten", | 1715 | 1716 | "a9129aaa7c955e46": "{label} für ausgewählte Umgebungen einschalten", | | 1717 | + "53207498f814efe0": "Gemischt · Ausschalten", | 1716 | 1718 | "fd569def3acc6750": "Gemischt · Einschalten", | 1717 | 1719 | "8eebcd051255ba20": "Nachricht schließen", | 1718 | 1720 | "8711a1de99862971": "{label} verringern", | |
Collapse file Copy file name to clipboardExpand all lines: apps/mobile/src/i18n/translations/en.json +2Lines changed: 2 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 1712 | 1712 | "0efe7ba6d7f681f1": "Reconnect to this environment and try again. The file may have been moved or deleted.", | 1713 | 1713 | "2b29584d2bcea749": "The file was not found at {path}.", | 1714 | 1714 | "61026d122846876c": "Attach the file again and retry.", | | 1715 | + "d0872cb98b34eae8": "Set {label} off for selected environments", | 1715 | 1716 | "a9129aaa7c955e46": "Set {label} on for selected environments", | | 1717 | + "53207498f814efe0": "Mixed · Set off", | 1716 | 1718 | "fd569def3acc6750": "Mixed · Set on", | 1717 | 1719 | "8eebcd051255ba20": "Dismiss message", | 1718 | 1720 | "8711a1de99862971": "Decrease {label}", | |
Collapse file Copy file name to clipboardExpand all lines: apps/mobile/src/i18n/translations/es.json +2Lines changed: 2 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 1712 | 1712 | "0efe7ba6d7f681f1": "Vuelve a conectarte a este entorno e inténtalo de nuevo. Puede que el archivo se haya movido o eliminado.", | 1713 | 1713 | "2b29584d2bcea749": "No se encontró el archivo en {path}.", | 1714 | 1714 | "61026d122846876c": "Vuelve a adjuntar el archivo y reinténtalo.", | | 1715 | + "d0872cb98b34eae8": "Desactivar {label} en los entornos seleccionados", | 1715 | 1716 | "a9129aaa7c955e46": "Activar {label} en los entornos seleccionados", | | 1717 | + "53207498f814efe0": "Mixto · Desactivar", | 1716 | 1718 | "fd569def3acc6750": "Mixto · Activar", | 1717 | 1719 | "8eebcd051255ba20": "Descartar mensaje", | 1718 | 1720 | "8711a1de99862971": "Reducir {label}", | |
Collapse file Copy file name to clipboardExpand all lines: apps/mobile/src/i18n/translations/fr.json +2Lines changed: 2 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 1712 | 1712 | "0efe7ba6d7f681f1": "Reconnectez-vous à cet environnement et réessayez. Le fichier a peut-être été déplacé ou supprimé.", | 1713 | 1713 | "2b29584d2bcea749": "Le fichier est introuvable dans {path}.", | 1714 | 1714 | "61026d122846876c": "Joignez à nouveau le fichier et réessayez.", | | 1715 | + "d0872cb98b34eae8": "Désactiver {label} pour les environnements sélectionnés", | 1715 | 1716 | "a9129aaa7c955e46": "Activer {label} pour les environnements sélectionnés", | | 1717 | + "53207498f814efe0": "Mixte · Désactiver", | 1716 | 1718 | "fd569def3acc6750": "Mixte · Activer", | 1717 | 1719 | "8eebcd051255ba20": "Ignorer le message", | 1718 | 1720 | "8711a1de99862971": "Diminuer {label}", | |
Collapse file Copy file name to clipboardExpand all lines: apps/mobile/src/i18n/translations/ja.json +2Lines changed: 2 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 1712 | 1712 | "0efe7ba6d7f681f1": "この環境に再接続して、もう一度お試しください。ファイルが移動または削除された可能性があります。", | 1713 | 1713 | "2b29584d2bcea749": "{path} にファイルが見つかりませんでした。", | 1714 | 1714 | "61026d122846876c": "ファイルをもう一度添付して再試行してください。", | | 1715 | + "d0872cb98b34eae8": "選択した環境で {label} をオフにする", | 1715 | 1716 | "a9129aaa7c955e46": "選択した環境で {label} をオンにする", | | 1717 | + "53207498f814efe0": "混在 · オフにする", | 1716 | 1718 | "fd569def3acc6750": "混在 · オンにする", | 1717 | 1719 | "8eebcd051255ba20": "メッセージを閉じる", | 1718 | 1720 | "8711a1de99862971": "{label} を減らす", | |
Collapse file Copy file name to clipboardExpand all lines: apps/mobile/src/i18n/translations/ko.json +2Lines changed: 2 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 1712 | 1712 | "0efe7ba6d7f681f1": "이 환경에 다시 연결한 뒤 시도하세요. 파일이 이동되었거나 삭제되었을 수 있습니다.", | 1713 | 1713 | "2b29584d2bcea749": "{path}에서 파일을 찾을 수 없습니다.", | 1714 | 1714 | "61026d122846876c": "파일을 다시 첨부한 뒤 다시 시도하세요.", | | 1715 | + "d0872cb98b34eae8": "선택한 환경에서 {label} 끄기", | 1715 | 1716 | "a9129aaa7c955e46": "선택한 환경에서 {label} 켜기", | | 1717 | + "53207498f814efe0": "혼합 · 끄기", | 1716 | 1718 | "fd569def3acc6750": "혼합 · 켜기", | 1717 | 1719 | "8eebcd051255ba20": "메시지 닫기", | 1718 | 1720 | "8711a1de99862971": "{label} 줄이기", | |
Collapse file Copy file name to clipboardExpand all lines: apps/mobile/src/i18n/translations/pt-BR.json +2Lines changed: 2 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 1712 | 1712 | "0efe7ba6d7f681f1": "Reconecte a este ambiente e tente novamente. O arquivo pode ter sido movido ou excluído.", | 1713 | 1713 | "2b29584d2bcea749": "O arquivo não foi encontrado em {path}.", | 1714 | 1714 | "61026d122846876c": "Anexe o arquivo novamente e tente de novo.", | | 1715 | + "d0872cb98b34eae8": "Desativar {label} nos ambientes selecionados", | 1715 | 1716 | "a9129aaa7c955e46": "Ativar {label} nos ambientes selecionados", | | 1717 | + "53207498f814efe0": "Misto · Desativar", | 1716 | 1718 | "fd569def3acc6750": "Misto · Ativar", | 1717 | 1719 | "8eebcd051255ba20": "Dispensar mensagem", | 1718 | 1720 | "8711a1de99862971": "Diminuir {label}", | |
Collapse file Copy file name to clipboardExpand all lines: apps/mobile/src/i18n/translations/ru.json +2Lines changed: 2 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 1712 | 1712 | "0efe7ba6d7f681f1": "Переподключитесь к этому окружению и попробуйте снова. Возможно, файл перемещён или удалён.", | 1713 | 1713 | "2b29584d2bcea749": "Файл не найден по пути {path}.", | 1714 | 1714 | "61026d122846876c": "Прикрепите файл снова и повторите.", | | 1715 | + "d0872cb98b34eae8": "Выключить {label} для выбранных окружений", | 1715 | 1716 | "a9129aaa7c955e46": "Включить {label} для выбранных окружений", | | 1717 | + "53207498f814efe0": "По-разному · Выключить", | 1716 | 1718 | "fd569def3acc6750": "По-разному · Включить", | 1717 | 1719 | "8eebcd051255ba20": "Скрыть сообщение", | 1718 | 1720 | "8711a1de99862971": "Уменьшить {label}", | |
|