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(native-app): add useLocale hook #16357

Merged
merged 4 commits into from
Oct 15, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
6 changes: 6 additions & 0 deletions apps/native/app/src/hooks/use-locale.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { usePreferencesStore } from '../stores/preferences-store'

export const useLocale = () => {
const locale = usePreferencesStore(({ locale }) => locale)
return locale === 'is-IS' ? 'is' : 'en'
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import {
} from '../../graphql/types/schema'
import { createNavigationOptionHooks } from '../../hooks/create-navigation-option-hooks'
import { useConnectivityIndicator } from '../../hooks/use-connectivity-indicator'
import { useLocale } from '../../hooks/use-locale'
import { ApplicationsList } from './components/applications-list'
import { usePreferencesStore } from '../../stores/preferences-store'

const { useNavigationOptions, getNavigationOptions } =
createNavigationOptionHooks(
Expand All @@ -33,7 +33,6 @@ export const ApplicationsCompletedScreen: NavigationFunctionComponent = ({
}) => {
useNavigationOptions(componentId)
const [refetching, setRefetching] = useState(false)
const { locale } = usePreferencesStore()

const applicationsRes = useListApplicationsQuery({
variables: {
Expand All @@ -44,7 +43,7 @@ export const ApplicationsCompletedScreen: NavigationFunctionComponent = ({
ApplicationResponseDtoStatusEnum.Approved,
],
},
locale: locale === 'is-IS' ? 'is' : 'en',
locale: useLocale(),
},
})

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import {
} from '../../graphql/types/schema'
import { createNavigationOptionHooks } from '../../hooks/create-navigation-option-hooks'
import { useConnectivityIndicator } from '../../hooks/use-connectivity-indicator'
import { useLocale } from '../../hooks/use-locale'
import { ApplicationsList } from './components/applications-list'
import { usePreferencesStore } from '../../stores/preferences-store'

const { useNavigationOptions, getNavigationOptions } =
createNavigationOptionHooks(
Expand All @@ -33,14 +33,13 @@ export const ApplicationsInProgressScreen: NavigationFunctionComponent = ({
}) => {
useNavigationOptions(componentId)
const [refetching, setRefetching] = useState(false)
const { locale } = usePreferencesStore()

const applicationsRes = useListApplicationsQuery({
variables: {
input: {
status: [ApplicationResponseDtoStatusEnum.Inprogress],
},
locale: locale === 'is-IS' ? 'is' : 'en',
locale: useLocale(),
},
})

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import {
} from '../../graphql/types/schema'
import { createNavigationOptionHooks } from '../../hooks/create-navigation-option-hooks'
import { useConnectivityIndicator } from '../../hooks/use-connectivity-indicator'
import { useLocale } from '../../hooks/use-locale'
import { ApplicationsList } from './components/applications-list'
import { usePreferencesStore } from '../../stores/preferences-store'

const { useNavigationOptions, getNavigationOptions } =
createNavigationOptionHooks(
Expand All @@ -33,14 +33,13 @@ export const ApplicationsIncompleteScreen: NavigationFunctionComponent = ({
}) => {
useNavigationOptions(componentId)
const [refetching, setRefetching] = useState(false)
const { locale } = usePreferencesStore()

const applicationsRes = useListApplicationsQuery({
variables: {
input: {
status: [ApplicationResponseDtoStatusEnum.Draft],
},
locale: locale === 'is-IS' ? 'is' : 'en',
locale: useLocale(),
},
})

Expand Down
7 changes: 2 additions & 5 deletions apps/native/app/src/screens/applications/applications.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ import {
} from '../../graphql/types/schema'
import { createNavigationOptionHooks } from '../../hooks/create-navigation-option-hooks'
import { useConnectivityIndicator } from '../../hooks/use-connectivity-indicator'
import { useLocale } from '../../hooks/use-locale'
import { testIDs } from '../../utils/test-ids'
import { isIos } from '../../utils/devices'
import { ApplicationsPreview } from './components/applications-preview'
import { BottomTabsIndicator } from '../../components/bottom-tabs-indicator/bottom-tabs-indicator'
import { usePreferencesStore } from '../../stores/preferences-store'

const { useNavigationOptions, getNavigationOptions } =
createNavigationOptionHooks(
Expand Down Expand Up @@ -102,12 +102,9 @@ export const ApplicationsScreen: NavigationFunctionComponent = ({
const theme = useTheme()
const [refetching, setRefetching] = useState(false)
const [hiddenContent, setHiddenContent] = useState(isIos)
const { locale } = usePreferencesStore()

const queryLocale = locale === 'is-IS' ? 'is' : 'en'

const applicationsRes = useListApplicationsQuery({
variables: { locale: queryLocale },
variables: { locale: useLocale() },
})

const applications = useMemo(
Expand Down