Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 15 additions & 3 deletions src/app/coaster/page.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
'use client';

import React, { useState, useEffect, useCallback, useMemo, useRef } from 'react';
import { useRouter } from 'next/navigation';
import { Button } from '@/components/ui/button';
import { CoasterProvider } from '@/context/CoasterContext';
import { MultiplayerContextProvider, useMultiplayerOptional } from '@/context/MultiplayerContext';
Expand Down Expand Up @@ -269,6 +270,7 @@ function SavedParkCard({ park, onLoad, onDelete }: { park: SavedParkMeta; onLoad

function CoasterPageContent() {
const multiplayer = useMultiplayerOptional();
const router = useRouter();
const [showGame, setShowGame] = useState(false);
const [startFresh, setStartFresh] = useState(false);
const [hasSaved, setHasSaved] = useState(false);
Expand Down Expand Up @@ -310,6 +312,15 @@ function CoasterPageContent() {
window.history.replaceState({}, '', '/coaster');
};

const handleBackToIsoCity = useCallback(() => {
multiplayer?.leaveRoom();
setShowGame(false);
setStartFresh(false);
setLoadParkId(null);
setPendingRoomCode(null);
router.push('/');
}, [multiplayer, router, setShowGame, setStartFresh, setLoadParkId, setPendingRoomCode]);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Duplicated cleanup logic between two handler functions

Medium Severity · Code Quality

handleBackToIsoCity duplicates 5 lines of cleanup logic from handleExitGame (lines 306-310). Both functions call multiplayer?.leaveRoom(), setShowGame(false), setStartFresh(false), setLoadParkId(null), and setPendingRoomCode(null). Extract this common cleanup logic into a shared helper function.

Fix in Cursor Fix in Web


const handleDeletePark = (park: SavedParkMeta) => {
const autosaveState = loadCoasterStateFromStorage(COASTER_AUTOSAVE_KEY);
if (autosaveState?.id === park.id) {
Expand Down Expand Up @@ -421,12 +432,13 @@ function CoasterPageContent() {
Load Example
</Button>

<a
href="/"
<button
type="button"
onClick={handleBackToIsoCity}
className="w-full text-center py-2 text-sm font-light tracking-wide text-white/40 hover:text-white/70 transition-colors duration-200"
>
Back to IsoCity
</a>
</button>
<a
href="https://github.com/amilich/isometric-city"
target="_blank"
Expand Down