Skip to content

Commit 038833c

Browse files
authored
feat(app): add support for pinyin layout candidates in ODD keyboard (#16873)
fix EXEC-885
1 parent 015e182 commit 038833c

File tree

9 files changed

+84
-7
lines changed

9 files changed

+84
-7
lines changed

app/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@
6363
"reselect": "4.0.0",
6464
"rxjs": "^6.5.1",
6565
"semver": "5.7.2",
66+
"simple-keyboard-layouts": "3.4.41",
6667
"styled-components": "5.3.6",
6768
"typeface-open-sans": "0.0.75",
6869
"uuid": "3.2.1"

app/src/atoms/SoftwareKeyboard/AlphanumericKeyboard/index.css

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,3 +68,12 @@ the rest is the same */
6868
height: 44.75px;
6969
width: 330px !important;
7070
}
71+
72+
.hg-candidate-box {
73+
max-width: 400px;
74+
}
75+
76+
li.hg-candidate-box-list-item {
77+
height: 60px;
78+
width: 60px;
79+
}

app/src/atoms/SoftwareKeyboard/AlphanumericKeyboard/index.tsx

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
import * as React from 'react'
22
import Keyboard from 'react-simple-keyboard'
3-
import { alphanumericKeyboardLayout, customDisplay } from '../constants'
3+
import { useSelector } from 'react-redux'
4+
import { getAppLanguage } from '/app/redux/config'
5+
import {
6+
alphanumericKeyboardLayout,
7+
layoutCandidates,
8+
customDisplay,
9+
} from '../constants'
410
import type { KeyboardReactInterface } from 'react-simple-keyboard'
511

612
import '../index.css'
@@ -19,6 +25,7 @@ export function AlphanumericKeyboard({
1925
debug = false, // If true, <ENTER> will input a \n
2026
}: AlphanumericKeyboardProps): JSX.Element {
2127
const [layoutName, setLayoutName] = React.useState<string>('default')
28+
const appLanguage = useSelector(getAppLanguage)
2229
const onKeyPress = (button: string): void => {
2330
if (button === '{ABC}') handleShift()
2431
if (button === '{numbers}') handleNumber()
@@ -47,6 +54,9 @@ export function AlphanumericKeyboard({
4754
onKeyPress={onKeyPress}
4855
layoutName={layoutName}
4956
layout={alphanumericKeyboardLayout}
57+
layoutCandidates={
58+
appLanguage != null ? layoutCandidates[appLanguage] : undefined
59+
}
5060
display={customDisplay}
5161
mergeDisplay={true}
5262
useButtonTag={true}

app/src/atoms/SoftwareKeyboard/FullKeyboard/index.css

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,3 +103,12 @@
103103
color: #16212d;
104104
background-color: #e3e3e3; /* grey30 */
105105
}
106+
107+
.hg-candidate-box {
108+
max-width: 400px;
109+
}
110+
111+
li.hg-candidate-box-list-item {
112+
height: 60px;
113+
width: 60px;
114+
}

app/src/atoms/SoftwareKeyboard/FullKeyboard/index.tsx

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
import * as React from 'react'
22
import { KeyboardReact as Keyboard } from 'react-simple-keyboard'
3-
import { customDisplay, fullKeyboardLayout } from '../constants'
3+
import { useSelector } from 'react-redux'
4+
import { getAppLanguage } from '/app/redux/config'
5+
import {
6+
customDisplay,
7+
layoutCandidates,
8+
fullKeyboardLayout,
9+
} from '../constants'
410
import type { KeyboardReactInterface } from 'react-simple-keyboard'
511

612
import '../index.css'
@@ -19,6 +25,7 @@ export function FullKeyboard({
1925
debug = false,
2026
}: FullKeyboardProps): JSX.Element {
2127
const [layoutName, setLayoutName] = React.useState<string>('default')
28+
const appLanguage = useSelector(getAppLanguage)
2229
const handleShift = (button: string): void => {
2330
switch (button) {
2431
case '{shift}':
@@ -56,6 +63,9 @@ export function FullKeyboard({
5663
onKeyPress={onKeyPress}
5764
layoutName={layoutName}
5865
layout={fullKeyboardLayout}
66+
layoutCandidates={
67+
appLanguage != null ? layoutCandidates[appLanguage] : undefined
68+
}
5969
display={customDisplay}
6070
mergeDisplay={true}
6171
useButtonTag={true}

app/src/atoms/SoftwareKeyboard/constants.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
import chineseLayout from 'simple-keyboard-layouts/build/layouts/chinese'
2+
3+
type LayoutCandidates =
4+
| {
5+
[key: string]: string
6+
}
7+
| undefined
8+
19
export const customDisplay = {
210
'{numbers}': '123',
311
'{shift}': 'ABC',
@@ -69,3 +77,12 @@ export const numericalKeyboardLayout = {
6977
export const numericalCustom = {
7078
'{backspace}': 'del',
7179
}
80+
81+
export const layoutCandidates: {
82+
[key: string]: LayoutCandidates
83+
} = {
84+
// @ts-expect-error layout candidates exists but is not on the type
85+
// in the simple-keyboard-layouts package
86+
'zh-CN': chineseLayout.layoutCandidates,
87+
'en-US': undefined,
88+
}

app/src/organisms/Desktop/SystemLanguagePreferenceModal/__tests__/SystemLanguagePreferenceModal.test.tsx

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,4 +180,16 @@ describe('SystemLanguagePreferenceModal', () => {
180180
'zh-Hant'
181181
)
182182
})
183+
184+
it('should not open update modal when system language changes to an unsuppported language', () => {
185+
vi.mocked(getSystemLanguage).mockReturnValue('es-MX')
186+
render()
187+
188+
expect(screen.queryByRole('button', { name: 'Don’t change' })).toBeNull()
189+
expect(
190+
screen.queryByRole('button', {
191+
name: 'Use system language',
192+
})
193+
).toBeNull()
194+
})
183195
})

app/src/organisms/Desktop/SystemLanguagePreferenceModal/index.tsx

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,7 @@ export function SystemLanguagePreferenceModal(): JSX.Element | null {
4646
const storedSystemLanguage = useSelector(getStoredSystemLanguage)
4747

4848
const showBootModal = appLanguage == null && systemLanguage != null
49-
const showUpdateModal =
50-
appLanguage != null &&
51-
systemLanguage != null &&
52-
storedSystemLanguage != null &&
53-
systemLanguage !== storedSystemLanguage
49+
const [showUpdateModal, setShowUpdateModal] = useState(false)
5450

5551
const title = showUpdateModal
5652
? t('system_language_preferences_update')
@@ -120,6 +116,13 @@ export function SystemLanguagePreferenceModal(): JSX.Element | null {
120116
void i18n.changeLanguage(systemLanguage)
121117
}
122118
}
119+
// only show update modal if we support the language their system has updated to
120+
setShowUpdateModal(
121+
appLanguage != null &&
122+
matchedSystemLanguageOption != null &&
123+
storedSystemLanguage != null &&
124+
systemLanguage !== storedSystemLanguage
125+
)
123126
}
124127
}, [i18n, systemLanguage, showBootModal])
125128

yarn.lock

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3403,6 +3403,7 @@
34033403
reselect "4.0.0"
34043404
rxjs "^6.5.1"
34053405
semver "5.7.2"
3406+
simple-keyboard-layouts "3.4.41"
34063407
styled-components "5.3.6"
34073408
typeface-open-sans "0.0.75"
34083409
uuid "3.2.1"
@@ -20041,6 +20042,11 @@ simple-git@^3.15.1:
2004120042
"@kwsites/promise-deferred" "^1.1.1"
2004220043
debug "^4.3.4"
2004320044

20045+
20046+
version "3.4.41"
20047+
resolved "https://registry.yarnpkg.com/simple-keyboard-layouts/-/simple-keyboard-layouts-3.4.41.tgz#eb1504c36626f29b0d5590d419ab39c43d06969a"
20048+
integrity sha512-vVnPRgZmK9DqbqUxOgZesdAlWkzY1Cvxf8YaFW3SHJHQKuvCkR8VL6TjJyrpM8BkJa3W4ry1i3CsSydlPckAoQ==
20049+
2004420050
simple-swizzle@^0.2.2:
2004520051
version "0.2.2"
2004620052
resolved "https://registry.yarnpkg.com/simple-swizzle/-/simple-swizzle-0.2.2.tgz#a4da6b635ffcccca33f70d17cb92592de95e557a"

0 commit comments

Comments
 (0)