diff --git a/src/app/[name]/chat/nearby/page.tsx b/src/app/[name]/chat/nearby/page.tsx new file mode 100644 index 0000000..84500e4 --- /dev/null +++ b/src/app/[name]/chat/nearby/page.tsx @@ -0,0 +1,140 @@ +'use client'; + +import { motion } from 'framer-motion'; +import Image from 'next/image'; +import Link from 'next/link'; +import React, { useEffect, useRef, useState } from 'react'; + +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 ChatNearby() { + 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); + } + }, []); + + + return ( +
+
+ + + + + + + + + + + + + + + + + + + + + +
+ {positions.length === users.length && + users.map((v, i) => ( + + user avatar +
{v.name}
+
+ میز {v.table} +
+ + ))} +
+
+
+ ); +} + +export default ChatNearby; diff --git a/src/app/[name]/chat/page.tsx b/src/app/[name]/chat/page.tsx index 1b34b01..84fd312 100644 --- a/src/app/[name]/chat/page.tsx +++ b/src/app/[name]/chat/page.tsx @@ -1,140 +1,156 @@ 'use client'; -import { motion } from 'framer-motion'; +import SearchBox from '@/components/input/SearchBox'; +import { ScrollArea } from '@/components/ui/scrollarea'; +import { Radar2, Trash } from 'iconsax-react'; +import { Check, CheckCheck } from 'lucide-react'; import Image from 'next/image'; import Link from 'next/link'; -import React, { useEffect, useRef, useState } from 'react'; +import React, { useState } from 'react' +import { useTranslation } from 'react-i18next'; -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' }, -]; +type Props = object -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); - } - }, []); - - - return ( -
-
- - - - - - - - - - - - - - - - - - - - - -
- {positions.length === users.length && - users.map((v, i) => ( - - user avatar -
{v.name}
-
- میز {v.table} -
- - ))} -
-
-
- ); +type ChatEntryModel = { + id: string, + username: string, + avatarUrl: string, + update?: { + time: string, + content: string, + count?: number, + seen?: boolean + } } -export default ChatIndex; +function ChatIndex({ }: Props) { + const { t } = useTranslation('chat'); + const [search, setSearch] = useState(''); + const [selectedChats, setSelectedChats] = useState([]); + + const chatsList: Array = [ + { + id: '0', + username: 'علی مصلحی', + avatarUrl: '/assets/images/user-avatar.png', + update: { + time: '12:03', + content: 'چه خبر', + count: 2, + } + }, + { + id: '1', + username: 'علی مصلحی', + avatarUrl: '/assets/images/user-avatar.png', + update: { + time: '12:03', + content: 'چه خبر', + count: 2, + } + }, + { + id: '2', + username: 'علی مصلحی', + avatarUrl: '/assets/images/user-avatar.png', + update: { + time: '12:03', + content: 'چه خبر', + seen: true + } + }, + { + id: '3', + username: 'علی مصلحی', + avatarUrl: '/assets/images/user-avatar.png', + update: { + time: '12:03', + content: 'چه خبر', + seen: true + } + }, + { + id: '4', + username: 'علی مصلحی', + avatarUrl: '/assets/images/user-avatar.png', + update: { + time: '12:03', + content: 'چه خبر', + seen: true + } + }, + { + id: '5', + username: 'علی مصلحی', + avatarUrl: '/assets/images/user-avatar.png', + update: { + time: '12:03', + content: 'چه خبر', + seen: false + } + }, + ] + + return ( +
+
+ setSearch(e.target.value)} /> + + +
+ +
+ +
    + {chatsList.map((chat, i) => { + return ( +
  • + + {`${chat.username}'s + +
    + {chat.username} + {chat.update?.content} +
    + +
    + {chat.update?.time} + {chat.update?.count !== undefined && chat.update?.count > 0 ? + + {chat.update?.count} + + : + chat.update?.seen !== undefined && + chat.update?.seen ? + : + + } + +
    + +
  • + ) + })} +
+
+
+
+ ) +} + +export default ChatIndex \ No newline at end of file