Skip to content

Commit

Permalink
Merge branch 'main' into dependabot/npm_and_yarn/postcss-8.4.31
Browse files Browse the repository at this point in the history
  • Loading branch information
NazarMykolenko authored Oct 4, 2023
2 parents 39b393a + 3e6de56 commit 43e79df
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 17 deletions.
1 change: 0 additions & 1 deletion public/next.svg

This file was deleted.

1 change: 0 additions & 1 deletion public/vercel.svg

This file was deleted.

6 changes: 3 additions & 3 deletions src/app/page.jsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use client'

import { useEffect, useState } from 'react'
import Message from '@/components/message'
import Message from '@/components/Message'
import ThemeToggle from '@/components/ThemeToggle'

const now = Date.now()
Expand All @@ -27,13 +27,13 @@ export default function Home() {
}

return (
<main className="flex flex-col gap-3 p-3">
<div className="flex flex-col gap-3 p-3">
{MOCK_MESSAGES.map(({ sentAt, content }, i) => (
<Message key={i} sentAt={sentAt}>
{content}
</Message>
))}
<ThemeToggle />
</main>
</div>
)
}
2 changes: 1 addition & 1 deletion src/components/message.jsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { timeFormatter } from '@/utils/getFormattedDate'
import { timeFormatter } from '@/utils'
import Image from 'next/image'
import Link from 'next/link'

Expand Down
28 changes: 17 additions & 11 deletions src/store/theme-context.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,29 @@ export const ThemeContext = createContext({
})

export default function ThemeProvider({ children }) {
const [currentTheme, setCurrentTheme] = useState('light')
const [currentTheme, setCurrentTheme] = useState('dark')

const checkTheme = useCallback(() => {
const isDarkPreferred = window.matchMedia(
'(prefers-color-scheme: dark)'
const isLightPreferred = window.matchMedia(
'(prefers-color-scheme: light)'
).matches
const isDarkStored = localStorage.theme === 'dark'

if (isDarkStored || (!localStorage.theme && isDarkPreferred)) {
localStorage.setItem('theme', 'dark')
document.documentElement.classList.add('dark')
setCurrentTheme('dark')
const isThemeStored = localStorage.theme
const isLightStored = localStorage.theme === 'light'

if (isLightStored || (!isThemeStored && isLightPreferred)) {
if (!isThemeStored) {
localStorage.setItem('theme', 'light')
}
document.documentElement.classList.remove('dark')
setCurrentTheme('light')
return
}

document.documentElement.classList.remove('dark')
setCurrentTheme('light')
if (!isThemeStored) {
localStorage.setItem('theme', 'dark')
}
document.documentElement.classList.add('dark')
setCurrentTheme('dark')
}, [])

const toggleThemeHandler = useCallback(() => {
Expand Down
1 change: 1 addition & 0 deletions src/utils/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './time'
File renamed without changes.

0 comments on commit 43e79df

Please sign in to comment.