-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat+refactor(shell): implement language switcher, refactor header, s…
…ome more work on i18n
- Loading branch information
1 parent
e6c5330
commit 02999d6
Showing
27 changed files
with
472 additions
and
169 deletions.
There are no files selected for viewing
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 0 additions & 1 deletion
1
apps/shell/src/app/[locale]/staking/validator/[address]/@modals/redelegate/page.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { useLocaleSwitcher } from '../hooks/use-locale-switcher'; | ||
import { LocaleDropdown } from '@haqq/shell-ui-kit'; | ||
|
||
export function AppLocaleDropdown() { | ||
const { switchLocale, locales, currentLocale } = useLocaleSwitcher(); | ||
|
||
return ( | ||
<LocaleDropdown | ||
locales={locales} | ||
switchLocale={switchLocale} | ||
currentLocale={currentLocale} | ||
/> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,43 +1,53 @@ | ||
import { haqqMainnet, haqqTestedge2 } from 'wagmi/chains'; | ||
import { HeaderLink } from '@haqq/shell-ui-kit'; | ||
|
||
export const headerLinks: { | ||
href: string; | ||
label: string; | ||
chains: number[]; | ||
}[] = [ | ||
// { | ||
// href: '/', | ||
// label: 'Home', | ||
// chains: [haqqMainnet.id, haqqTestedge2.id], | ||
// }, | ||
export const headerLinks: HeaderLink[] = [ | ||
{ | ||
href: '/uc-dao', | ||
type: 'link', | ||
label: 'UC DAO', | ||
href: '/uc-dao', | ||
chains: [haqqMainnet.id, haqqTestedge2.id], | ||
}, | ||
{ | ||
href: '/staking', | ||
type: 'link', | ||
label: 'Staking', | ||
href: '/staking', | ||
chains: [haqqMainnet.id, haqqTestedge2.id], | ||
}, | ||
{ | ||
href: '/governance', | ||
type: 'link', | ||
label: 'Governance', | ||
href: '/governance', | ||
chains: [haqqMainnet.id, haqqTestedge2.id], | ||
}, | ||
{ | ||
href: '/authz', | ||
label: 'Authz', | ||
chains: [haqqMainnet.id, haqqTestedge2.id], | ||
type: 'dropdown', | ||
label: 'Tools', | ||
children: [ | ||
{ | ||
type: 'link', | ||
label: 'Authz', | ||
href: '/authz', | ||
chains: [haqqMainnet.id, haqqTestedge2.id], | ||
}, | ||
{ | ||
type: 'link', | ||
label: 'Faucet', | ||
href: '/faucet', | ||
chains: [haqqTestedge2.id], | ||
}, | ||
], | ||
}, | ||
{ | ||
href: '/faucet', | ||
label: 'Faucet', | ||
chains: [haqqTestedge2.id], | ||
type: 'dropdown', | ||
label: 'Utils', | ||
children: [ | ||
{ | ||
type: 'link', | ||
label: 'Address conversion', | ||
href: '/utils/address-conversion', | ||
chains: [haqqMainnet.id, haqqTestedge2.id], | ||
}, | ||
], | ||
}, | ||
]; | ||
|
||
export const headerUtilsLinks: { | ||
name: string; | ||
link: string; | ||
}[] = [{ name: 'Address conversion', link: '/utils/address-conversion' }]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { AVAILABLE_LOCALES, LOCALE_LABELS } from '../tolgee/shared'; | ||
|
||
export function useAvailableLocaleLinks() { | ||
return AVAILABLE_LOCALES.map((locale) => { | ||
return { | ||
id: locale, | ||
label: `${LOCALE_LABELS[locale].emoji} ${LOCALE_LABELS[locale].label}`, | ||
}; | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import { useMemo } from 'react'; | ||
import { Chain } from 'wagmi/chains'; | ||
import { HeaderLink } from '@haqq/shell-ui-kit'; | ||
import { headerLinks } from '../config/header-links'; | ||
|
||
export function useFilteredLinks(chain: Chain) { | ||
const links = useMemo(() => { | ||
return headerLinks | ||
.map((link) => { | ||
if (link.type === 'dropdown') { | ||
const filteredChildren = link.children.filter((child) => { | ||
return !child.chains || child.chains.includes(chain.id); | ||
}); | ||
if (filteredChildren.length > 0) { | ||
return { ...link, children: filteredChildren }; | ||
} | ||
return null; | ||
} | ||
|
||
if (link.type === 'link' && link.chains.includes(chain.id)) { | ||
return link; | ||
} | ||
|
||
return null; | ||
}) | ||
.filter(Boolean) as HeaderLink[]; | ||
}, [chain.id]); | ||
|
||
return links; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
'use client'; | ||
import { useCallback } from 'react'; | ||
import { useLocale } from 'next-intl'; | ||
import { useRouter, usePathname } from '../i18n/routing'; | ||
import { AVAILABLE_LOCALES, LOCALE_LABELS } from '../tolgee/shared'; | ||
|
||
export function useLocaleSwitcher() { | ||
const router = useRouter(); | ||
const pathname = usePathname(); | ||
const currentLocale = useLocale(); | ||
|
||
const switchLocale = useCallback( | ||
(locale: string) => { | ||
router.replace(pathname, { locale }); | ||
}, | ||
[router, pathname], | ||
); | ||
|
||
const locales = AVAILABLE_LOCALES.map((locale) => { | ||
return { | ||
id: locale, | ||
label: LOCALE_LABELS[locale].label, | ||
emoji: LOCALE_LABELS[locale].emoji, | ||
}; | ||
}); | ||
|
||
return { | ||
switchLocale, | ||
locales, | ||
currentLocale, | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,17 @@ | ||
import { getRequestConfig } from 'next-intl/server'; | ||
import { routing } from './routing'; | ||
import { Locale } from '../tolgee/shared'; | ||
|
||
export default getRequestConfig(async ({ requestLocale }) => { | ||
// Get locale from request and fallback to default if needed | ||
let locale = await requestLocale; | ||
|
||
if (!locale || !routing.locales.includes(locale as Locale)) { | ||
locale = routing.defaultLocale; | ||
} | ||
|
||
// The i18n/request.ts is required by next-intl package, we don't actually need it, | ||
// so we are only doing necessary actions to stop next-intl from complaining. | ||
export default getRequestConfig(async ({ locale }) => { | ||
return { | ||
// do this to make next-intl not emmit any warnings | ||
locale, | ||
messages: { locale }, | ||
}; | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { createNavigation } from 'next-intl/navigation'; | ||
import { defineRouting } from 'next-intl/routing'; | ||
import { AVAILABLE_LOCALES, DEFAULT_LOCALE } from '../tolgee/shared'; | ||
|
||
export const routing = defineRouting({ | ||
locales: AVAILABLE_LOCALES, | ||
defaultLocale: DEFAULT_LOCALE, | ||
localeCookie: { | ||
// Custom cookie name | ||
name: 'USER_LOCALE', | ||
// Expire in one day | ||
maxAge: 60 * 60 * 24, | ||
}, | ||
}); | ||
|
||
export const { Link, redirect, usePathname, useRouter, permanentRedirect } = | ||
createNavigation(routing); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.