tooltip tweaks
This commit is contained in:
@@ -7,13 +7,13 @@ import { socket } from '@/socket';
|
|||||||
import Card from '@/components/Card';
|
import Card from '@/components/Card';
|
||||||
import { cardMap, layout } from '@/constants/tarokka';
|
import { cardMap, layout } from '@/constants/tarokka';
|
||||||
|
|
||||||
import type { GameUpdate, ClientUpdate, StandardGameCard, TarokkaGameCard } from '@/types';
|
import type { GameUpdate, ClientUpdate, TarokkaGameCard } from '@/types';
|
||||||
|
|
||||||
export default function GamePage() {
|
export default function GamePage() {
|
||||||
const { gameID: gameIDParam } = useParams();
|
const { gameID: gameIDParam } = useParams();
|
||||||
|
|
||||||
const [gameID, setGameID] = useState('');
|
const [gameID, setGameID] = useState('');
|
||||||
const [cards, setCards] = useState<StandardGameCard[] | TarokkaGameCard[]>([]);
|
const [cards, setCards] = useState<TarokkaGameCard[]>([]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (gameIDParam) {
|
if (gameIDParam) {
|
||||||
|
|||||||
@@ -1,18 +1,22 @@
|
|||||||
'use client';
|
'use client';
|
||||||
import { useState, useEffect, useRef } from 'react';
|
import { useState, useRef } from 'react';
|
||||||
|
|
||||||
import { StandardGameCard, TarokkaGameCard } from '@/types';
|
import { TarokkaGameCard } from '@/types';
|
||||||
import tarokkaCards from '@/constants/tarokkaCards';
|
import tarokkaCards from '@/constants/tarokkaCards';
|
||||||
|
|
||||||
const cardBack = tarokkaCards.find((card) => card.back)!;
|
const cardBack = tarokkaCards.find((card) => card.back)!;
|
||||||
|
|
||||||
type CardProps = {
|
type CardProps = {
|
||||||
card: StandardGameCard | TarokkaGameCard;
|
card: TarokkaGameCard;
|
||||||
position: { text: string };
|
position: { text: string };
|
||||||
flipAction: () => void;
|
flipAction: () => void;
|
||||||
};
|
};
|
||||||
|
|
||||||
export default function Card({ card: { aria, flipped, url }, position, flipAction }: CardProps) {
|
export default function Card({
|
||||||
|
card: { aria, description, flipped, url },
|
||||||
|
position,
|
||||||
|
flipAction,
|
||||||
|
}: CardProps) {
|
||||||
const [showTooltip, setShowTooltip] = useState(false);
|
const [showTooltip, setShowTooltip] = useState(false);
|
||||||
const [tooltipPos, setTooltipPos] = useState({ x: 0, y: 0 });
|
const [tooltipPos, setTooltipPos] = useState({ x: 0, y: 0 });
|
||||||
const longPressTimeout = useRef<NodeJS.Timeout | null>(null);
|
const longPressTimeout = useRef<NodeJS.Timeout | null>(null);
|
||||||
@@ -71,13 +75,14 @@ export default function Card({ card: { aria, flipped, url }, position, flipActio
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div
|
<div
|
||||||
className={`fixed w-[20vh] pointer-events-none duration-300 ease-in z-50 text-xs bg-black text-white rounded border border-gray-300 px-2 py-1 rounded transition-opacity ${showTooltip ? 'opacity-100' : 'opacity-0'}`}
|
className={`fixed w-[25vh] pointer-events-none duration-300 ease-in z-50 text-xs bg-black text-white rounded border border-gray-300 px-2 py-1 rounded transition-opacity ${showTooltip ? 'opacity-100' : 'opacity-0'}`}
|
||||||
style={{
|
style={{
|
||||||
top: `${tooltipPos.y + 20}px`,
|
top: `${tooltipPos.y + 20}px`,
|
||||||
left: `${tooltipPos.x + 20}px`,
|
left: `${tooltipPos.x + 20}px`,
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
{position.text}
|
{!flipped && position.text}
|
||||||
|
{flipped && description}
|
||||||
</div>
|
</div>
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
|
|||||||
Reference in New Issue
Block a user