From 8e7a41c3c2bc419a3ed85a7d0c54eda95907fc7c Mon Sep 17 00:00:00 2001 From: thoreyjona Date: Thu, 10 Oct 2024 14:37:20 +0000 Subject: [PATCH 1/2] feat: add useLocale hook and use for all applications queries --- apps/native/app/src/hooks/use-locale.ts | 6 ++++++ .../src/screens/applications/applications-completed.tsx | 5 ++--- .../src/screens/applications/applications-in-progress.tsx | 5 ++--- .../src/screens/applications/applications-incomplete.tsx | 5 ++--- apps/native/app/src/screens/applications/applications.tsx | 7 ++----- 5 files changed, 14 insertions(+), 14 deletions(-) create mode 100644 apps/native/app/src/hooks/use-locale.ts diff --git a/apps/native/app/src/hooks/use-locale.ts b/apps/native/app/src/hooks/use-locale.ts new file mode 100644 index 000000000000..97ce8277c447 --- /dev/null +++ b/apps/native/app/src/hooks/use-locale.ts @@ -0,0 +1,6 @@ +import { usePreferencesStore } from '../stores/preferences-store' + +export const useLocale = () => { + const locale = usePreferencesStore(({ locale }) => locale) + return locale === 'is-IS' ? 'is' : 'en' +} diff --git a/apps/native/app/src/screens/applications/applications-completed.tsx b/apps/native/app/src/screens/applications/applications-completed.tsx index 32ffb4bd29d8..e390c83068c8 100644 --- a/apps/native/app/src/screens/applications/applications-completed.tsx +++ b/apps/native/app/src/screens/applications/applications-completed.tsx @@ -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( @@ -33,7 +33,6 @@ export const ApplicationsCompletedScreen: NavigationFunctionComponent = ({ }) => { useNavigationOptions(componentId) const [refetching, setRefetching] = useState(false) - const { locale } = usePreferencesStore() const applicationsRes = useListApplicationsQuery({ variables: { @@ -44,7 +43,7 @@ export const ApplicationsCompletedScreen: NavigationFunctionComponent = ({ ApplicationResponseDtoStatusEnum.Approved, ], }, - locale: locale === 'is-IS' ? 'is' : 'en', + locale: useLocale(), }, }) diff --git a/apps/native/app/src/screens/applications/applications-in-progress.tsx b/apps/native/app/src/screens/applications/applications-in-progress.tsx index 28305f7fb516..237c2c7d719d 100644 --- a/apps/native/app/src/screens/applications/applications-in-progress.tsx +++ b/apps/native/app/src/screens/applications/applications-in-progress.tsx @@ -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( @@ -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(), }, }) diff --git a/apps/native/app/src/screens/applications/applications-incomplete.tsx b/apps/native/app/src/screens/applications/applications-incomplete.tsx index d9a224e4e667..5859693de702 100644 --- a/apps/native/app/src/screens/applications/applications-incomplete.tsx +++ b/apps/native/app/src/screens/applications/applications-incomplete.tsx @@ -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( @@ -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(), }, }) diff --git a/apps/native/app/src/screens/applications/applications.tsx b/apps/native/app/src/screens/applications/applications.tsx index 42e157caf749..f999a0c124a9 100644 --- a/apps/native/app/src/screens/applications/applications.tsx +++ b/apps/native/app/src/screens/applications/applications.tsx @@ -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( @@ -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( From d994b5c526ede930408203d03c84045745d579fd Mon Sep 17 00:00:00 2001 From: thoreyjona Date: Fri, 11 Oct 2024 16:17:35 +0000 Subject: [PATCH 2/2] feat: add to document detail query --- .../app/src/screens/document-detail/document-detail.tsx | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/apps/native/app/src/screens/document-detail/document-detail.tsx b/apps/native/app/src/screens/document-detail/document-detail.tsx index 0e1da89446cc..6b913a98a79a 100644 --- a/apps/native/app/src/screens/document-detail/document-detail.tsx +++ b/apps/native/app/src/screens/document-detail/document-detail.tsx @@ -30,10 +30,10 @@ 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 { toggleAction } from '../../lib/post-mail-action' import { authStore } from '../../stores/auth-store' import { useOrganizationsStore } from '../../stores/organizations-store' -import { usePreferencesStore } from '../../stores/preferences-store' import { ButtonRegistry } from '../../utils/component-registry' import { getButtonsForActions } from './utils/get-buttons-for-actions' import { useBrowser } from '../../lib/use-browser' @@ -230,7 +230,6 @@ export const DocumentDetailScreen: NavigationFunctionComponent<{ const client = useApolloClient() const intl = useIntl() const htmlStyles = useHtmlStyles() - const { locale } = usePreferencesStore() const { openBrowser } = useBrowser() const { getOrganizationLogoUrl } = useOrganizationsStore() const [accessToken, setAccessToken] = useState() @@ -293,7 +292,7 @@ export const DocumentDetailScreen: NavigationFunctionComponent<{ // If the document is urgent we need to check if the user needs to confirm reception of it before fetching the document data includeDocument: shouldIncludeDocument, }, - locale: locale === 'is-IS' ? 'is' : 'en', + locale: useLocale(), }, fetchPolicy: 'no-cache', onCompleted: async (data) => {