refactor: 提取 useGeolocation hook 和 joinRoom 工具函数
- useGeolocation: 将 PanicPage 中 ~50 行 GPS 定位逻辑(requestGps + reverseGeocode + 状态管理)提取为独立 hook - joinRoom: 统一 3 处重复的 POST /api/room/:id/join 调用(room、invite、panic 页面)
This commit is contained in:
@@ -12,6 +12,7 @@ import {
|
||||
Coffee,
|
||||
} from "lucide-react";
|
||||
import { getUserId } from "@/lib/userId";
|
||||
import { joinRoom } from "@/lib/room";
|
||||
import { Skeleton, SkeletonCircle } from "@/components/Skeleton";
|
||||
import Button from "@/components/Button";
|
||||
import { getSceneConfig } from "@/lib/sceneConfig";
|
||||
@@ -48,12 +49,7 @@ export default function InvitePage() {
|
||||
const handleJoin = async () => {
|
||||
setJoining(true);
|
||||
try {
|
||||
const userId = getUserId();
|
||||
await fetch(`/api/room/${roomId}/join`, {
|
||||
method: "POST",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify({ userId }),
|
||||
});
|
||||
await joinRoom(roomId, getUserId());
|
||||
router.push(`/room/${roomId}`);
|
||||
} catch {
|
||||
setJoining(false);
|
||||
|
||||
Reference in New Issue
Block a user