diff --git a/src/app/[name]/chat/page.tsx b/src/app/[name]/chat/page.tsx index 546cd09..50f84dc 100644 --- a/src/app/[name]/chat/page.tsx +++ b/src/app/[name]/chat/page.tsx @@ -1,16 +1,134 @@ 'use client'; -import React from 'react' +import { motion } from 'framer-motion'; +import Image from 'next/image'; +import Link from 'next/link'; +import React, { useEffect, useRef, useState } from 'react'; -type Props = object +const users = [ + { id: 0, name: '1 علی مصلحی', table: 12, avatar: '/assets/images/user-avatar.png' }, + { id: 1, name: '2 علی مصلحی', table: 10, avatar: '/assets/images/user-avatar.png' }, + { id: 2, name: '3 علی مصلحی', table: 11, avatar: '/assets/images/user-avatar.png' }, + { id: 3, name: '4 علی مصلحی', table: 5, avatar: '/assets/images/user-avatar.png' }, + { id: 4, name: '5 علی مصلحی', table: 2, avatar: '/assets/images/user-avatar.png' }, + { id: 5, name: '6 علی مصلحی', table: 1, avatar: '/assets/images/user-avatar.png' }, +]; + +function ChatIndex() { + const containerRef = useRef(null); + const [positions, setPositions] = useState<{ top: number; left: number }[]>([]); + + useEffect(() => { + if (containerRef.current) { + const maxW = containerRef.current.offsetWidth - 50; + const maxH = containerRef.current.offsetHeight - 80; + const elementSize = 110; // approximate size of each user element + const padding = 80; // minimum distance between elements + + const positions: { top: number; left: number }[] = []; + + const isTooClose = (top: number, left: number) => { + return positions.some(p => { + const dx = p.left - left; + const dy = p.top - top; + const distance = Math.sqrt(dx * dx + dy * dy); + return distance < padding; + }); + }; + + users.forEach(() => { + let top = 0; + let left = 0; + let tries = 0; + + do { + top = Math.random() * (maxH - elementSize); + left = Math.random() * (maxW - elementSize); + tries++; + } while (isTooClose(top, left) && tries < 100); + + positions.push({ top, left }); + }); + + setPositions(positions); + } + }, []); -function ChatIndex({ }: Props) { return ( -
- TODO +
+
+ + + + + + + + + + + + + + + + + + +
+ {positions.length === users.length && + users.map((v, i) => ( + + user avatar +
{v.name}
+
+ میز {v.table} +
+ + ))} +
+
- ) + ); } -export default ChatIndex \ No newline at end of file +export default ChatIndex;