Skip to content

Commit

Permalink
feat(native-app): add useLocale hook (#16357)
Browse files Browse the repository at this point in the history
* feat: add useLocale hook and use for all applications queries

* feat: add to document detail query

---------

Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
  • Loading branch information
thoreyjona and kodiakhq[bot] authored Oct 15, 2024
1 parent 9a11ba4 commit 020a316
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 17 deletions.
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
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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<string>()
Expand Down Expand Up @@ -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) => {
Expand Down

0 comments on commit 020a316

Please sign in to comment.