Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FE] fix: 대기방 새로고침 기능 수정 #319

Merged
merged 2 commits into from
Dec 4, 2024
Merged
Show file tree
Hide file tree
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
12 changes: 11 additions & 1 deletion FE/src/features/lobby/GameLobbyPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,16 @@ export const GameLobbyPage = () => {
},
[isLoading, paging]
);
const refreshRooms = useCallback(() => {
if (isLoading) return;
setRooms([]);
setPaging(null);
loadRooms(null);
}, [isLoading, loadRooms]);

useEffect(() => {
loadRooms(null);
}, [loadRooms]);

useEffect(() => {
loadRooms(null);
Expand All @@ -70,7 +80,7 @@ export const GameLobbyPage = () => {
return (
<div className="bg-gradient-to-r from-blue-300 to-indigo-500 min-h-screen flex flex-col items-center justify-center">
<Header />
<LobbyList rooms={rooms} loadRooms={loadRooms} />
<LobbyList rooms={rooms} refreshRooms={refreshRooms} />
{isLoading && <div className="text-center mt-4">Loading...</div>}
</div>
);
Expand Down
6 changes: 3 additions & 3 deletions FE/src/features/lobby/LobbyList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ type Room = {

type LobbyListProps = {
rooms: Room[];
loadRooms: (cursor: string | null, take: number) => Promise<void>;
refreshRooms: () => void;
};
import { useNavigate } from 'react-router-dom';

export const LobbyList: React.FC<LobbyListProps> = ({ rooms, loadRooms }) => {
export const LobbyList: React.FC<LobbyListProps> = ({ rooms, refreshRooms }) => {
const navigate = useNavigate();

const handleJoinRoom = (gameId: string) => {
Expand All @@ -35,7 +35,7 @@ export const LobbyList: React.FC<LobbyListProps> = ({ rooms, loadRooms }) => {
width: '50px',
height: '50px'
}}
onClick={() => loadRooms(null, 10)}
onClick={refreshRooms}
/>
</header>
<div className="grid grid-cols-1 sm:grid-cols-2 md:grid-cols-3 lg:grid-cols-4 gap-8 w-full">
Expand Down
Loading