Skip to content

Commit

Permalink
fix: update typed bio on locale change
Browse files Browse the repository at this point in the history
  • Loading branch information
hta218 committed Aug 14, 2023
1 parent 7d711c3 commit afbb274
Showing 1 changed file with 39 additions and 31 deletions.
70 changes: 39 additions & 31 deletions components/homepage/TypedBios.tsx
Original file line number Diff line number Diff line change
@@ -1,58 +1,66 @@
import React from 'react'
import { useTranslation } from 'next-i18next'
import { useEffect, useRef } from 'react'
import Typed from 'typed.js'
import { Twemoji } from '../Twemoji'
import { useTranslation } from 'next-i18next'
import { useLocale } from '~/hooks/useLocale'

function createTypedInstance(el: HTMLElement) {
return new Typed(el, {
stringsElement: '#bios',
typeSpeed: 40,
backSpeed: 10,
loop: true,
backDelay: 1000,
})
}

export function TypedBios() {
let el = React.useRef(null)
let typed = React.useRef(null)
let { t } = useTranslation('common')
let el = useRef(null)
let typed = useRef(null)
let [locale] = useLocale()
let tr = useTranslation('common')

React.useEffect(() => {
typed.current = new Typed(el.current, {
stringsElement: '#bios',
typeSpeed: 40,
backSpeed: 10,
loop: true,
backDelay: 1000,
})
return () => typed.current.destroy()
}, [])
useEffect(() => {
if (tr.ready) {
typed.current?.destroy()
typed.current = createTypedInstance(el.current)
}
}, [locale, tr])

return (
<div>
<ul id="bios" className="hidden">
<li>{t('bio_1')}</li>
<li>{t('bio_2')}</li>
<li>{t('bio_3')}</li>
<li>{t('bio_4')}</li>
<li>{t('bio_5')}</li>
<li>{t('bio_6')}</li>
<li>{t('bio_7')}</li>
<li>{t('bio_8')}</li>
<li>{t('bio_9')}</li>
<li>{tr.t('bio_1')}</li>
<li>{tr.t('bio_2')}</li>
<li>{tr.t('bio_3')}</li>
<li>{tr.t('bio_4')}</li>
<li>{tr.t('bio_5')}</li>
<li>{tr.t('bio_6')}</li>
<li>{tr.t('bio_7')}</li>
<li>{tr.t('bio_8')}</li>
<li>{tr.t('bio_9')}</li>
<li>
{t('bio_10')} <Twemoji emoji="dog" />
{tr.t('bio_10')} <Twemoji emoji="dog" />
</li>
<li>
{t('bio_11')}
{tr.t('bio_11')}
<span className="ml-1">
<Twemoji emoji="soccer-ball" />,
<Twemoji emoji="man-swimming" />,
<Twemoji emoji="ping-pong" />,
<Twemoji emoji="volleyball" />
</span>
</li>
<li>{t('bio_12')}</li>
<li>{tr.t('bio_12')}</li>
<li>
{t('bio_13')} <Twemoji emoji="musical-keyboard" /> & <Twemoji emoji="guitar" />
{tr.t('bio_13')} <Twemoji emoji="musical-keyboard" /> & <Twemoji emoji="guitar" />
</li>
<li>{t('bio_14')}</li>
<li>{tr.t('bio_14')}</li>
<li>
{t('bio_15')} <Twemoji emoji="chess-pawn" />
{tr.t('bio_15')} <Twemoji emoji="chess-pawn" />
</li>
<li>
{t('bio_16')} <Twemoji emoji="video-game" />.
{tr.t('bio_16')} <Twemoji emoji="video-game" />.
</li>
</ul>
<span ref={el} className="text-neutral-900 dark:text-neutral-200" />
Expand Down

1 comment on commit afbb274

@vercel
Copy link

@vercel vercel bot commented on afbb274 Aug 14, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

leo-huynh-dot-dev – ./

leo-huynh-dot-dev-git-main-hta218.vercel.app
www.leohuynh.dev
leo-huynh-dot-dev-hta218.vercel.app
leohuynh.dev

Please sign in to comment.