From f7f9425117b737717064439faf7e9413f17e3ce5 Mon Sep 17 00:00:00 2001 From: hyperzlib Date: Sun, 14 Sep 2025 00:41:51 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0toast=E6=8F=90=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 3 +- package.json | 1 + pnpm-lock.yaml | 15 ++++++++ services/static.go | 4 --- src/components/custom-notification.tsx | 31 ++++++++++++++++ src/components/player.tsx | 14 ++++++++ src/components/ui/textarea.tsx | 21 +++++++++++ src/pages/room/[room].tsx | 50 ++++++++++++++++++++++---- 8 files changed, 128 insertions(+), 11 deletions(-) create mode 100644 src/components/custom-notification.tsx create mode 100644 src/components/ui/textarea.tsx diff --git a/.gitignore b/.gitignore index 9543ca4..5e13b76 100644 --- a/.gitignore +++ b/.gitignore @@ -38,4 +38,5 @@ next-env.d.ts *__debug* movie-sync* -dist \ No newline at end of file +dist +/main diff --git a/package.json b/package.json index 7cce50f..06cae33 100644 --- a/package.json +++ b/package.json @@ -28,6 +28,7 @@ "react": "^18", "react-dom": "^18", "react-icons": "^5.0.1", + "react-toastify": "^11.0.5", "socket.io-client": "^4.7.4", "tailwind-merge": "^2.2.0", "tailwindcss-animate": "^1.0.7" diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 1fbc979..fa1d04f 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -65,6 +65,9 @@ importers: react-icons: specifier: ^5.0.1 version: 5.5.0(react@18.3.1) + react-toastify: + specifier: ^11.0.5 + version: 11.0.5(react-dom@18.3.1(react@18.3.1))(react@18.3.1) socket.io-client: specifier: ^4.7.4 version: 4.8.1 @@ -2449,6 +2452,12 @@ packages: '@types/react': optional: true + react-toastify@11.0.5: + resolution: {integrity: sha512-EpqHBGvnSTtHYhCPLxML05NLY2ZX0JURbAdNYa6BUkk+amz4wbKBQvoKQAB0ardvSarUBuY4Q4s1sluAzZwkmA==} + peerDependencies: + react: ^18 || ^19 + react-dom: ^18 || ^19 + react@18.3.1: resolution: {integrity: sha512-wS+hAgJShR0KhEvPJArfuPVN1+Hz1t0Y6n5jLrGQbkb4urgPE/0Rve+1kMB1v/oWgHgm4WIcV+i7F2pTVj+2iQ==} engines: {node: '>=0.10.0'} @@ -5489,6 +5498,12 @@ snapshots: optionalDependencies: '@types/react': 18.3.23 + react-toastify@11.0.5(react-dom@18.3.1(react@18.3.1))(react@18.3.1): + dependencies: + clsx: 2.1.1 + react: 18.3.1 + react-dom: 18.3.1(react@18.3.1) + react@18.3.1: dependencies: loose-envify: 1.4.0 diff --git a/services/static.go b/services/static.go index 6843b8b..86d53a8 100644 --- a/services/static.go +++ b/services/static.go @@ -32,16 +32,13 @@ func EmbedFolder(fsEmbed embed.FS, targetPath string) static.ServeFileSystem { func FindNextIndexFile(currentPath string, fsys static.ServeFileSystem) string { findPath := strings.TrimSuffix(currentPath, "/") - logrus.Infoln("Finding index file for path:", findPath) testFile := findPath + ".html" - logrus.Infoln("Checking for HTML file:", testFile) if fsys.Exists("", testFile) { return testFile } testFile = findPath + "/index.html" - logrus.Infoln("Checking for index file:", testFile) if fsys.Exists("", testFile) { return testFile } @@ -60,7 +57,6 @@ func FindNextIndexFile(currentPath string, fsys static.ServeFileSystem) string { endfix := findPath[lastSlash+1:] testFile = findPath + "/[" + endfix + "].html" - logrus.Infoln("Checking for dynamic route file:", testFile) if fsys.Exists("", testFile) { return testFile } diff --git a/src/components/custom-notification.tsx b/src/components/custom-notification.tsx new file mode 100644 index 0000000..5fa4699 --- /dev/null +++ b/src/components/custom-notification.tsx @@ -0,0 +1,31 @@ +import { ToastContentProps } from "react-toastify"; +import { cn } from "@/lib/utils" + +type CustomNotificationProps = ToastContentProps<{ + title: string; + content: string; +}>; + +export function CustomNotification({ + closeToast, + data, + toastProps, +}: CustomNotificationProps) { + const isColored = toastProps.theme === 'colored'; + + return ( +
+

+ {data.title} +

+
+

{data.content}

+
+
+ ); +} \ No newline at end of file diff --git a/src/components/player.tsx b/src/components/player.tsx index a9671c7..78be399 100644 --- a/src/components/player.tsx +++ b/src/components/player.tsx @@ -4,6 +4,8 @@ import { ClientMessage, ClientUserStatus, RoomState, RoomStateChangedMessage, Se import { $playerState, $userInfo, $userStatus } from '@/store/player' import { useStore as useNanoStore } from '@nanostores/react' import { getUserPlayTimeSeconds, unixTimestampWithOffset } from '@/lib/utils' +import { toast } from 'react-toastify' +import { CustomNotification } from './custom-notification' const TIME_SYNC_ALLOWANCE = 5 // 如果播放时间与服务器时间差小于此值,则认为是同步的 @@ -94,6 +96,18 @@ export const Player = ({ roomName }: { roomName: string }) => { room: roomName, username: $userInfo.value.username, } as ClientMessage) + } else { + // 如果是普通用户,检测是否可以开始播放 + if (!prevRoomState.current.playing) { + player.current.pause() + + toast.info(CustomNotification, { + data: { + title: '提示', + content: '已准备好播放,正在等待房管开始播放...' + } + }); + } } // 标记用户开始播放 diff --git a/src/components/ui/textarea.tsx b/src/components/ui/textarea.tsx new file mode 100644 index 0000000..e85f023 --- /dev/null +++ b/src/components/ui/textarea.tsx @@ -0,0 +1,21 @@ +import * as React from "react" + +import { cn } from "@/lib/utils" + +export interface TextAreaProps + extends React.TextareaHTMLAttributes {} + +export const TextArea = React.forwardRef( + ({ className, ...props }, ref) => { + return ( +