Skip to content

Commit

Permalink
app routes index: remove solo toggle option
Browse files Browse the repository at this point in the history
If players want to play solo they can find the /game/$gameId/solo route
themselves. Otherwise, they can just play without sharing the link to the game.

Keep the route around for debugging purposes.
  • Loading branch information
cmnord committed Jul 12, 2023
1 parent 7b7c683 commit 73036e5
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 50 deletions.
10 changes: 2 additions & 8 deletions app/routes/_index/game-card.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,9 @@ import { GameVisibilityTag } from "~/components/game-visibility-icon";
import { LoadingSpinner } from "~/components/icons";
import type { DbGame } from "~/models/game.server";

export default function GameCard({
game,
solo,
}: {
game: DbGame;
solo: boolean;
}) {
export default function GameCard({ game }: { game: DbGame }) {
const [loading, setLoading] = React.useState(false);
const to = solo ? `/game/${game.id}/solo` : `/game/${game.id}/play`;
const to = `/game/${game.id}/play`;

return (
<button
Expand Down
44 changes: 3 additions & 41 deletions app/routes/_index/route.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,16 @@ import {
useSearchParams,
useSubmit,
} from "@remix-run/react";
import classNames from "classnames";
import * as React from "react";

import {
DefaultErrorBoundary,
ErrorMessage,
SuccessMessage,
} from "~/components/error";
import { LoadingSpinner, QuestionMarkCircle } from "~/components/icons";
import { LoadingSpinner } from "~/components/icons";
import Main from "~/components/main";
import Popover from "~/components/popover";
import Search from "~/components/search";
import Switch from "~/components/switch";
import Upload from "~/components/upload";
import { getValidAuthSession } from "~/models/auth";
import { getGames } from "~/models/game.server";
Expand Down Expand Up @@ -66,10 +63,6 @@ export default function Index() {
const submit = useSubmit();
const navigation = useNavigation();

// Solo toggle
const solo = params.get("solo") === "on";
const [optimisticSolo, setOptimisticSolo] = React.useState(solo);

// Pagination
const gameFetcher = useFetcher<typeof loader>();
const [games, setGames] = React.useState(data.serverGames);
Expand All @@ -80,8 +73,7 @@ export default function Index() {
useScrollToBottom(() => {
if (!shouldLoadMore) return;
const qParam = debouncedSearch ? `&q=${debouncedSearch}` : "";
const soloParam = optimisticSolo ? "&solo=on" : "";
gameFetcher.load(`/?index${qParam}&page=${page}${soloParam}`);
gameFetcher.load(`/?index${qParam}&page=${page}`);

setShouldLoadMore(false);
});
Expand All @@ -108,10 +100,6 @@ export default function Index() {
setShouldLoadMore(true);
}, [data.serverGames]);

React.useEffect(() => {
setOptimisticSolo(solo);
}, [solo]);

React.useEffect(() => {
if (uploadFetcher.state === "submitting") {
// JavaScript to clean messages when submitting
Expand Down Expand Up @@ -148,32 +136,6 @@ export default function Index() {
defaultValue={initialSearch}
loading={navigation.state === "loading"}
/>
<div className="mb-4 flex flex-col flex-wrap justify-between gap-2 sm:flex-row">
<div className="inline-flex items-center gap-3">
<Switch
name="solo"
checked={optimisticSolo}
onClick={(checked) => setOptimisticSolo(checked)}
/>
<div className="inline-flex gap-0.5">
<p
className={classNames("text-sm text-slate-500", {
"font-bold": optimisticSolo,
})}
>
Solo mode {optimisticSolo ? "on" : "off"}
</p>
<Popover content="In solo mode, no other players can join the game. If you refresh the page the game will reset.">
<button type="button">
<QuestionMarkCircle
className={`h-4 w-4 rounded-md text-slate-400
hover:bg-slate-100 hover:text-slate-500`}
/>
</button>
</Popover>
</div>
</div>
</div>
</Form>
<Upload
fetcher={uploadFetcher}
Expand All @@ -195,7 +157,7 @@ export default function Index() {
)}
<div className="mb-4 flex flex-col gap-4 sm:grid sm:grid-cols-2">
{games.map((game, i) => (
<GameCard key={`game-${i}`} game={game} solo={optimisticSolo} />
<GameCard key={`game-${i}`} game={game} />
))}
</div>
{gameFetcher.state === "loading" && (
Expand Down
5 changes: 4 additions & 1 deletion app/routes/game_.$gameId.solo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,10 @@ export async function loader({ request, params }: LoaderArgs) {
}
}

export default function PlayGame() {
/** SoloGame lets a single user play a game without others being able to join. If
* they refresh the page, the game will reset.
*/
export default function SoloGame() {
const data = useLoaderData<typeof loader>();
const matches = useMatches();
const pathname = matches[matches.length - 1].pathname;
Expand Down

1 comment on commit 73036e5

@vercel
Copy link

@vercel vercel bot commented on 73036e5 Jul 12, 2023

Choose a reason for hiding this comment

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

Please sign in to comment.