💄 Better UX

This commit is contained in:
2024-02-25 01:36:12 +08:00
parent 743c007806
commit 6916d208c0
8 changed files with 87 additions and 5 deletions

View File

@@ -38,7 +38,7 @@ export interface NavigationItem {
export const DRAWER_WIDTH = 320;
export const NAVIGATION_ITEMS: NavigationItem[] = [
{ icon: <HomeIcon />, title: "首页", link: "/" },
{ icon: <ArticleIcon />, title: "新闻", link: "/posts" },
{ icon: <ArticleIcon />, title: "博客", link: "/posts" },
{
icon: <InfoIcon />, title: "信息中心", children: [
{ icon: <GavelIcon />, title: "用户协议", link: "/i/user-agreement" },

View File

@@ -0,0 +1,30 @@
"use client";
import { useEffect, useRef } from "react";
import Zoomist from "zoomist";
import "zoomist/css";
export default function ImageViewer({ src, alt }: { src: string, alt: string }) {
const container = useRef<HTMLDivElement>(null);
useEffect(() => {
if (container.current) {
new Zoomist(container.current, {
maxScale: 5,
bounds: true,
pinchable: true,
});
}
});
return (
<div ref={container} className="zoomist-container h-fit">
<div className="zoomist-wrapper">
<div className="zoomist-image h-fit">
<img src={src} alt={alt} />
</div>
</div>
</div>
);
}

View File

@@ -1,7 +1,30 @@
"use client";
import { PortableText } from "@portabletext/react";
import { client } from "@/sanity/lib/client";
import imageUrlBuilder from "@sanity/image-url";
import Link from "next/link";
import ImageViewer from "@/components/articles/ImageViewer";
export default function PostContent({ content }: { content: any }) {
return <PortableText value={content} />;
const imageBuilder = imageUrlBuilder(client);
const componentSet = {
types: {
image: ({ value }: any) => {
const image = imageBuilder.image(value);
return <ImageViewer src={image.url()} alt={value.alt} />;
}
},
marks: {
link: ({ children, value }: any) => {
const rel = !value.href.startsWith("/") ? "noreferrer noopener" : undefined;
return (
<Link href={value.href} rel={rel}>
{children}
</Link>
);
}
}
};
return <PortableText value={content} components={componentSet} />;
}