feat: redesign homepage layout and fix invite links
- Homepage: Grid-Layout mit 3 Karten (Spiel erstellen, KI, Freunde/Beitreten) statt vertikalem Stack mit Dividers - CreateGame: kompakteres Styling, auf Deutsch, in Primary-Card integriert - Einladungslink: APP_URL statt hardcoded ches.su in GamePage und CopyLink - JoinGame: URL-Parsing für beliebige Domains (nicht nur ches.su) Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -22,7 +22,7 @@ import { Chess } from "chess.js";
|
||||
import type { ClearPremoves } from "react-chessboard";
|
||||
import { Chessboard } from "react-chessboard";
|
||||
|
||||
import { API_URL } from "@/config";
|
||||
import { API_URL, APP_URL } from "@/config";
|
||||
import { io } from "socket.io-client";
|
||||
|
||||
import { lobbyReducer, squareReducer } from "./reducers";
|
||||
@@ -408,12 +408,8 @@ export default function GamePage({ initialLobby }: { initialLobby: Game }) {
|
||||
}
|
||||
|
||||
function copyInvite() {
|
||||
const text = `https://ches.su/${lobby.endReason ? `archive/${lobby.id}` : initialLobby.code}`;
|
||||
if ("clipboard" in navigator) {
|
||||
navigator.clipboard.writeText(text);
|
||||
} else {
|
||||
document.execCommand("copy", true, text);
|
||||
}
|
||||
const text = `${APP_URL}/${lobby.endReason ? `archive/${lobby.id}` : initialLobby.code}`;
|
||||
navigator.clipboard.writeText(text).catch(() => {});
|
||||
setCopiedLink(true);
|
||||
setTimeout(() => {
|
||||
setCopiedLink(false);
|
||||
@@ -586,7 +582,7 @@ export default function GamePage({ initialLobby }: { initialLobby: Game }) {
|
||||
onClick={copyInvite}
|
||||
>
|
||||
<IconCopy size={16} />
|
||||
ches.su/{lobby.endReason ? `archive/${lobby.id}` : initialLobby.code}
|
||||
{APP_URL.replace(/^https?:\/\//, "")}/{lobby.endReason ? `archive/${lobby.id}` : initialLobby.code}
|
||||
</label>
|
||||
<div tabIndex={0} className="dropdown-content badge badge-neutral text-xs shadow">
|
||||
copied to clipboard
|
||||
|
||||
@@ -33,35 +33,35 @@ export default function CreateGame() {
|
||||
}
|
||||
|
||||
return (
|
||||
<form className="form-control" onSubmit={submitCreateGame}>
|
||||
<label className="label cursor-pointer">
|
||||
<span className="label-text">Unlisted/invite-only</span>
|
||||
<input type="checkbox" className="checkbox" name="createUnlisted" id="createUnlisted" />
|
||||
<form className="flex flex-col gap-3" onSubmit={submitCreateGame}>
|
||||
<label className="flex items-center justify-between cursor-pointer">
|
||||
<span className="label-text text-sm">Nur per Einladung</span>
|
||||
<input type="checkbox" className="checkbox checkbox-primary checkbox-sm" name="createUnlisted" id="createUnlisted" />
|
||||
</label>
|
||||
<label className="label" htmlFor="createStartingSide">
|
||||
<span className="label-text">Select your side</span>
|
||||
</label>
|
||||
<div className="input-group">
|
||||
<div className="flex gap-2">
|
||||
<select
|
||||
className="select select-bordered"
|
||||
className="select select-bordered select-sm flex-1"
|
||||
name="createStartingSide"
|
||||
id="createStartingSide"
|
||||
>
|
||||
<option value="random">Random</option>
|
||||
<option value="white">White</option>
|
||||
<option value="black">Black</option>
|
||||
<option value="random">Zufällig</option>
|
||||
<option value="white">Weiß</option>
|
||||
<option value="black">Schwarz</option>
|
||||
</select>
|
||||
<button
|
||||
className={
|
||||
"btn" +
|
||||
"btn btn-primary btn-sm" +
|
||||
(buttonLoading ? " loading" : "") +
|
||||
(!session?.user?.id ? " btn-disabled text-base-content" : "")
|
||||
(!session?.user?.id ? " btn-disabled" : "")
|
||||
}
|
||||
type="submit"
|
||||
>
|
||||
Create
|
||||
Erstellen
|
||||
</button>
|
||||
</div>
|
||||
{!session?.user?.id && (
|
||||
<p className="text-xs opacity-60">Bitte einloggen um ein Spiel zu erstellen</p>
|
||||
)}
|
||||
</form>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -25,8 +25,8 @@ export default function JoinGame() {
|
||||
|
||||
setButtonLoading(true);
|
||||
|
||||
if (code.startsWith("ches.su")) {
|
||||
code = "http://" + code;
|
||||
if (!code.startsWith("http") && code.includes("/")) {
|
||||
code = "https://" + code;
|
||||
}
|
||||
if (code.startsWith("http")) {
|
||||
code = new URL(code).pathname.split("/")[1];
|
||||
|
||||
@@ -2,18 +2,14 @@
|
||||
|
||||
import { IconCopy } from "@tabler/icons-react";
|
||||
import { useState } from "react";
|
||||
import { APP_URL } from "@/config";
|
||||
|
||||
export default function CopyLink({ name }: { name: string }) {
|
||||
const [copiedLink, setCopiedLink] = useState(false);
|
||||
const host = APP_URL.replace(/^https?:\/\//, "");
|
||||
|
||||
function copyLink() {
|
||||
const text = `https://ches.su/user/${name}`;
|
||||
|
||||
if ("clipboard" in navigator) {
|
||||
navigator.clipboard.writeText(text);
|
||||
} else {
|
||||
document.execCommand("copy", true, text);
|
||||
}
|
||||
navigator.clipboard.writeText(`${APP_URL}/user/${name}`).catch(() => {});
|
||||
setCopiedLink(true);
|
||||
setTimeout(() => {
|
||||
setCopiedLink(false);
|
||||
@@ -27,7 +23,7 @@ export default function CopyLink({ name }: { name: string }) {
|
||||
onClick={copyLink}
|
||||
>
|
||||
<IconCopy size={16} />
|
||||
ches.su/user/{name}
|
||||
{host}/user/{name}
|
||||
</label>
|
||||
<div tabIndex={0} className="dropdown-content badge badge-neutral text-xs shadow">
|
||||
copied to clipboard
|
||||
|
||||
Reference in New Issue
Block a user