Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Navbar Edits/Dark Mode Toggle #17

Open
wants to merge 23 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
75432fb
feat: enabled light/dark mode toggle in tailwind
alairon May 9, 2022
354539c
feat: dark mode
alairon May 9, 2022
22f0347
Merge branch 'cwjoshuak:main' into dark-mode
alairon May 9, 2022
9a8ad84
fix: defaults to system theme until set
alairon May 9, 2022
e01770b
fix: stops FoUC when changing pages in dark mode
alairon May 9, 2022
41e58db
Merge branch 'main' into dark-mode
alairon May 29, 2022
24c9382
refactor: Moved dark mode to its own component
alairon May 29, 2022
63e327c
refactor: navbar dark toggle, language btn test
alairon May 29, 2022
ac82836
refactor: removed unused switch toggle
alairon May 30, 2022
977a25f
refactor: Moved settings into navbar
alairon May 30, 2022
5e4b60a
fix: dark mode desync
alairon May 30, 2022
26bf717
refactor: changed color of selected language
alairon May 30, 2022
a62cbb6
feat: changed colors to match system dropdown
alairon May 30, 2022
c78a253
Merge branch 'cwjoshuak:main' into dark-mode
alairon May 30, 2022
3280e4c
refactor: changed language selector
alairon May 31, 2022
f7b06ba
moved navbar elements and sizes
alairon May 31, 2022
9d67b7f
fix: data alignment
alairon May 31, 2022
140eb8f
refactor: replaced chevron with current language
alairon May 31, 2022
0c6f1c6
refactor: added div ids
alairon May 31, 2022
8207074
fix: unique key warning
alairon Jun 6, 2022
5b735a1
fix: removed InnerHTML in favor of i18n
alairon Jun 6, 2022
2dcf425
fix: i18nKey typo
alairon Jun 6, 2022
e3dc4e2
feat: EN/ZH localization line parity
alairon Jun 6, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 69 additions & 1 deletion components/NavBar.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,36 @@
import classNames from 'classnames'
import Link from 'next/link'
import { useRouter } from 'next/router'
import { useEffect, useRef } from 'react'
import { IconSun, IconMoon } from '@tabler/icons'
import useLocalStorage from '@olerichter00/use-localstorage'
import { useTranslation } from 'next-i18next'
import { IconLanguage } from '@tabler/icons'

const NavBar = () => {
const { t } = useTranslation('common')

const router = useRouter()

const isMounted = useRef(false)
const defaultTheme = () => {
return (localStorage.getItem('darkMode') || window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches)
}
const [darkMode, setDarkMode] = useLocalStorage<boolean>('darkMode', defaultTheme)

useEffect(() => {
//Prevents FoUC (Flash of Unstylized Content) by not refreshing on first mount
if (!isMounted.current) { isMounted.current = true; return }

//Toggle Daisy UI colors (e.g. bg-base-###)
document.documentElement.setAttribute('data-theme', darkMode ? 'dark' : 'light')

//Toggle standard Tailwind colors (e.g. bg-sky-800)
darkMode
? document.documentElement.classList.add('dark')
: document.documentElement.classList.remove('dark')
}, [darkMode])

return (
<>
<div className="relative bg-sky-800 py-2 text-center lg:px-4">
Expand All @@ -17,7 +41,7 @@ const NavBar = () => {
<span className="sm:text-md mx-4 flex-auto text-center text-sm font-semibold">
<label
className="cursor-pointer text-teal-300"
// htmlFor="changelog-modal"
// htmlFor="changelog-modal"
>
<a
href="https://discord.gg/qhnqxtphSg"
Expand Down Expand Up @@ -86,6 +110,7 @@ const NavBar = () => {
</a>
</div>
</div>
{/* The previous language selector
<div className="navbar-end text-right text-lg font-semibold uppercase">
<IconLanguage />
<select
Expand All @@ -102,9 +127,52 @@ const NavBar = () => {
<option value="zh">ZH</option>
</select>
</div>
*/}
<div className="navbar-end uppercase">
<div id="darkModeToggle">
<button
className="btn btn-ghost btn-sm ml-2 mr-auto cursor-pointer"
onClick={() =>
setDarkMode(!darkMode)
}
>
{darkMode ? <IconMoon /> : <IconSun />}
</button>
</div>
<span className="mx-1" />
<div id="langSelector" className='dropdown dropdown-end'>
<label tabIndex={0} className="btn btn-ghost btn-sm"><IconLanguage /><span className='px-1'>{router.locale}</span></label>
<ul id="langSelectorList" tabIndex={0} className={'dropdown-content menu shadow bg-base-100 border border-white'}>
{router.locales?.map((locale, idx, arr) => {
return (
<li
id={"langSelector_" + locale}
role="option"
key={idx+1}
tabIndex={idx+1}
className={
classNames('px-4 rounded-none select-none active:bg-base-dropdown active:text-white hover:bg-base-dropdown hover:text-white',
{ 'bg-sky-600 text-white font-semibold': router.locale === locale },
)}
onClick={() => {
const { pathname, asPath, query } = router
router.replace({ pathname, query }, asPath, {
locale: arr[idx],
})
}}>
{locale}
</li>
)
})
}
</ul>
</div>

</div>
</div>
</>
)
}


export default NavBar
1 change: 1 addition & 0 deletions components/modals/AlarmConfigModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ const AlarmConfigModal = () => {
setDarkMode((e.target as HTMLInputElement).checked)
}
defaultChecked={darkMode}
checked={darkMode}
className="checkbox checkbox-sm"
/>
</label>
Expand Down
1 change: 1 addition & 0 deletions components/modals/MerchantConfigModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ const MerchantConfigModal = () => {
setDarkMode((e.target as HTMLInputElement).checked)
}
defaultChecked={darkMode}
checked={darkMode}
className="checkbox checkbox-sm"
/>
</label>
Expand Down
32 changes: 0 additions & 32 deletions pages/alarms.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -85,38 +85,6 @@ const Alarms: NextPage = () => {
'regionTZName',
'US West'
)
const isMounted = useRef(false)
const defaultTheme = () => {
// Defaults to system theme if unconfigured
return (
localStorage.getItem('darkMode') ||
(window.matchMedia &&
window.matchMedia('(prefers-color-scheme: dark)').matches)
)
}
const [darkMode, setDarkMode] = useLocalStorage<boolean>(
'darkMode',
defaultTheme
)
useEffect(() => {
//Prevents FoUC (Flash of Unstylized Content) by not refreshing on first mount
if (!isMounted.current) {
isMounted.current = true
return
}

//Toggle Daisy UI colors (e.g. bg-base-###)
document.documentElement.setAttribute(
'data-theme',
darkMode ? 'dark' : 'light'
)

//Toggle standard Tailwind colors (e.g. bg-sky-800)
darkMode
? document.documentElement.classList.add('dark')
: document.documentElement.classList.remove('dark')
}, [darkMode])

const [serverTime, setServerTime] = useState<DateTime>(
currDate.setZone(regionTZ)
)
Expand Down
46 changes: 13 additions & 33 deletions pages/merchants.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,25 +32,6 @@ const Merchants: NextPage = (props) => {
'merchantServer',
'Shandi'
)
const isMounted = useRef(false);
const defaultTheme = () => {
// Defaults to system theme if unconfigured
return (localStorage.getItem('darkMode') || window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches)
}
const [darkMode, setDarkMode] = useLocalStorage<boolean>('darkMode', defaultTheme)
useEffect(()=> {
//Prevents FoUC (Flash of Unstylized Content) by not refreshing on first mount
if (!isMounted.current){ isMounted.current = true; return }

//Toggle Daisy UI colors (e.g. bg-base-###)
document.documentElement.setAttribute('data-theme', darkMode ? 'dark' : 'light')

//Toggle standard Tailwind colors (e.g. bg-sky-800)
darkMode
? document.documentElement.classList.add("dark")
: document.documentElement.classList.remove("dark")
}, [darkMode])

const [currDate, setCurrDate] = useState<DateTime>(DateTime.now())
const [regionTZ, setRegionTZ] = useLocalStorage<string>('regionTZ', 'UTC-7')

Expand Down Expand Up @@ -219,24 +200,23 @@ const Merchants: NextPage = (props) => {
</Head>
<MerchantConfigModal />
<div className="flex min-h-screen flex-col items-center whitespace-normal bg-base-300 py-2 dark:bg-base-100">
<div className="ml-auto flex w-full justify-end px-4 lg:px-20">
<div className="hidden w-1/5 whitespace-normal text-center text-sm uppercase sm:inline lg:text-lg">
<span
dangerouslySetInnerHTML={{
__html: t('server-note-text', {
timeType: viewLocalizedTime ? 'CURRENT TIME' : 'SERVER TIME',
}),
}}
/>
<div className="ml-auto flex w-full justify-end px-4 pb-2 lg:px-20">
<div className="hidden w-1/5 whitespace-normal text-center align-middle text-sm uppercase sm:inline lg:text-lg">
<Trans
i18nKey="server-note-text"
values={{ timeType: viewLocalizedTime ? t('common:current-time') : t('common:server-time') }}
>
{t('server-note-text')}
</Trans>
</div>
<label
htmlFor="merchant-config-modal"
className="btn btn-ghost ml-2 mr-auto cursor-pointer"
className="btn btn-ghost ml-2 my-auto cursor-pointer"
>
<IconSettings className="transition ease-in-out hover:-translate-y-px hover:rotate-45" />
</label>

<div className="mr-4 mb-2 w-40 flex-col">
<div className="flex grow" />
<div className="w-40 flex-col mr-4 my-auto">
<select
className="select select-bordered select-sm w-full"
onChange={(e) => {
Expand Down Expand Up @@ -269,7 +249,7 @@ const Merchants: NextPage = (props) => {
</select>
)}
</div>
<table className="mb-2">
<table className="my-auto">
<tbody>
<tr
className={classNames('text-left', {
Expand Down Expand Up @@ -491,7 +471,7 @@ const Merchants: NextPage = (props) => {
}

import { serverSideTranslations } from 'next-i18next/serverSideTranslations'
import { useTranslation } from 'next-i18next'
import { Trans, useTranslation } from 'next-i18next'
import classNames from 'classnames'

export async function getStaticProps({ locale }: { locale: string }) {
Expand Down
2 changes: 1 addition & 1 deletion public/locales/zh/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@
"view-in-24-hr": "查看24小时内的",
"option-minute-before": "提前{{minutes}}分钟提醒",
"view-in-current-time": "当前时间内查看",
"dark-mode": "Dark Mode",
"dark-mode": "深色模式",
"all-done": "确定"
}
20 changes: 17 additions & 3 deletions public/locales/zh/merchants.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"vote": "投票",
"data-by": "数据来源: ",
"last-updated": "最后更新",
"server-note-text": "注意:当前显示的是<strong>服务器时间</strong>.",
"server-note-text": "注意:当前显示的是<strong>{{timeType}}</strong>.",

"locations": {
"Rethramis": "阿尔忒弥斯",
Expand Down Expand Up @@ -82,7 +82,10 @@
"Tideshelf Path": "浅海之路",
"Starsand Beach": "星星沙滩",
"Tikatika Colony": "蒂卡蒂卡群落地",
"Secret Forest": "秘密森林"
"Secret Forest": "秘密森林",
"South Vern": "伯尔尼南部",
"Candaria Territory": "Candaria Territory",
"Bellion Ruins": "Bellion Ruins"
},
"items": {
"920404": {
Expand Down Expand Up @@ -227,6 +230,17 @@
"70503001": { "name": "Yudia Spellbook" },
"70503005": { "name": "Shimmering Essence" },
"70503006": { "name": "Energy X7 Capsule" },
"70503008": { "name": "Piyer's Secret Textbook" }
"70503008": { "name": "Piyer's Secret Textbook" },

"70500063": { "name": "Feather Fan" },
"70500062": { "name": "Febre Potion" },
"70500064": { "name": "Mockup Firefly" },
"70501012": { "name": "Necromancer's Records" },

"63200407": { "name": "Satra" },
"63200408": { "name": "Killian" },
"63200402": { "name": "Lujean" },
"63200404": { "name": "Vern Zenlord" },
"63200403": { "name": "Xereon" }
}
}
6 changes: 5 additions & 1 deletion tailwind.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@ module.exports = {
],
darkMode: 'class',
theme: {
extend: {},
extend: {
colors: {
'base-dropdown': '#767676',
}
},
},
plugins: [require('daisyui')],
daisyui: {
Expand Down