Skip to content

Commit

Permalink
LanguageSelection
Browse files Browse the repository at this point in the history
  • Loading branch information
johannesloetzsch committed Dec 20, 2021
1 parent 2314043 commit 891b050
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 2 deletions.
26 changes: 26 additions & 0 deletions frontend/codegen/generates.ts
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,11 @@ export type LoginQueryVariables = Exact<{

export type LoginQuery = { __typename?: 'QueryType', login: { __typename?: 'login', jwt?: string | null | undefined } };

export type LanguagesQueryVariables = Exact<{ [key: string]: never; }>;


export type LanguagesQuery = { __typename?: 'QueryType', languages: Array<{ __typename?: 'languages', id: string, name: string, flag_url: string }> };

export type LookupQueryVariables = Exact<{
token?: InputMaybe<Scalars['String']>;
}>;
Expand Down Expand Up @@ -310,6 +315,27 @@ export const useLoginQuery = <
fetcher<LoginQuery, LoginQueryVariables>(LoginDocument, variables),
options
);
export const LanguagesDocument = `
query Languages {
languages {
id
name
flag_url
}
}
`;
export const useLanguagesQuery = <
TData = LanguagesQuery,
TError = unknown
>(
variables?: LanguagesQueryVariables,
options?: UseQueryOptions<LanguagesQuery, TError, TData>
) =>
useQuery<LanguagesQuery, TError, TData>(
variables === undefined ? ['Languages'] : ['Languages', variables],
fetcher<LanguagesQuery, LanguagesQueryVariables>(LanguagesDocument, variables),
options
);
export const LookupDocument = `
query Lookup($token: String = "R4nd0m") {
lookup(token: $token) {
Expand Down
9 changes: 9 additions & 0 deletions frontend/codegen/queries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,15 @@ export const login = gql`
login(auth: $auth) {jwt}
}`

export const languages = gql`
query Languages {
languages {
id
name
flag_url
}
}`

export const lookup = gql`
query Lookup($token: String="R4nd0m") {
lookup(token: $token) {
Expand Down
21 changes: 21 additions & 0 deletions frontend/components/LanguageSelection.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { useLanguagesQuery } from '../codegen/generates'
import i18next from 'i18next'

export default function LanguageSelection() {
const {data, remove, refetch} = useLanguagesQuery()
const {languages} = data || {}

return languages && (
<div>
{ languages.map( lang => (
<span key={lang.id}>
<img src={lang.flag_url} title={lang.name} style={{height: "15px"}}
onClick={() => i18next.changeLanguage(lang.id)}
/>
&nbsp;
</span>
))
}
</div>
) || ''
}
3 changes: 2 additions & 1 deletion frontend/components/Layout.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import styles from '../styles/Layout.module.css'
import Head from 'next/head'
import QueryClientProvider from '../components/QueryClientProvider'
import LanguageSelection from './LanguageSelection';
import { useTranslation, Trans } from 'react-i18next';
import constants from '../i18n/const.json'

Expand All @@ -17,7 +18,7 @@ export default function Layout({children}) {
</Head>

<div className={styles.header}>
<div>LangSelection</div>
<div><LanguageSelection/></div>
<div className={styles.slogan}>
<h1>psych<img src="/favicon.ico" className={styles.favicon}/>logical.<wbr/>contact</h1>
{ t('Find support from the SAR Network') }
Expand Down
2 changes: 1 addition & 1 deletion frontend/styles/Layout.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
}

.header div {
min-width: 100px; /** keep LangSelection and Login symetric **/
min-width: 200px; /** keep LangSelection and Login symetric **/
}

.footer {
Expand Down

0 comments on commit 891b050

Please sign in to comment.