fix: ssr date render inconsistence
This commit is contained in:
@@ -3,14 +3,25 @@ import { BlockchainIcon } from "~/components/icons/BlockchainIcon"
|
||||
import { UniLink } from "~/components/ui/UniLink"
|
||||
import { Note } from "~/lib/types"
|
||||
import { CSB_SCAN } from "~/lib/env"
|
||||
import { useEffect, useState } from "react"
|
||||
|
||||
export const PostMeta: React.FC<{
|
||||
page: Note
|
||||
}> = ({ page }) => {
|
||||
const [isMounted, setIsMounted] = useState(false)
|
||||
|
||||
useEffect(() => {
|
||||
setIsMounted(true)
|
||||
}, [])
|
||||
|
||||
return (
|
||||
<div className="text-zinc-400 mt-2 xlog-post-meta">
|
||||
<span className="xlog-post-date align-middle">
|
||||
{formatDate(page.date_published)}
|
||||
{formatDate(
|
||||
page.date_published,
|
||||
undefined,
|
||||
isMounted ? undefined : "America/Los_Angeles",
|
||||
)}
|
||||
</span>
|
||||
<span className="xlog-post-tags ml-4 space-x-1 align-middle">
|
||||
{page.tags
|
||||
|
||||
@@ -5,6 +5,7 @@ import { EmptyState } from "../ui/EmptyState"
|
||||
import { useRouter } from "next/router"
|
||||
import { Image } from "~/components/ui/Image"
|
||||
import { Button } from "~/components/ui/Button"
|
||||
import { useEffect, useState } from "react"
|
||||
|
||||
export const SiteHome: React.FC<{
|
||||
postPages?: Notes[]
|
||||
@@ -14,6 +15,12 @@ export const SiteHome: React.FC<{
|
||||
}> = ({ postPages, fetchNextPage, hasNextPage, isFetchingNextPage }) => {
|
||||
const router = useRouter()
|
||||
|
||||
const [isMounted, setIsMounted] = useState(false)
|
||||
|
||||
useEffect(() => {
|
||||
setIsMounted(true)
|
||||
}, [])
|
||||
|
||||
if (!postPages?.length) return null
|
||||
|
||||
let currentLength = 0
|
||||
@@ -38,7 +45,11 @@ export const SiteHome: React.FC<{
|
||||
</h3>
|
||||
<div className="xlog-post-meta text-sm text-zinc-400 mt-1">
|
||||
<span className="xlog-post-date">
|
||||
{formatDate(post.date_published)}
|
||||
{formatDate(
|
||||
post.date_published,
|
||||
undefined,
|
||||
isMounted ? undefined : "America/Los_Angeles",
|
||||
)}
|
||||
</span>
|
||||
<span className="xlog-post-tags ml-4 space-x-1">
|
||||
{post.tags
|
||||
|
||||
+2
-1
@@ -9,8 +9,9 @@ dayjs.extend(tz)
|
||||
export const formatDate = (
|
||||
date: string | Date,
|
||||
format: "MMM D" | "MMM D, YYYY" | "YYYY" = "MMM D, YYYY",
|
||||
timezone?: string,
|
||||
) => {
|
||||
return dayjs(date).format(format)
|
||||
return dayjs(date).tz(timezone).format(format)
|
||||
}
|
||||
|
||||
export const inLocalTimezone = (date: string | Date) => {
|
||||
|
||||
Reference in New Issue
Block a user