Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(app): add support for pinyin layout candidates in ODD keyboard #16873

Merged
merged 4 commits into from
Nov 22, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@
"reselect": "4.0.0",
"rxjs": "^6.5.1",
"semver": "5.7.2",
"simple-keyboard-layouts": "3.4.41",
"styled-components": "5.3.6",
"typeface-open-sans": "0.0.75",
"uuid": "3.2.1"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,3 +68,12 @@ the rest is the same */
height: 44.75px;
width: 330px !important;
}

.hg-candidate-box {
max-width: 400px;
}

li.hg-candidate-box-list-item {
height: 60px;
width: 60px;
}
12 changes: 11 additions & 1 deletion app/src/atoms/SoftwareKeyboard/AlphanumericKeyboard/index.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
import * as React from 'react'
import Keyboard from 'react-simple-keyboard'
import { alphanumericKeyboardLayout, customDisplay } from '../constants'
import { useSelector } from 'react-redux'
import { getAppLanguage } from '/app/redux/config'
import {
alphanumericKeyboardLayout,
pinYinLayoutCandidates,
customDisplay,
} from '../constants'
import type { KeyboardReactInterface } from 'react-simple-keyboard'

import '../index.css'
Expand All @@ -19,6 +25,7 @@ export function AlphanumericKeyboard({
debug = false, // If true, <ENTER> will input a \n
}: AlphanumericKeyboardProps): JSX.Element {
const [layoutName, setLayoutName] = React.useState<string>('default')
const appLanguage = useSelector(getAppLanguage)
const onKeyPress = (button: string): void => {
if (button === '{ABC}') handleShift()
if (button === '{numbers}') handleNumber()
Expand Down Expand Up @@ -47,6 +54,9 @@ export function AlphanumericKeyboard({
onKeyPress={onKeyPress}
layoutName={layoutName}
layout={alphanumericKeyboardLayout}
layoutCandidates={
appLanguage === 'zh-CN' ? pinYinLayoutCandidates : undefined
}
display={customDisplay}
mergeDisplay={true}
useButtonTag={true}
Expand Down
9 changes: 9 additions & 0 deletions app/src/atoms/SoftwareKeyboard/FullKeyboard/index.css
Original file line number Diff line number Diff line change
Expand Up @@ -103,3 +103,12 @@
color: #16212d;
background-color: #e3e3e3; /* grey30 */
}

.hg-candidate-box {
max-width: 400px;
}

li.hg-candidate-box-list-item {
height: 60px;
width: 60px;
}
12 changes: 11 additions & 1 deletion app/src/atoms/SoftwareKeyboard/FullKeyboard/index.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
import * as React from 'react'
import { KeyboardReact as Keyboard } from 'react-simple-keyboard'
import { customDisplay, fullKeyboardLayout } from '../constants'
import { useSelector } from 'react-redux'
import { getAppLanguage } from '/app/redux/config'
import {
customDisplay,
pinYinLayoutCandidates,
fullKeyboardLayout,
} from '../constants'
import type { KeyboardReactInterface } from 'react-simple-keyboard'

import '../index.css'
Expand All @@ -19,6 +25,7 @@ export function FullKeyboard({
debug = false,
}: FullKeyboardProps): JSX.Element {
const [layoutName, setLayoutName] = React.useState<string>('default')
const appLanguage = useSelector(getAppLanguage)
const handleShift = (button: string): void => {
switch (button) {
case '{shift}':
Expand Down Expand Up @@ -56,6 +63,9 @@ export function FullKeyboard({
onKeyPress={onKeyPress}
layoutName={layoutName}
layout={fullKeyboardLayout}
layoutCandidates={
appLanguage === 'zh-CN' ? pinYinLayoutCandidates : undefined
}
display={customDisplay}
mergeDisplay={true}
useButtonTag={true}
Expand Down
6 changes: 6 additions & 0 deletions app/src/atoms/SoftwareKeyboard/constants.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import chineseLayout from 'simple-keyboard-layouts/build/layouts/chinese'

export const customDisplay = {
'{numbers}': '123',
'{shift}': 'ABC',
Expand Down Expand Up @@ -69,3 +71,7 @@ export const numericalKeyboardLayout = {
export const numericalCustom = {
'{backspace}': 'del',
}

// @ts-expect-error layout candidates exists but is not on the type
// in the simple-keyboard-layouts package
export const pinYinLayoutCandidates = chineseLayout.layoutCandidates
smb2268 marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -180,4 +180,16 @@ describe('SystemLanguagePreferenceModal', () => {
'zh-Hant'
)
})

it('should not open update modal when system language changes to an unsuppported language', () => {
vi.mocked(getSystemLanguage).mockReturnValue('es-MX')
render()

expect(screen.queryByRole('button', { name: 'Don’t change' })).toBeNull()
expect(
screen.queryByRole('button', {
name: 'Use system language',
})
).toBeNull()
})
})
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,7 @@ export function SystemLanguagePreferenceModal(): JSX.Element | null {
const storedSystemLanguage = useSelector(getStoredSystemLanguage)

const showBootModal = appLanguage == null && systemLanguage != null
const showUpdateModal =
appLanguage != null &&
systemLanguage != null &&
storedSystemLanguage != null &&
systemLanguage !== storedSystemLanguage
const [showUpdateModal, setShowUpdateModal] = useState(false)

const title = showUpdateModal
? t('system_language_preferences_update')
Expand Down Expand Up @@ -120,6 +116,13 @@ export function SystemLanguagePreferenceModal(): JSX.Element | null {
void i18n.changeLanguage(systemLanguage)
}
}
// only show update modal if we support the language their system has updated to
setShowUpdateModal(
appLanguage != null &&
matchedSystemLanguageOption != null &&
storedSystemLanguage != null &&
systemLanguage !== storedSystemLanguage
)
}
}, [i18n, systemLanguage, showBootModal])

Expand Down
6 changes: 6 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3403,6 +3403,7 @@
reselect "4.0.0"
rxjs "^6.5.1"
semver "5.7.2"
simple-keyboard-layouts "3.4.41"
styled-components "5.3.6"
typeface-open-sans "0.0.75"
uuid "3.2.1"
Expand Down Expand Up @@ -20041,6 +20042,11 @@ simple-git@^3.15.1:
"@kwsites/promise-deferred" "^1.1.1"
debug "^4.3.4"

[email protected]:
version "3.4.41"
resolved "https://registry.yarnpkg.com/simple-keyboard-layouts/-/simple-keyboard-layouts-3.4.41.tgz#eb1504c36626f29b0d5590d419ab39c43d06969a"
integrity sha512-vVnPRgZmK9DqbqUxOgZesdAlWkzY1Cvxf8YaFW3SHJHQKuvCkR8VL6TjJyrpM8BkJa3W4ry1i3CsSydlPckAoQ==

simple-swizzle@^0.2.2:
version "0.2.2"
resolved "https://registry.yarnpkg.com/simple-swizzle/-/simple-swizzle-0.2.2.tgz#a4da6b635ffcccca33f70d17cb92592de95e557a"
Expand Down
Loading