Merge branch 'dev'
This commit is contained in:
+21
-20
@@ -39,13 +39,13 @@
|
||||
"@codemirror/state": "6.2.1",
|
||||
"@codemirror/theme-one-dark": "6.1.2",
|
||||
"@codemirror/view": "6.16.0",
|
||||
"@crossbell/connect-kit": "1.5.7",
|
||||
"@crossbell/contract": "1.5.6",
|
||||
"@crossbell/indexer": "1.5.6",
|
||||
"@crossbell/notification": "1.5.7",
|
||||
"@crossbell/ui": "1.5.6",
|
||||
"@crossbell/util-hooks": "1.5.6",
|
||||
"@crossbell/util-metadata": "1.5.6",
|
||||
"@crossbell/connect-kit": "1.5.8",
|
||||
"@crossbell/contract": "1.5.8",
|
||||
"@crossbell/indexer": "1.5.8",
|
||||
"@crossbell/notification": "1.5.8",
|
||||
"@crossbell/ui": "1.5.8",
|
||||
"@crossbell/util-hooks": "1.5.8",
|
||||
"@crossbell/util-metadata": "1.5.8",
|
||||
"@ddietr/codemirror-themes": "1.4.2",
|
||||
"@dqbd/tiktoken": "1.0.7",
|
||||
"@emoji-mart/data": "1.1.2",
|
||||
@@ -89,19 +89,20 @@
|
||||
"jsdom": "22.1.0",
|
||||
"jsonfeed-to-rss": "3.0.7",
|
||||
"katex": "0.16.8",
|
||||
"langchain": "0.0.127",
|
||||
"langchain": "0.0.129",
|
||||
"lottie-react": "2.4.0",
|
||||
"mdast-util-to-hast": "12.3.0",
|
||||
"mdast-util-toc": "7.0.0",
|
||||
"medium-zoom": "1.0.8",
|
||||
"mermaid": "10.3.1",
|
||||
"nanoid": "4.0.2",
|
||||
"next": "13.4.12",
|
||||
"next": "13.4.16",
|
||||
"next-themes": "0.2.1",
|
||||
"node-id3": "0.2.6",
|
||||
"open-graph-scraper": "^6.2.2",
|
||||
"pangu": "4.0.7",
|
||||
"path-to-regexp": "6.2.1",
|
||||
"pinyin-pro": "3.16.2",
|
||||
"pinyin-pro": "3.16.3",
|
||||
"plaiceholder": "3.0.0",
|
||||
"prismjs": "1.29.0",
|
||||
"qier-progress": "1.0.4",
|
||||
@@ -116,7 +117,7 @@
|
||||
"react-popper": "2.3.0",
|
||||
"react-sortablejs": "6.1.4",
|
||||
"react-string-replace": "1.1.1",
|
||||
"react-tweet": "3.1.0",
|
||||
"react-tweet": "3.1.1",
|
||||
"react-virtuoso": "4.5.0",
|
||||
"refractor": "4.8.1",
|
||||
"rehype-autolink-headings": "6.1.1",
|
||||
@@ -141,7 +142,7 @@
|
||||
"remark-stringify": "10.0.3",
|
||||
"remove-markdown": "0.5.0",
|
||||
"serialize-javascript": "6.0.1",
|
||||
"sharp": "0.32.4",
|
||||
"sharp": "0.32.5",
|
||||
"sortablejs": "1.15.0",
|
||||
"swiper": "^10.1.0",
|
||||
"tailwind-merge": "1.14.0",
|
||||
@@ -158,7 +159,7 @@
|
||||
},
|
||||
"devDependencies": {
|
||||
"@iconify/tailwind": "0.1.3",
|
||||
"@next/bundle-analyzer": "13.4.13",
|
||||
"@next/bundle-analyzer": "13.4.16",
|
||||
"@trivago/prettier-plugin-sort-imports": "4.2.0",
|
||||
"@types/async-lock": "1.4.0",
|
||||
"@types/canvas-confetti": "1.6.0",
|
||||
@@ -169,7 +170,7 @@
|
||||
"@types/katex": "0.16.2",
|
||||
"@types/mdast": "4.0.0",
|
||||
"@types/mjml": "4.7.1",
|
||||
"@types/node": "20.4.10",
|
||||
"@types/node": "20.5.0",
|
||||
"@types/pangu": "4.0.0",
|
||||
"@types/prismjs": "1.26.0",
|
||||
"@types/react": "18.2.20",
|
||||
@@ -180,21 +181,21 @@
|
||||
"@types/sortablejs": "1.15.1",
|
||||
"@types/ua-parser-js": "0.7.36",
|
||||
"@types/uuid": "9.0.2",
|
||||
"autoprefixer": "10.4.14",
|
||||
"autoprefixer": "10.4.15",
|
||||
"babel-loader": "9.1.3",
|
||||
"cspell": "7.0.0",
|
||||
"esbuild": "0.19.1",
|
||||
"esbuild": "0.19.2",
|
||||
"esbuild-register": "3.4.2",
|
||||
"eslint": "8.47.0",
|
||||
"eslint-config-next": "13.4.13",
|
||||
"eslint-config-next": "13.4.16",
|
||||
"eslint-plugin-import": "2.28.0",
|
||||
"eslint-plugin-react": "7.33.1",
|
||||
"eslint-plugin-react": "7.33.2",
|
||||
"eslint-plugin-unused-imports": "3.0.0",
|
||||
"husky": "8.0.3",
|
||||
"lint-staged": "13.2.3",
|
||||
"lint-staged": "14.0.0",
|
||||
"postcss-import": "15.1.0",
|
||||
"postcss-prune-var": "1.1.1",
|
||||
"prettier": "3.0.1",
|
||||
"prettier": "3.0.2",
|
||||
"prettier-package-json": "2.8.0",
|
||||
"prisma": "5.1.1",
|
||||
"tailwindcss": "3.3.3",
|
||||
|
||||
Generated
+646
-924
File diff suppressed because it is too large
Load Diff
@@ -43,7 +43,7 @@ export default async function HomeLayout({
|
||||
<footer className="mt-10 font-medium border-t">
|
||||
<div className="max-w-screen-xl px-5 py-14 mx-auto flex flex-col sm:flex-row justify-between">
|
||||
<PromotionLinks className="w-full sm:w-72" />
|
||||
<span className="inline-flex items-center space-x-4 mx-auto sm:mx-0 mt-10 sm:mt-0">
|
||||
<span className="inline-flex items-center space-y-4 sm:space-y-0 sm:space-x-4 mx-auto sm:mx-0 mt-10 sm:mt-0 flex-col sm:flex-row">
|
||||
<DarkModeSwitch />
|
||||
<span>
|
||||
©{" "}
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
"use client"
|
||||
|
||||
import { useServerInsertedHTML } from "next/navigation"
|
||||
|
||||
import {
|
||||
COLOR_SCHEME_DARK,
|
||||
COLOR_SCHEME_LIGHT,
|
||||
@@ -9,40 +7,27 @@ import {
|
||||
} from "~/lib/constants"
|
||||
|
||||
export const ColorSchemeInjector = () => {
|
||||
useServerInsertedHTML(() => {
|
||||
return (
|
||||
<script
|
||||
dangerouslySetInnerHTML={{
|
||||
__html: `(() => {
|
||||
return (
|
||||
<script
|
||||
dangerouslySetInnerHTML={{
|
||||
__html: `(() => {
|
||||
let DARK_MODE_STORAGE_KEY = "${DARK_MODE_STORAGE_KEY}";
|
||||
let namespace = "xlog"
|
||||
let getStorage = (key) => {
|
||||
let data = {}
|
||||
try {
|
||||
data = JSON.parse(localStorage.getItem(namespace) || "{}")
|
||||
} catch (error) {}
|
||||
return data[key]
|
||||
}
|
||||
let COLOR_SCHEME_LIGHT = "${COLOR_SCHEME_LIGHT}";
|
||||
let COLOR_SCHEME_DARK = "${COLOR_SCHEME_DARK}";
|
||||
|
||||
let data = {}
|
||||
const isDark = getStorage(DARK_MODE_STORAGE_KEY)
|
||||
const isDark = localStorage.getItem(DARK_MODE_STORAGE_KEY)
|
||||
if (typeof isDark === "undefined") {
|
||||
const currentColorScheme = window.matchMedia("(prefers-color-scheme: dark)")
|
||||
.matches
|
||||
? COLOR_SCHEME_DARK
|
||||
: COLOR_SCHEME_LIGHT
|
||||
? "${COLOR_SCHEME_DARK}"
|
||||
: "${COLOR_SCHEME_LIGHT}"
|
||||
document.documentElement.classList.add(currentColorScheme)
|
||||
} else {
|
||||
document.documentElement.classList.add(
|
||||
isDark === "true" ? COLOR_SCHEME_DARK : COLOR_SCHEME_LIGHT,
|
||||
isDark === "true" ? "${COLOR_SCHEME_DARK}" : "${COLOR_SCHEME_LIGHT}",
|
||||
)
|
||||
}
|
||||
})();`,
|
||||
}}
|
||||
></script>
|
||||
)
|
||||
})
|
||||
return null
|
||||
}}
|
||||
></script>
|
||||
)
|
||||
}
|
||||
|
||||
+5
-2
@@ -15,6 +15,7 @@ import {
|
||||
APP_SLOGAN,
|
||||
SITE_URL,
|
||||
UMAMI_ID,
|
||||
UMAMI_SCRIPT,
|
||||
} from "~/lib/env"
|
||||
import { getColorScheme } from "~/lib/get-color-scheme"
|
||||
|
||||
@@ -115,7 +116,9 @@ export default function RootLayout({
|
||||
className={colorScheme}
|
||||
suppressHydrationWarning
|
||||
>
|
||||
<ColorSchemeInjector />
|
||||
<head>
|
||||
<ColorSchemeInjector />
|
||||
</head>
|
||||
<body>
|
||||
<Providers lang={lang}>
|
||||
{modal}
|
||||
@@ -126,7 +129,7 @@ export default function RootLayout({
|
||||
id="xlog-umami-analytics"
|
||||
strategy="afterInteractive"
|
||||
async
|
||||
src="https://analytics.umami.is/script.js?xlog"
|
||||
src={UMAMI_SCRIPT}
|
||||
data-website-id={UMAMI_ID}
|
||||
></Script>
|
||||
</body>
|
||||
|
||||
+28
-20
@@ -1,5 +1,6 @@
|
||||
"use client"
|
||||
|
||||
import { ThemeProvider } from "next-themes"
|
||||
import { useState } from "react"
|
||||
import { WagmiConfig } from "wagmi"
|
||||
|
||||
@@ -11,10 +12,11 @@ import {
|
||||
import { QueryClient, QueryClientProvider } from "@tanstack/react-query"
|
||||
|
||||
import { ModalStackProvider } from "~/components/ui/ModalStack"
|
||||
import { useDarkModeListener } from "~/hooks/useDarkMode"
|
||||
// eslint-disable-next-line import/no-unresolved
|
||||
import { useDarkMode } from "~/hooks/useDarkMode"
|
||||
import { useMobileLayout } from "~/hooks/useMobileLayout"
|
||||
import { useNProgress } from "~/hooks/useNProgress"
|
||||
import { DARK_MODE_STORAGE_KEY } from "~/lib/constants"
|
||||
import { APP_NAME, WALLET_CONNECT_V2_PROJECT_ID } from "~/lib/env"
|
||||
import { filterNotificationCharacter } from "~/lib/filter-character"
|
||||
import { toGateway } from "~/lib/ipfs-parser"
|
||||
@@ -42,31 +44,37 @@ export default function Providers({
|
||||
children: React.ReactNode
|
||||
lang: string
|
||||
}) {
|
||||
useDarkMode()
|
||||
useMobileLayout()
|
||||
useNProgress()
|
||||
useDarkModeListener()
|
||||
|
||||
const [queryClient] = useState(createQueryClient)
|
||||
|
||||
return (
|
||||
<WagmiConfig config={wagmiConfig}>
|
||||
<QueryClientProvider client={queryClient}>
|
||||
<ConnectKitProvider
|
||||
ipfsLinkToHttpLink={toGateway}
|
||||
urlComposer={urlComposer}
|
||||
signInStrategy="simple"
|
||||
ignoreWalletDisconnectEvent={true}
|
||||
>
|
||||
<LangProvider lang={lang}>
|
||||
<ModalStackProvider>{children}</ModalStackProvider>
|
||||
</LangProvider>
|
||||
<ThemeProvider
|
||||
disableTransitionOnChange
|
||||
storageKey={DARK_MODE_STORAGE_KEY}
|
||||
attribute="class"
|
||||
>
|
||||
<WagmiConfig config={wagmiConfig}>
|
||||
<QueryClientProvider client={queryClient}>
|
||||
<ConnectKitProvider
|
||||
ipfsLinkToHttpLink={toGateway}
|
||||
urlComposer={urlComposer}
|
||||
signInStrategy="simple"
|
||||
ignoreWalletDisconnectEvent={true}
|
||||
>
|
||||
<LangProvider lang={lang}>
|
||||
<ModalStackProvider>{children}</ModalStackProvider>
|
||||
</LangProvider>
|
||||
|
||||
<NotificationModal
|
||||
colorScheme={colorScheme}
|
||||
filter={filterNotificationCharacter}
|
||||
/>
|
||||
</ConnectKitProvider>
|
||||
</QueryClientProvider>
|
||||
</WagmiConfig>
|
||||
<NotificationModal
|
||||
colorScheme={colorScheme}
|
||||
filter={filterNotificationCharacter}
|
||||
/>
|
||||
</ConnectKitProvider>
|
||||
</QueryClientProvider>
|
||||
</WagmiConfig>
|
||||
</ThemeProvider>
|
||||
)
|
||||
}
|
||||
|
||||
@@ -1,34 +1,135 @@
|
||||
"use client"
|
||||
|
||||
import { Switch } from "@headlessui/react"
|
||||
import { useTheme } from "next-themes"
|
||||
import { MouseEvent } from "react"
|
||||
|
||||
import { useDarkModeSwitch, useIsDark } from "~/hooks/useDarkMode"
|
||||
import { useIsClient } from "~/hooks/useClient"
|
||||
import { cn } from "~/lib/utils"
|
||||
|
||||
export const DarkModeSwitch = () => {
|
||||
const toggle = useDarkModeSwitch()
|
||||
const isDark = useIsDark()
|
||||
return (
|
||||
<Switch
|
||||
checked={isDark || false}
|
||||
onClick={(e) => toggle(e)}
|
||||
className={cn(
|
||||
`${isDark ? "bg-accent" : "bg-gray-200"}`,
|
||||
` relative inline-flex h-6 w-11 items-center rounded-full text-base dark:text-always-gray-200 text-always-gray-700 align-middle`,
|
||||
)}
|
||||
>
|
||||
<span className="sr-only">Switch Dark Mode</span>
|
||||
<span
|
||||
className={`${
|
||||
isDark ? "translate-x-6" : "translate-x-1"
|
||||
} inline-block h-4 w-4 transform rounded-full bg-white transition`}
|
||||
/>
|
||||
const styles = {
|
||||
base: " rounded-inherit inline-flex h-[24px] w-[24px] items-center justify-center border-0 text-current",
|
||||
}
|
||||
|
||||
{isDark ? (
|
||||
<i className="icon-[mingcute--moon-line] translate-x-2 scale-75" />
|
||||
) : (
|
||||
<i className="icon-[mingcute--sun-line] scale-75 -translate-x-3" />
|
||||
const ThemeIndicator = () => {
|
||||
const { theme } = useTheme()
|
||||
|
||||
const isClient = useIsClient()
|
||||
|
||||
if (!isClient) return null
|
||||
if (!theme) return null
|
||||
return (
|
||||
<div
|
||||
className={cn(
|
||||
"absolute top-[3px] bottom-[3px] aspect-square rounded-full bg-white shadow duration-200 transition-[left]",
|
||||
{
|
||||
"left-[3px]": theme === "light",
|
||||
"left-[27px]": theme === "system",
|
||||
"left-[51px]": theme === "dark",
|
||||
},
|
||||
)}
|
||||
</Switch>
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
const ThemeSwitcher = () => {
|
||||
const { setTheme } = useTheme()
|
||||
|
||||
const buildThemeTransition = (
|
||||
e: MouseEvent,
|
||||
theme: "light" | "dark" | "system",
|
||||
) => {
|
||||
return setTheme(theme)
|
||||
// disable in https://github.com/Crossbell-Box/xLog/commit/06713c901e90b57de6f5f5a0252d2c9dd874335f
|
||||
if (
|
||||
!("startViewTransition" in document) ||
|
||||
window.matchMedia(`(prefers-reduced-motion: reduce)`).matches
|
||||
) {
|
||||
setTheme(theme)
|
||||
return
|
||||
}
|
||||
|
||||
const $document = document.documentElement
|
||||
|
||||
const { x, y } = e.currentTarget.getBoundingClientRect()
|
||||
|
||||
const endRadius = Math.hypot(
|
||||
Math.max(x, window.innerWidth - x),
|
||||
Math.max(y, window.innerHeight - y),
|
||||
)
|
||||
|
||||
document
|
||||
.startViewTransition(() => {
|
||||
return Promise.resolve()
|
||||
})
|
||||
?.ready.then(() => {
|
||||
setTheme(theme)
|
||||
|
||||
if (x === 0) return
|
||||
const clipPath = [
|
||||
`circle(0px at ${x}px ${y}px)`,
|
||||
`circle(${endRadius}px at ${x}px ${y}px)`,
|
||||
]
|
||||
|
||||
$document.animate(
|
||||
{
|
||||
clipPath,
|
||||
},
|
||||
{
|
||||
duration: 300,
|
||||
easing: "ease-in",
|
||||
pseudoElement: "::view-transition-new(root)",
|
||||
// pseudoElement: darkMode
|
||||
// ? "::view-transition-old(root)"
|
||||
// : "::view-transition-new(root)",
|
||||
},
|
||||
)
|
||||
})
|
||||
}
|
||||
|
||||
return (
|
||||
<div
|
||||
role="radiogroup"
|
||||
className="w-fit-content inline-flex rounded-full p-[3px] bg-zinc-200/80 text-xs"
|
||||
>
|
||||
<button
|
||||
aria-label="Switch to light theme"
|
||||
type="button"
|
||||
className={styles.base}
|
||||
onClick={(e) => {
|
||||
buildThemeTransition(e, "light")
|
||||
}}
|
||||
>
|
||||
<i className="icon-[mingcute--sun-line]" />
|
||||
</button>
|
||||
<button
|
||||
aria-label="Switch to system theme"
|
||||
className={styles.base}
|
||||
type="button"
|
||||
onClick={(e) => {
|
||||
buildThemeTransition(e, "system")
|
||||
}}
|
||||
>
|
||||
<i className="icon-[mingcute--computer-line]" />
|
||||
</button>
|
||||
<button
|
||||
aria-label="Switch to dark theme"
|
||||
className={styles.base}
|
||||
type="button"
|
||||
onClick={(e) => {
|
||||
buildThemeTransition(e, "dark")
|
||||
}}
|
||||
>
|
||||
<i className="icon-[mingcute--moon-line]" />
|
||||
</button>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
export const DarkModeSwitch = () => {
|
||||
return (
|
||||
<div className="relative">
|
||||
<ThemeIndicator />
|
||||
<ThemeSwitcher />
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
@@ -18,7 +18,7 @@ export default function ConnectedAccounts({
|
||||
{!!connectedAccounts?.length && (
|
||||
<div
|
||||
className={cn(
|
||||
"xlog-social-platforms align-middle inline-flex items-center pt-1",
|
||||
"xlog-social-platforms align-middle inline-flex items-center",
|
||||
className,
|
||||
)}
|
||||
>
|
||||
|
||||
@@ -31,7 +31,7 @@ export default async function SiteFooter({
|
||||
return (
|
||||
<>
|
||||
<footer className="text-zinc-500 border-t">
|
||||
<div className="max-w-screen-lg mx-auto px-5 py-10 text-xs sm:flex justify-between sm:space-x-5 sm:space-y-0 space-y-5">
|
||||
<div className="max-w-screen-lg mx-auto px-5 py-10 text-xs sm:flex justify-between sm:space-x-5 sm:space-y-0 space-y-5 sm:items-center">
|
||||
<div className="font-medium text-base">
|
||||
<span>© </span>
|
||||
<UniLink href="/" className="hover:text-accent">
|
||||
|
||||
+16
-216
@@ -1,231 +1,31 @@
|
||||
import { MouseEvent, useEffect, useRef, useState } from "react"
|
||||
import { create } from "zustand"
|
||||
import { useTheme } from "next-themes"
|
||||
import { useEffect } from "react"
|
||||
|
||||
import {
|
||||
COLOR_SCHEME_DARK,
|
||||
COLOR_SCHEME_LIGHT,
|
||||
DARK_MODE_STORAGE_KEY,
|
||||
DEFAULT_COLOR_SCHEME,
|
||||
IS_DEV,
|
||||
} from "~/lib/constants"
|
||||
import { COLOR_SCHEME_DARK, COLOR_SCHEME_LIGHT, IS_DEV } from "~/lib/constants"
|
||||
import { OUR_DOMAIN } from "~/lib/env"
|
||||
import { noop } from "~/lib/noop"
|
||||
import { delStorage, getStorage, setStorage } from "~/lib/storage"
|
||||
import { isServerSide } from "~/lib/utils"
|
||||
|
||||
import { useGetState } from "./useGetState"
|
||||
|
||||
interface IMediaStore {
|
||||
isDark: boolean
|
||||
toggle: (e: MouseEvent) => void
|
||||
}
|
||||
|
||||
const useMediaStore = create<IMediaStore>(() => {
|
||||
return {
|
||||
isDark: DEFAULT_COLOR_SCHEME === COLOR_SCHEME_DARK,
|
||||
toggle: () => void 0,
|
||||
}
|
||||
})
|
||||
|
||||
interface DarkModeConfig {
|
||||
classNameDark?: string // A className to set "dark mode". Default = "dark".
|
||||
classNameLight?: string // A className to set "light mode". Default = "light".
|
||||
element?: HTMLElement | undefined | null // The element to apply the className. Default = `document.body`.
|
||||
transition?: ViewTransition | undefined // Specify the `animate` when switching the mode. Only Chromium >= 111 etc.
|
||||
}
|
||||
|
||||
const useDarkModeInternal = (
|
||||
initialState: boolean | undefined,
|
||||
options: DarkModeConfig,
|
||||
) => {
|
||||
const {
|
||||
classNameDark = COLOR_SCHEME_DARK,
|
||||
classNameLight = COLOR_SCHEME_LIGHT,
|
||||
element,
|
||||
transition,
|
||||
} = options
|
||||
|
||||
const [darkMode, setDarkMode] = useState(initialState)
|
||||
const [mousePosition, setMousePosition] = useState({ x: 0, y: 0 })
|
||||
|
||||
export const useDarkModeListener = () => {
|
||||
const { theme, systemTheme } = useTheme()
|
||||
useEffect(() => {
|
||||
const presentedDarkMode =
|
||||
!isServerSide() && getStorage(DARK_MODE_STORAGE_KEY)
|
||||
if (theme === "system") {
|
||||
// delete cookie
|
||||
document.cookie = IS_DEV
|
||||
? `color_scheme=;`
|
||||
: `color_scheme=; Domain=.${OUR_DOMAIN}; Path=/; Secure; expires=Thu, 01 Jan 1970 00:00:00 GMT`
|
||||
|
||||
if (presentedDarkMode !== undefined) {
|
||||
setDarkMode(presentedDarkMode === "true")
|
||||
} else if (typeof initialState === "undefined") {
|
||||
setDarkMode(window.matchMedia("(prefers-color-scheme: dark)").matches)
|
||||
}
|
||||
}, [])
|
||||
|
||||
useEffect(() => {
|
||||
const handler = (e: MediaQueryListEvent) => {
|
||||
const storageValue = getStorage(DARK_MODE_STORAGE_KEY)
|
||||
const parseStorageValueAsBool = storageValue === "true"
|
||||
setDarkMode(e.matches)
|
||||
|
||||
// reset dark mode, follow system
|
||||
if (parseStorageValueAsBool === e.matches) {
|
||||
delStorage(DARK_MODE_STORAGE_KEY)
|
||||
}
|
||||
}
|
||||
|
||||
const storageHandler = () => {
|
||||
const storageValue = getStorage(DARK_MODE_STORAGE_KEY, true)
|
||||
// if not storage color mode, switch to follow system
|
||||
if (storageValue === undefined) {
|
||||
setDarkMode(window.matchMedia("(prefers-color-scheme: dark)").matches)
|
||||
} else {
|
||||
// make multiple pages to switch to dark mode together.
|
||||
setDarkMode(storageValue === "true")
|
||||
}
|
||||
}
|
||||
|
||||
window.addEventListener("storage", storageHandler)
|
||||
window
|
||||
.matchMedia("(prefers-color-scheme: dark)")
|
||||
.addEventListener("change", handler)
|
||||
|
||||
return () => {
|
||||
window.removeEventListener("storage", storageHandler)
|
||||
window
|
||||
.matchMedia("(prefers-color-scheme: dark)")
|
||||
.removeEventListener("change", handler)
|
||||
}
|
||||
}, [])
|
||||
|
||||
const getDarkMode = useGetState(darkMode)
|
||||
useEffect(() => {
|
||||
const handler = () => {
|
||||
// if set color mode follow system, del storage
|
||||
if (
|
||||
window.matchMedia("(prefers-color-scheme: dark)").matches ===
|
||||
getDarkMode()
|
||||
) {
|
||||
delStorage(DARK_MODE_STORAGE_KEY)
|
||||
}
|
||||
}
|
||||
window.addEventListener("beforeunload", handler)
|
||||
|
||||
return () => {
|
||||
window.removeEventListener("beforeunload", handler)
|
||||
}
|
||||
}, [])
|
||||
useEffect(() => {
|
||||
if (isServerSide() || typeof darkMode === "undefined") {
|
||||
return
|
||||
}
|
||||
const $document = element || document.documentElement
|
||||
const setDarkModeClass = () => {
|
||||
if (darkMode) {
|
||||
$document.classList.remove(classNameLight)
|
||||
$document.classList.add(classNameDark)
|
||||
} else {
|
||||
$document.classList.remove(classNameDark)
|
||||
$document.classList.add(classNameLight)
|
||||
}
|
||||
}
|
||||
|
||||
const { x, y } = mousePosition
|
||||
const endRadius = Math.hypot(
|
||||
Math.max(x, innerWidth - x),
|
||||
Math.max(y, innerHeight - y),
|
||||
)
|
||||
transition?.ready.then(() => {
|
||||
setDarkModeClass()
|
||||
if (mousePosition.x === 0) return
|
||||
const clipPath = [
|
||||
`circle(0px at ${x}px ${y}px)`,
|
||||
`circle(${endRadius}px at ${x}px ${y}px)`,
|
||||
]
|
||||
$document.animate(
|
||||
{
|
||||
clipPath: !darkMode ? clipPath : [...clipPath].reverse(),
|
||||
},
|
||||
{
|
||||
duration: 400,
|
||||
easing: "ease-in-out",
|
||||
pseudoElement: darkMode
|
||||
? "::view-transition-old(root)"
|
||||
: "::view-transition-new(root)",
|
||||
},
|
||||
)
|
||||
}) ?? setDarkModeClass()
|
||||
}, [classNameDark, classNameLight, darkMode, element])
|
||||
|
||||
if (isServerSide()) {
|
||||
return {
|
||||
toggle: () => {},
|
||||
value: false,
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
value: darkMode,
|
||||
toggle: (e: MouseEvent) => {
|
||||
setDarkMode((d) => {
|
||||
if (DARK_MODE_STORAGE_KEY && !isServerSide()) {
|
||||
setStorage(DARK_MODE_STORAGE_KEY, String(!d))
|
||||
setMousePosition({ x: e.clientX, y: e.clientY })
|
||||
}
|
||||
return !d
|
||||
})
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
const mockElement = {
|
||||
classList: {
|
||||
add: noop,
|
||||
remove: noop,
|
||||
},
|
||||
}
|
||||
|
||||
export const useDarkMode = () => {
|
||||
const { toggle, value } = useDarkModeInternal(
|
||||
getStorage(DARK_MODE_STORAGE_KEY) === undefined
|
||||
? undefined
|
||||
: getStorage(DARK_MODE_STORAGE_KEY) === "true",
|
||||
{
|
||||
classNameDark: COLOR_SCHEME_DARK,
|
||||
classNameLight: COLOR_SCHEME_LIGHT,
|
||||
element: (globalThis.document && document.documentElement) || mockElement,
|
||||
// transition:
|
||||
// !isServerSide() &&
|
||||
// !!document.startViewTransition &&
|
||||
// !window.matchMedia(`(prefers-reduced-motion: reduce)`).matches
|
||||
// ? document.startViewTransition()
|
||||
// : undefined,
|
||||
},
|
||||
)
|
||||
|
||||
useEffect(() => {
|
||||
useMediaStore.setState({
|
||||
isDark: value,
|
||||
})
|
||||
const colorScheme = value ? COLOR_SCHEME_DARK : COLOR_SCHEME_LIGHT
|
||||
const isDarkMode = theme === "dark"
|
||||
const colorScheme = isDarkMode ? COLOR_SCHEME_DARK : COLOR_SCHEME_LIGHT
|
||||
const date = new Date()
|
||||
date.setMonth(date.getMonth() + 1)
|
||||
document.cookie = IS_DEV
|
||||
? `color_scheme=${colorScheme};`
|
||||
: `color_scheme=${colorScheme}; Domain=.${OUR_DOMAIN}; Path=/; Secure; expires=${date.toUTCString()}`
|
||||
}, [value])
|
||||
|
||||
const onceRef = useRef(false)
|
||||
if (!onceRef.current) {
|
||||
onceRef.current = true
|
||||
useMediaStore.setState({ toggle })
|
||||
}
|
||||
|
||||
return {
|
||||
toggle,
|
||||
value,
|
||||
}
|
||||
}, [theme, systemTheme])
|
||||
}
|
||||
|
||||
export const useIsDark = () => useMediaStore((state) => state.isDark)
|
||||
|
||||
export const useDarkModeSwitch = () => {
|
||||
return useMediaStore((state) => state.toggle)
|
||||
export const useIsDark = () => {
|
||||
const { theme, systemTheme } = useTheme()
|
||||
return theme === "dark" || (theme === "system" && systemTheme === "dark")
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@ import { pinyin } from "pinyin-pro"
|
||||
|
||||
export const getDefaultSlug = (title: string, id?: string) => {
|
||||
let generated =
|
||||
pinyin(title, {
|
||||
pinyin(String(title), {
|
||||
toneType: "none",
|
||||
type: "array",
|
||||
nonZh: "consecutive",
|
||||
|
||||
+3
-1
@@ -35,4 +35,6 @@ export const WALLET_CONNECT_V2_PROJECT_ID =
|
||||
export const DEFAULT_AVATAR =
|
||||
"ipfs://bafkreiabgixxp63pg64moxnsydz7hewmpdkxxi3kdsa4oqv4pb6qvwnmxa"
|
||||
export const UMAMI_ID =
|
||||
process.env.NEXT_PUBLIC_UMAMI_ID || "4f03105b-1d0d-4e49-823b-0342861c51de"
|
||||
process.env.NEXT_PUBLIC_UMAMI_ID || "c2a15ccb-dba8-4763-b4a7-0e0edf5a8857"
|
||||
export const UMAMI_SCRIPT =
|
||||
process.env.NEXT_PUBLIC_UMAMI_SCRIPT || "https://umami.rss3.io/umami"
|
||||
|
||||
Reference in New Issue
Block a user