Refactor i18n initialization and make UI adjustments

Converted the `initializeI18nClient` function to an asynchronous function for a more straightforward implementation. Simultaneously, made some tweaks to the UI components, such as altering dimensions in `site-footer.tsx` and `site-page-header.tsx`, and refactoring the `FooterSectionHeading` component for easier maintenance and improved readability.
This commit is contained in:
giancarlo
2024-04-16 21:06:28 +08:00
parent cad729670f
commit 1f3c4805f0
3 changed files with 51 additions and 57 deletions

View File

@@ -1,5 +1,6 @@
import Link from 'next/link'; import Link from 'next/link';
import { Heading } from '@kit/ui/heading';
import { Trans } from '@kit/ui/trans'; import { Trans } from '@kit/ui/trans';
import { AppLogo } from '~/components/app-logo'; import { AppLogo } from '~/components/app-logo';
@@ -10,7 +11,7 @@ const YEAR = new Date().getFullYear();
export function SiteFooter() { export function SiteFooter() {
return ( return (
<footer className={'border-t py-8 xl:py-12 2xl:py-14'}> <footer className={'border-t py-8 xl:py-12 2xl:py-14'}>
<div className={'container mx-auto'}> <div className={'px-8'}>
<div className={'flex flex-col space-y-8 lg:flex-row lg:space-y-0'}> <div className={'flex flex-col space-y-8 lg:flex-row lg:space-y-0'}>
<div <div
className={ className={
@@ -20,10 +21,10 @@ export function SiteFooter() {
> >
<div className={'flex flex-col space-y-4'}> <div className={'flex flex-col space-y-4'}>
<div> <div>
<AppLogo className={'w-[85px] md:w-[115px]'} /> <AppLogo className={'w-[85px] md:w-[95px]'} />
</div> </div>
<div className={'flex flex-col space-y-2'}> <div className={'flex flex-col space-y-4'}>
<div> <div>
<p className={'text-sm text-muted-foreground'}> <p className={'text-sm text-muted-foreground'}>
Add a short tagline about your product Add a short tagline about your product
@@ -42,8 +43,7 @@ export function SiteFooter() {
<div <div
className={ className={
'flex flex-col space-y-8 lg:space-x-6 lg:space-y-0' + 'flex flex-col space-y-8 lg:space-x-6 lg:space-y-0' +
' xl:space-x-16 2xl:space-x-20' + ' w-full lg:flex-row lg:justify-end xl:space-x-16'
' w-full lg:flex-row lg:justify-end'
} }
> >
<div> <div>
@@ -116,11 +116,7 @@ export function SiteFooter() {
} }
function FooterSectionHeading(props: React.PropsWithChildren) { function FooterSectionHeading(props: React.PropsWithChildren) {
return ( return <Heading level={6}>{props.children}</Heading>;
<p>
<span className={'font-semibold'}>{props.children}</span>
</p>
);
} }
function FooterSectionList(props: React.PropsWithChildren) { function FooterSectionList(props: React.PropsWithChildren) {

View File

@@ -6,7 +6,7 @@ export function SitePageHeader(props: {
className?: string; className?: string;
}) { }) {
return ( return (
<div className={cn('border-b py-8 xl:py-12 2xl:py-14', props.className)}> <div className={cn('border-b py-8 xl:py-10 2xl:py-12', props.className)}>
<div className={'container flex flex-col space-y-2 lg:space-y-4'}> <div className={'container flex flex-col space-y-2 lg:space-y-4'}>
<h1 className={'font-base font-heading text-3xl xl:text-5xl'}> <h1 className={'font-base font-heading text-3xl xl:text-5xl'}>
{props.title} {props.title}

View File

@@ -10,7 +10,7 @@ let clientInstance: i18n | null = null;
* @param settings - the i18n settings * @param settings - the i18n settings
* @param resolver - a function that resolves the i18n resources * @param resolver - a function that resolves the i18n resources
*/ */
export function initializeI18nClient( export async function initializeI18nClient(
settings: InitOptions, settings: InitOptions,
resolver: (lang: string, namespace: string) => Promise<object>, resolver: (lang: string, namespace: string) => Promise<object>,
): Promise<i18n> { ): Promise<i18n> {
@@ -18,8 +18,7 @@ export function initializeI18nClient(
return Promise.resolve(clientInstance); return Promise.resolve(clientInstance);
} }
return new Promise<i18n>((resolve, reject) => { await i18next
void i18next
.use(initReactI18next) .use(initReactI18next)
.use( .use(
resourcesToBackend(async (language, namespace, callback) => { resourcesToBackend(async (language, namespace, callback) => {
@@ -44,10 +43,12 @@ export function initializeI18nClient(
(err) => { (err) => {
if (err) { if (err) {
console.error('Error initializing i18n client', err); console.error('Error initializing i18n client', err);
return reject(err);
} }
},
);
console.log('i18n client initialized'); console.log('i18n client initialized');
console.log( console.log(
`initialized with ${i18next.languages.join(', ')} languages`, `initialized with ${i18next.languages.join(', ')} languages`,
clientInstance, clientInstance,
@@ -62,8 +63,5 @@ export function initializeI18nClient(
clientInstance = i18next; clientInstance = i18next;
resolve(clientInstance); return clientInstance;
},
);
});
} }