start chat detroyed css by merging multiples files
This commit is contained in:
parent
5ee67927f6
commit
7b593831bb
6
chat/package-lock.json
generated
Normal file
6
chat/package-lock.json
generated
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
{
|
||||||
|
"name": "app",
|
||||||
|
"lockfileVersion": 3,
|
||||||
|
"requires": true,
|
||||||
|
"packages": {}
|
||||||
|
}
|
||||||
Binary file not shown.
|
Before Width: | Height: | Size: 767 B |
@ -53,6 +53,12 @@ export class AppController {
|
|||||||
return req.user;
|
return req.user;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@UseGuards(JwtAuthGuard)
|
||||||
|
@Get('/user')
|
||||||
|
async getUser( @Body() data: any) {
|
||||||
|
return await this.userService.findOne(data.username);
|
||||||
|
}
|
||||||
|
|
||||||
@UseGuards(JwtAuthGuard)
|
@UseGuards(JwtAuthGuard)
|
||||||
@Post('/win')
|
@Post('/win')
|
||||||
async addWin(@Request() req, @Body() data: any) {
|
async addWin(@Request() req, @Body() data: any) {
|
||||||
@ -131,9 +137,60 @@ export class AppController {
|
|||||||
console.log("User quit");
|
console.log("User quit");
|
||||||
}
|
}
|
||||||
|
|
||||||
// @Get('/chat')
|
@Post('/conv')
|
||||||
// async Chat(@Res() res) {
|
async createConv(@Request() req, @Body() data: any) {
|
||||||
// const messages = await this.chatService.getMessages();
|
///create conv and return it ? id?
|
||||||
// res.json(messages);
|
console.log(`data post /conv= ${data}`);
|
||||||
// }
|
// let test = {id: 2, members: "cc"};
|
||||||
}
|
return await this.chatService.createConv(data);
|
||||||
|
// res.json(messages);
|
||||||
|
}
|
||||||
|
|
||||||
|
// @UseGuards(JwtAuthGuard)
|
||||||
|
@Get('/conv')
|
||||||
|
async getConv(@Request() req, @Body() data: any) {
|
||||||
|
///create conv and return it ? id?
|
||||||
|
// console.log(`data get /conv= ${data}`);
|
||||||
|
// let test = {id: 2, members: "cc"};
|
||||||
|
|
||||||
|
// let tab = [data.member, "test"];
|
||||||
|
// console.log(`tab= ${tab}`);
|
||||||
|
return await this.chatService.getConv(data.member);
|
||||||
|
// return await this.chatService.getConv(req.user.username);
|
||||||
|
|
||||||
|
|
||||||
|
// res.json(messages);
|
||||||
|
}
|
||||||
|
|
||||||
|
// @UseGuards(JwtAuthGuard)
|
||||||
|
@Post('/message')
|
||||||
|
async postMessage(@Request() req, @Body() data: any) {
|
||||||
|
//if i can post post ?
|
||||||
|
let message =
|
||||||
|
{
|
||||||
|
convid: data.convId,
|
||||||
|
sender: data.sender,
|
||||||
|
text: data.text,
|
||||||
|
// createdAt: null,
|
||||||
|
id: null,
|
||||||
|
}
|
||||||
|
console.log(data);
|
||||||
|
return await this.chatService.createMessage(message);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Post('/getMessage')
|
||||||
|
async getMessage(@Request() req, @Body() data: any) {
|
||||||
|
console.log(data);
|
||||||
|
console.log(req.query )
|
||||||
|
console.log(`data get /conv= ${data.convId}`);
|
||||||
|
// let test = {id: 2, members: "cc"};
|
||||||
|
|
||||||
|
|
||||||
|
return await this.chatService.getMessages(data.convId);
|
||||||
|
// return await this.chatService.getConv(req.user.username);
|
||||||
|
|
||||||
|
|
||||||
|
// res.json(messages);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -8,13 +8,15 @@ import { ChatService} from './chat.service';
|
|||||||
|
|
||||||
import { TypeOrmModule } from '@nestjs/typeorm';
|
import { TypeOrmModule } from '@nestjs/typeorm';
|
||||||
import { getTypeOrmConfig } from '../config/config.service';
|
import { getTypeOrmConfig } from '../config/config.service';
|
||||||
import { Chat } from '../model/chat.entity';
|
import { Conv } from '../model/chat.entity';
|
||||||
|
import { Message } from '../model/chat.entity';
|
||||||
|
|
||||||
@Module({
|
@Module({
|
||||||
imports:
|
imports:
|
||||||
[
|
[
|
||||||
TypeOrmModule.forRoot(getTypeOrmConfig()),
|
TypeOrmModule.forRoot(getTypeOrmConfig()),
|
||||||
TypeOrmModule.forFeature([Chat]),
|
TypeOrmModule.forFeature([Conv]),
|
||||||
|
TypeOrmModule.forFeature([Message]),
|
||||||
// TypeOrmModule.forFeature([UserRepository]),
|
// TypeOrmModule.forFeature([UserRepository]),
|
||||||
],
|
],
|
||||||
providers:[ChatService],
|
providers:[ChatService],
|
||||||
|
|||||||
@ -1,22 +1,92 @@
|
|||||||
// import { Injectable } from '@nestjs/common';
|
// import { Injectable } from '@nestjs/common';
|
||||||
|
|
||||||
// @Injectable()
|
// @Injectable()
|
||||||
// export class ChatService {}
|
// export class ConvService {}
|
||||||
|
|
||||||
import { Injectable } from '@nestjs/common';
|
import { Injectable } from '@nestjs/common';
|
||||||
import { InjectRepository } from '@nestjs/typeorm';
|
import { InjectRepository } from '@nestjs/typeorm';
|
||||||
import { Repository } from 'typeorm';
|
import { Repository } from 'typeorm';
|
||||||
import { Chat } from '../model/chat.entity';
|
import { Conv } from '../model/chat.entity';
|
||||||
|
import { Message } from '../model/chat.entity';
|
||||||
|
|
||||||
|
import { ArrayContains } from "typeorm"
|
||||||
|
import { query } from 'express';
|
||||||
|
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class ChatService {
|
export class ChatService {
|
||||||
constructor(@InjectRepository(Chat) private chatRepository: Repository<Chat>,) {}
|
constructor(@InjectRepository(Conv) private chatRepository: Repository<Conv>,
|
||||||
|
@InjectRepository(Message) private messageRepository: Repository<Message>,
|
||||||
|
) {}
|
||||||
|
|
||||||
async createMessage(chat: Chat): Promise<Chat> {
|
async createConv(conv: Conv): Promise<Conv> {
|
||||||
return await this.chatRepository.save(chat);
|
return await this.chatRepository.save(conv);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// SELECT "conv"."id" AS "conv_id", "conv"."members" AS "conv_members", "conv"."name" AS "conv_name", "conv"."banned" AS "conv_banned", "conv"."admin" AS "conv_admin", "conv"."messages" AS "conv_messages" FROM "conv" "conv" WHERE $1 = ANY("conv"."members")
|
||||||
|
|
||||||
|
|
||||||
|
// import { createConnection } from 'typeorm';
|
||||||
|
|
||||||
|
async getConv(username: string): Promise<Conv[]>{
|
||||||
|
username = "apommier"
|
||||||
|
const convs = await this.chatRepository.query("SELECT * FROM \"conv\" WHERE $1 = ANY (ARRAY[members]);", [username])
|
||||||
|
console.log(`convs= ${convs}`)
|
||||||
|
return convs;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Usage
|
||||||
|
// const user = 'user1';
|
||||||
|
// findConvsContainingUser(user)
|
||||||
|
// .then((convs) => {
|
||||||
|
// console.log('Convs containing user:', convs);
|
||||||
|
// })
|
||||||
|
// .catch((error) => {
|
||||||
|
// console.error('Error:', error);
|
||||||
|
// });
|
||||||
|
// return await this.chatRepository.findOneBy({
|
||||||
|
// members: { $in: [username] },
|
||||||
|
// });
|
||||||
|
|
||||||
|
// return await this.chatRepository.find()
|
||||||
|
|
||||||
|
|
||||||
|
// return await this.chatRepository.findOneBy({
|
||||||
|
// members: ArrayContains(["apommier"]),
|
||||||
|
// })
|
||||||
|
|
||||||
|
// console.log(`get conv username= ${username} `)
|
||||||
|
// let test = await this.chatRepository.find({
|
||||||
|
// where : {
|
||||||
|
// members: { $all: ["apommier"] },
|
||||||
|
// }})
|
||||||
|
// console.log(`test= ${test}`)
|
||||||
|
// return test
|
||||||
|
// }
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//
|
||||||
|
// message
|
||||||
|
//
|
||||||
|
|
||||||
|
async createMessage(message: Message): Promise<Message> {
|
||||||
|
return await this.messageRepository.save(message);
|
||||||
}
|
}
|
||||||
|
|
||||||
async getMessages(): Promise<Chat[]> {
|
async getMessages(convId: number): Promise<Message[]> {
|
||||||
return await this.chatRepository.find();
|
// return await this.messageRepository.find({
|
||||||
}
|
// where: {
|
||||||
|
// convId: convId,
|
||||||
|
// },
|
||||||
|
// });
|
||||||
|
const convs = await this.chatRepository
|
||||||
|
.query("SELECT * FROM \"message\" WHERE $1 = message.convid;", [convId])
|
||||||
|
|
||||||
|
return (convs)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -6,12 +6,13 @@
|
|||||||
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
|
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2023/04/09 14:53:49 by apommier #+# #+# */
|
/* Created: 2023/04/09 14:53:49 by apommier #+# #+# */
|
||||||
/* Updated: 2023/05/05 23:11:44 by apommier ### ########.fr */
|
/* Updated: 2023/06/01 13:07:12 by apommier ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
import { TypeOrmModuleOptions } from '@nestjs/typeorm';
|
import { TypeOrmModuleOptions } from '@nestjs/typeorm';
|
||||||
export const getTypeOrmConfig = (): TypeOrmModuleOptions => ({
|
|
||||||
|
export const getTypeOrmConfig = (): TypeOrmModuleOptions => ({
|
||||||
type: 'postgres',
|
type: 'postgres',
|
||||||
host: 'postgresql',
|
host: 'postgresql',
|
||||||
port: 5432,
|
port: 5432,
|
||||||
@ -25,4 +26,4 @@ import { TypeOrmModuleOptions } from '@nestjs/typeorm';
|
|||||||
migrations: ['src/migration/*.ts'],
|
migrations: ['src/migration/*.ts'],
|
||||||
ssl: process.env.MODE !== 'DEV',
|
ssl: process.env.MODE !== 'DEV',
|
||||||
synchronize: true,
|
synchronize: true,
|
||||||
});
|
});
|
||||||
@ -1,18 +1,35 @@
|
|||||||
import { Entity, Column, PrimaryGeneratedColumn, CreateDateColumn, BaseEntity } from 'typeorm';
|
import { Entity, Column, PrimaryGeneratedColumn, CreateDateColumn, BaseEntity } from 'typeorm';
|
||||||
|
|
||||||
@Entity()
|
@Entity()
|
||||||
export class Chat{
|
export class Conv{
|
||||||
@PrimaryGeneratedColumn('uuid')
|
@PrimaryGeneratedColumn()
|
||||||
id: number;
|
id: number;
|
||||||
|
|
||||||
|
@Column('text', { array: true, nullable: true })
|
||||||
|
members: string[];
|
||||||
|
|
||||||
|
@Column({ nullable: true })
|
||||||
|
name: string
|
||||||
|
|
||||||
|
@Column({ nullable: true })
|
||||||
|
group: boolean
|
||||||
|
|
||||||
|
// @Column()
|
||||||
|
// members: string;// arry ??? one to many ???
|
||||||
|
|
||||||
|
@Column({ nullable: true })
|
||||||
|
banned: string;// arry ??? one to many ???
|
||||||
|
|
||||||
|
@Column({ nullable: true })
|
||||||
|
admin: string;// arry ??? one to many ???
|
||||||
|
|
||||||
@Column()
|
@Column({ nullable: true })
|
||||||
email: string;
|
messages: string;
|
||||||
|
|
||||||
@Column({ unique: true })
|
// @CreateDateColumn()
|
||||||
text: string;
|
// createdAt: Date;
|
||||||
|
|
||||||
@CreateDateColumn()
|
|
||||||
createdAt: Date;
|
|
||||||
|
|
||||||
//ban user
|
//ban user
|
||||||
//user list
|
//user list
|
||||||
@ -20,4 +37,24 @@ import { Entity, Column, PrimaryGeneratedColumn, CreateDateColumn, BaseEntity }
|
|||||||
//op list
|
//op list
|
||||||
//a way to stock conv ?
|
//a way to stock conv ?
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Entity()
|
||||||
|
export class Message{
|
||||||
|
@PrimaryGeneratedColumn()
|
||||||
|
id: number;
|
||||||
|
|
||||||
|
@Column({nullable: true})
|
||||||
|
convid: number;
|
||||||
|
|
||||||
|
@Column()
|
||||||
|
sender: string;
|
||||||
|
|
||||||
|
@Column()
|
||||||
|
text: string;
|
||||||
|
|
||||||
|
|
||||||
|
@CreateDateColumn({ nullable: true })
|
||||||
|
createdAt?: Date;
|
||||||
|
|
||||||
|
}
|
||||||
1153
containers/chat/package-lock.json
generated
1153
containers/chat/package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@ -1,36 +1,42 @@
|
|||||||
import { NestFactory } from '@nestjs/core';
|
import { NestFactory } from '@nestjs/core';
|
||||||
import { AppModule } from './app.module';
|
import { AppModule } from './app.module';
|
||||||
|
import * as cors from 'cors';
|
||||||
|
import { Server } from 'socket.io';
|
||||||
import * as socketio from 'socket.io';
|
import * as socketio from 'socket.io';
|
||||||
|
|
||||||
async function bootstrap() {
|
async function bootstrap() {
|
||||||
const app = await NestFactory.create(AppModule, {
|
const app = await NestFactory.create(AppModule, {
|
||||||
cors:
|
cors: {
|
||||||
{
|
origin: '*',
|
||||||
origin: '*',
|
methods: '*',
|
||||||
methods: '*',
|
// preflightContinue: false,
|
||||||
allowedHeaders: '*',
|
// optionsSuccessStatus: 204,
|
||||||
},
|
// credentials: true,
|
||||||
});
|
allowedHeaders: '*',
|
||||||
|
},
|
||||||
|
});
|
||||||
|
// const app = await NestFactory.create(AppModule);
|
||||||
|
|
||||||
const httpServer = app.getHttpServer();
|
const httpServer = app.getHttpServer();
|
||||||
const io = new socketio.Server(httpServer);
|
const io = new socketio.Server(httpServer);
|
||||||
|
|
||||||
io.on('connection', (socket) => {
|
io.on('connection', (socket) => {
|
||||||
console.log('Client connected:', socket.id);
|
console.log('Client connected:', socket.id);
|
||||||
|
|
||||||
// Gestion des événements personnalisés ici
|
// Gestion des événements personnalisés ici
|
||||||
socket.on('customEvent', (data) => {
|
socket.on('customEvent', (data) => {
|
||||||
console.log('Custom event received:', data);
|
console.log('Custom event received:', data);
|
||||||
|
|
||||||
// Exemple de réponse à un événement personnalisé
|
// Exemple de réponse à un événement personnalisé
|
||||||
socket.emit('customEventResponse', { message: 'Event processed.' });
|
socket.emit('customEventResponse', { message: 'Event processed.' });
|
||||||
});
|
});
|
||||||
|
|
||||||
socket.on('disconnect', () => {
|
socket.on('disconnect', () => {
|
||||||
console.log('Client disconnected:', socket.id);
|
console.log('Client disconnected:', socket.id);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
await app.listen(4001);
|
await app.listen(4001);
|
||||||
}
|
}
|
||||||
|
|
||||||
bootstrap();
|
bootstrap();
|
||||||
|
|||||||
23
containers/old_react/.gitignore
vendored
23
containers/old_react/.gitignore
vendored
@ -1,23 +0,0 @@
|
|||||||
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
|
|
||||||
|
|
||||||
# dependencies
|
|
||||||
/node_modules
|
|
||||||
/.pnp
|
|
||||||
.pnp.js
|
|
||||||
|
|
||||||
# testing
|
|
||||||
/coverage
|
|
||||||
|
|
||||||
# production
|
|
||||||
/build
|
|
||||||
|
|
||||||
# misc
|
|
||||||
.DS_Store
|
|
||||||
.env.local
|
|
||||||
.env.development.local
|
|
||||||
.env.test.local
|
|
||||||
.env.production.local
|
|
||||||
|
|
||||||
npm-debug.log*
|
|
||||||
yarn-debug.log*
|
|
||||||
yarn-error.log*
|
|
||||||
@ -1,70 +0,0 @@
|
|||||||
# Getting Started with Create React App
|
|
||||||
|
|
||||||
This project was bootstrapped with [Create React App](https://github.com/facebook/create-react-app).
|
|
||||||
|
|
||||||
## Available Scripts
|
|
||||||
|
|
||||||
In the project directory, you can run:
|
|
||||||
|
|
||||||
### `npm start`
|
|
||||||
|
|
||||||
Runs the app in the development mode.\
|
|
||||||
Open [http://localhost:3000](http://localhost:3000) to view it in your browser.
|
|
||||||
|
|
||||||
The page will reload when you make changes.\
|
|
||||||
You may also see any lint errors in the console.
|
|
||||||
|
|
||||||
### `npm test`
|
|
||||||
|
|
||||||
Launches the test runner in the interactive watch mode.\
|
|
||||||
See the section about [running tests](https://facebook.github.io/create-react-app/docs/running-tests) for more information.
|
|
||||||
|
|
||||||
### `npm run build`
|
|
||||||
|
|
||||||
Builds the app for production to the `build` folder.\
|
|
||||||
It correctly bundles React in production mode and optimizes the build for the best performance.
|
|
||||||
|
|
||||||
The build is minified and the filenames include the hashes.\
|
|
||||||
Your app is ready to be deployed!
|
|
||||||
|
|
||||||
See the section about [deployment](https://facebook.github.io/create-react-app/docs/deployment) for more information.
|
|
||||||
|
|
||||||
### `npm run eject`
|
|
||||||
|
|
||||||
**Note: this is a one-way operation. Once you `eject`, you can't go back!**
|
|
||||||
|
|
||||||
If you aren't satisfied with the build tool and configuration choices, you can `eject` at any time. This command will remove the single build dependency from your project.
|
|
||||||
|
|
||||||
Instead, it will copy all the configuration files and the transitive dependencies (webpack, Babel, ESLint, etc) right into your project so you have full control over them. All of the commands except `eject` will still work, but they will point to the copied scripts so you can tweak them. At this point you're on your own.
|
|
||||||
|
|
||||||
You don't have to ever use `eject`. The curated feature set is suitable for small and middle deployments, and you shouldn't feel obligated to use this feature. However we understand that this tool wouldn't be useful if you couldn't customize it when you are ready for it.
|
|
||||||
|
|
||||||
## Learn More
|
|
||||||
|
|
||||||
You can learn more in the [Create React App documentation](https://facebook.github.io/create-react-app/docs/getting-started).
|
|
||||||
|
|
||||||
To learn React, check out the [React documentation](https://reactjs.org/).
|
|
||||||
|
|
||||||
### Code Splitting
|
|
||||||
|
|
||||||
This section has moved here: [https://facebook.github.io/create-react-app/docs/code-splitting](https://facebook.github.io/create-react-app/docs/code-splitting)
|
|
||||||
|
|
||||||
### Analyzing the Bundle Size
|
|
||||||
|
|
||||||
This section has moved here: [https://facebook.github.io/create-react-app/docs/analyzing-the-bundle-size](https://facebook.github.io/create-react-app/docs/analyzing-the-bundle-size)
|
|
||||||
|
|
||||||
### Making a Progressive Web App
|
|
||||||
|
|
||||||
This section has moved here: [https://facebook.github.io/create-react-app/docs/making-a-progressive-web-app](https://facebook.github.io/create-react-app/docs/making-a-progressive-web-app)
|
|
||||||
|
|
||||||
### Advanced Configuration
|
|
||||||
|
|
||||||
This section has moved here: [https://facebook.github.io/create-react-app/docs/advanced-configuration](https://facebook.github.io/create-react-app/docs/advanced-configuration)
|
|
||||||
|
|
||||||
### Deployment
|
|
||||||
|
|
||||||
This section has moved here: [https://facebook.github.io/create-react-app/docs/deployment](https://facebook.github.io/create-react-app/docs/deployment)
|
|
||||||
|
|
||||||
### `npm run build` fails to minify
|
|
||||||
|
|
||||||
This section has moved here: [https://facebook.github.io/create-react-app/docs/troubleshooting#npm-run-build-fails-to-minify](https://facebook.github.io/create-react-app/docs/troubleshooting#npm-run-build-fails-to-minify)
|
|
||||||
17612
containers/old_react/package-lock.json
generated
17612
containers/old_react/package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@ -1,47 +0,0 @@
|
|||||||
{
|
|
||||||
"name": "my-app",
|
|
||||||
"version": "0.1.0",
|
|
||||||
"private": true,
|
|
||||||
"compilerOptions": {
|
|
||||||
"topLevelAwait": true
|
|
||||||
},
|
|
||||||
"dependencies": {
|
|
||||||
"@testing-library/jest-dom": "^5.16.5",
|
|
||||||
"@testing-library/react": "^13.4.0",
|
|
||||||
"@testing-library/user-event": "^13.5.0",
|
|
||||||
"axios": "^1.3.5",
|
|
||||||
"query-string": "^8.1.0",
|
|
||||||
"react": "^18.2.0",
|
|
||||||
"react-dom": "^18.2.0",
|
|
||||||
"react-router-dom": "^6.10.0",
|
|
||||||
"react-scripts": "5.0.1",
|
|
||||||
"socket.io-client": "^4.6.1",
|
|
||||||
"typescript": "^4.9.5",
|
|
||||||
"web-vitals": "^2.1.4"
|
|
||||||
},
|
|
||||||
"scripts": {
|
|
||||||
"start": "HOST=0.0.0.0 PORT=8080 react-scripts start",
|
|
||||||
"start:dev": "npm run start --watch",
|
|
||||||
"build": "react-scripts build",
|
|
||||||
"test": "react-scripts test",
|
|
||||||
"eject": "react-scripts eject"
|
|
||||||
},
|
|
||||||
"eslintConfig": {
|
|
||||||
"extends": [
|
|
||||||
"react-app",
|
|
||||||
"react-app/jest"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"browserslist": {
|
|
||||||
"production": [
|
|
||||||
">0.2%",
|
|
||||||
"not dead",
|
|
||||||
"not op_mini all"
|
|
||||||
],
|
|
||||||
"development": [
|
|
||||||
"last 1 chrome version",
|
|
||||||
"last 1 firefox version",
|
|
||||||
"last 1 safari version"
|
|
||||||
]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Binary file not shown.
|
Before Width: | Height: | Size: 3.8 KiB |
@ -1,43 +0,0 @@
|
|||||||
<!DOCTYPE html>
|
|
||||||
<html lang="en">
|
|
||||||
<head>
|
|
||||||
<meta charset="utf-8" />
|
|
||||||
<!-- <link rel="icon" href="%PUBLIC_URL%/favicon.ico" /> -->
|
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
|
||||||
<meta name="theme-color" content="#000000" />
|
|
||||||
<meta
|
|
||||||
name="description"
|
|
||||||
content="Web site created using create-react-app"
|
|
||||||
/>
|
|
||||||
<link rel="apple-touch-icon" href="%PUBLIC_URL%/logo192.png" />
|
|
||||||
<!--
|
|
||||||
manifest.json provides metadata used when your web app is installed on a
|
|
||||||
user's mobile device or desktop. See https://developers.google.com/web/fundamentals/web-app-manifest/
|
|
||||||
-->
|
|
||||||
<link rel="manifest" href="%PUBLIC_URL%/manifest.json" />
|
|
||||||
<!--
|
|
||||||
Notice the use of %PUBLIC_URL% in the tags above.
|
|
||||||
It will be replaced with the URL of the `public` folder during the build.
|
|
||||||
Only files inside the `public` folder can be referenced from the HTML.
|
|
||||||
|
|
||||||
Unlike "/favicon.ico" or "favicon.ico", "%PUBLIC_URL%/favicon.ico" will
|
|
||||||
work correctly both with client-side routing and a non-root public URL.
|
|
||||||
Learn how to configure a non-root public URL by running `npm run build`.
|
|
||||||
-->
|
|
||||||
<title>React App</title>
|
|
||||||
</head>
|
|
||||||
<body>
|
|
||||||
<noscript>You need to enable JavaScript to run this app.</noscript>
|
|
||||||
<div id="root"></div>
|
|
||||||
<!--
|
|
||||||
This HTML file is a template.
|
|
||||||
If you open it directly in the browser, you will see an empty page.
|
|
||||||
|
|
||||||
You can add webfonts, meta tags, or analytics to this file.
|
|
||||||
The build step will place the bundled scripts into the <body> tag.
|
|
||||||
|
|
||||||
To begin the development, run `npm start` or `yarn start`.
|
|
||||||
To create a production bundle, use `npm run build` or `yarn build`.
|
|
||||||
-->
|
|
||||||
</body>
|
|
||||||
</html>
|
|
||||||
Binary file not shown.
|
Before Width: | Height: | Size: 5.2 KiB |
Binary file not shown.
|
Before Width: | Height: | Size: 9.4 KiB |
@ -1,25 +0,0 @@
|
|||||||
{
|
|
||||||
"short_name": "React App",
|
|
||||||
"name": "Create React App Sample",
|
|
||||||
"icons": [
|
|
||||||
{
|
|
||||||
"src": "favicon.ico",
|
|
||||||
"sizes": "64x64 32x32 24x24 16x16",
|
|
||||||
"type": "image/x-icon"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"src": "logo192.png",
|
|
||||||
"type": "image/png",
|
|
||||||
"sizes": "192x192"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"src": "logo512.png",
|
|
||||||
"type": "image/png",
|
|
||||||
"sizes": "512x512"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"start_url": ".",
|
|
||||||
"display": "standalone",
|
|
||||||
"theme_color": "#000000",
|
|
||||||
"background_color": "#ffffff"
|
|
||||||
}
|
|
||||||
@ -1,3 +0,0 @@
|
|||||||
# https://www.robotstxt.org/robotstxt.html
|
|
||||||
User-agent: *
|
|
||||||
Disallow:
|
|
||||||
@ -1,92 +0,0 @@
|
|||||||
import { useEffect, useState } from "react";
|
|
||||||
import { Navigate, Route, Routes, useNavigate } from "react-router-dom";
|
|
||||||
import "../styles/App.css";
|
|
||||||
|
|
||||||
import Field from './Field';
|
|
||||||
import PlayButton from './PlayButton';
|
|
||||||
import SuccessToken from '../script/tokenSuccess'
|
|
||||||
import Home from './Home';
|
|
||||||
|
|
||||||
import api from '../script/axiosApi';
|
|
||||||
|
|
||||||
// import Login42 from './Login42';
|
|
||||||
|
|
||||||
// const navigate = useNavigate();
|
|
||||||
|
|
||||||
// const [isLoggedIn, setisLoggedIn] = useState(false);
|
|
||||||
// useEffect(() => {
|
|
||||||
// if (!localStorage.getItem('token'))
|
|
||||||
// {
|
|
||||||
// navigate("/");
|
|
||||||
// }
|
|
||||||
// else
|
|
||||||
// {
|
|
||||||
// setisLoggedIn(true);
|
|
||||||
// }
|
|
||||||
// },);
|
|
||||||
|
|
||||||
function App() {
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
const handleUnload = async (event) => {
|
|
||||||
await api.post('/quit');
|
|
||||||
// Custom logic when the user is quitting the app
|
|
||||||
// You can perform any necessary cleanup or trigger actions here
|
|
||||||
// This function will be called when the user leaves the app
|
|
||||||
};
|
|
||||||
|
|
||||||
// Add the event listener when the component mounts
|
|
||||||
window.addEventListener('beforeunload', handleUnload);
|
|
||||||
|
|
||||||
// Remove the event listener when the component unmounts
|
|
||||||
return () => {
|
|
||||||
window.removeEventListener('beforeunload', handleUnload);
|
|
||||||
};
|
|
||||||
}, []);
|
|
||||||
|
|
||||||
return (
|
|
||||||
<>
|
|
||||||
<Routes>
|
|
||||||
<Route exact path="/" element={<Home/>}/>
|
|
||||||
<Route exact path="/pong" element={<PlayButton />}/>
|
|
||||||
<Route exact path="/pong/play" element={<Field />}/>
|
|
||||||
<Route exact path="/token" element={<SuccessToken />}/>
|
|
||||||
|
|
||||||
<Route path='*' element={<Navigate to='/' />} />
|
|
||||||
|
|
||||||
</Routes>
|
|
||||||
</>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
export default App;
|
|
||||||
|
|
||||||
// {/* <Route path="*"><Navigate to="/" /></Route>
|
|
||||||
// */}
|
|
||||||
|
|
||||||
// {/* Gestion des pages inexistantes */}
|
|
||||||
|
|
||||||
// {/* ------- ROUTE FOR CHAT APP HERE --------- */}
|
|
||||||
// {/* <Route exact path="/chat" element={<NOM DU COMPONENT == index dans le tuto/>}/> */}
|
|
||||||
|
|
||||||
|
|
||||||
// {/* <Routes>
|
|
||||||
// {/* {redirectToUrl} */}
|
|
||||||
// <Route exact path="/" element={<Home/>}/>
|
|
||||||
// <Route exact path="/pong" element={<PlayButton />}/>
|
|
||||||
// <Route exact path="/pong/play" element={<Field />}/>
|
|
||||||
// <Route exact path="/token" element={<SuccessToken />}/>
|
|
||||||
|
|
||||||
// <Route path='*' element={<Navigate to='/' />} />
|
|
||||||
|
|
||||||
// {/* <Route path="*"><Navigate to="/" /></Route>
|
|
||||||
// */}
|
|
||||||
|
|
||||||
// {/* Gestion des pages inexistantes */}
|
|
||||||
|
|
||||||
// {/* ------- ROUTE FOR CHAT APP HERE --------- */}
|
|
||||||
// {/* <Route exact path="/chat" element={<NOM DU COMPONENT == index dans le tuto/>}/> */}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// </Routes> */}
|
|
||||||
@ -1,20 +0,0 @@
|
|||||||
import { BrowserRouter, Routes, Route } from 'react-router-dom';
|
|
||||||
import Home from './components/Home';
|
|
||||||
import ChatPage from './components/ChatPage';
|
|
||||||
import socketIO from 'socket.io-client';
|
|
||||||
|
|
||||||
const socket = socketIO.connect('http://localhost:4000');
|
|
||||||
function App() {
|
|
||||||
return (
|
|
||||||
<BrowserRouter>
|
|
||||||
<div>
|
|
||||||
<Routes>
|
|
||||||
<Route path="/" element={<Home socket={socket} />}></Route>
|
|
||||||
<Route path="/chat" element={<ChatPage socket={socket} />}></Route>
|
|
||||||
</Routes>
|
|
||||||
</div>
|
|
||||||
</BrowserRouter>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
export default App;
|
|
||||||
@ -1,72 +0,0 @@
|
|||||||
import { useEffect } from 'react';
|
|
||||||
import { useState, useRef } from 'react';
|
|
||||||
import { drawCanvas } from './canvas.js';
|
|
||||||
import '../styles/field.css';
|
|
||||||
|
|
||||||
function Field()
|
|
||||||
{
|
|
||||||
useEffect(() => {
|
|
||||||
console.log("launch canva hehe")
|
|
||||||
drawCanvas();
|
|
||||||
}, []);
|
|
||||||
|
|
||||||
// const [buttonClicked, setButtonClicked] = useState(false);
|
|
||||||
|
|
||||||
// const handleButtonClick = () => {
|
|
||||||
// drawCanvas();
|
|
||||||
// setButtonClicked(true);
|
|
||||||
// };
|
|
||||||
|
|
||||||
return (
|
|
||||||
<div className="field" id="canvas_container">
|
|
||||||
<canvas id="myCanvas"></canvas>
|
|
||||||
{/* <button onClick={handleButtonClick}>Draw on Canvas</button> */}
|
|
||||||
{/* {buttonClicked && <canvas id="myCanvas"></canvas>}
|
|
||||||
{!buttonClicked && <button onClick={handleButtonClick}>Draw on Canvas</button>} */}
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
export default Field;
|
|
||||||
|
|
||||||
|
|
||||||
// function Field() {
|
|
||||||
// const [buttonClicked, setButtonClicked] = useState(false);
|
|
||||||
|
|
||||||
// const handleButtonClick = () => {
|
|
||||||
// const canvas = document.createElement('canvas');
|
|
||||||
// canvas.id = 'myCanvas';
|
|
||||||
// console.log("button clicked")
|
|
||||||
// document.getElementById('canvas_container').appendChild(canvas);
|
|
||||||
// setButtonClicked(true);
|
|
||||||
// drawCanvas(canvas);
|
|
||||||
// };
|
|
||||||
// setButtonClicked(true);
|
|
||||||
// return (
|
|
||||||
// // <div className="field" id="canvas_container">
|
|
||||||
// <div className={`notClicked ${buttonClicked ? 'clicked' : ''}`} id="canvas_container">
|
|
||||||
// {!buttonClicked && <button className="playButton" onClick={handleButtonClick}>Play</button>}
|
|
||||||
// </div>
|
|
||||||
// );
|
|
||||||
// }
|
|
||||||
|
|
||||||
// export default Field;
|
|
||||||
|
|
||||||
// function draw() {
|
|
||||||
// // Effacer le canvas
|
|
||||||
// ctx.clearRect(0, 0, canvas.width, canvas.height);
|
|
||||||
|
|
||||||
// // Dessiner la raquette
|
|
||||||
// ctx.fillRect(canvas.width - paddleWidth, paddleY, paddleWidth, paddleHeight);
|
|
||||||
|
|
||||||
// // Appeler la fonction draw à chaque frame
|
|
||||||
// requestAnimationFrame(draw);
|
|
||||||
// }
|
|
||||||
|
|
||||||
// draw(); // Appeler la fonction draw pour la première fois
|
|
||||||
|
|
||||||
// const canvas = document.getElementById('myCanvas');
|
|
||||||
// canvas.width = 500;
|
|
||||||
// canvas.height = 500;
|
|
||||||
// const ctx = canvas.getContext('2d');
|
|
||||||
// ctx.fillRect(50, 50, 1000, 1000);
|
|
||||||
@ -1,12 +0,0 @@
|
|||||||
import '../styles/old.css';
|
|
||||||
|
|
||||||
function Footer()
|
|
||||||
{
|
|
||||||
return (
|
|
||||||
<footer>
|
|
||||||
<p>@apommier | apommier@student.42.fr</p>
|
|
||||||
</footer>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
export default Footer;
|
|
||||||
@ -1,16 +0,0 @@
|
|||||||
function Head()
|
|
||||||
{
|
|
||||||
return (
|
|
||||||
<div>
|
|
||||||
<meta charSet="utf-8"></meta>
|
|
||||||
<link href="./css/header.css" rel="stylesheet"></link>
|
|
||||||
<title>BEST PONG EVER</title>
|
|
||||||
{/* <script src="./script/login.js"></script> */}
|
|
||||||
<link rel="preconnect" href="https://fonts.googleapis.com"></link>
|
|
||||||
<link rel="preconnect" href="https://fonts.gstatic.com" crossOrigin="true"></link>
|
|
||||||
<link href="https://fonts.googleapis.com/css2?family=Rubik+Iso&display=swap" rel="stylesheet"></link>
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
export default Head;
|
|
||||||
@ -1,31 +0,0 @@
|
|||||||
import '../styles/App.css';
|
|
||||||
import '../styles/old.css';
|
|
||||||
import logo from '../logo.svg';
|
|
||||||
|
|
||||||
|
|
||||||
import React, { useEffect, useState } from 'react';
|
|
||||||
import axios from 'axios';
|
|
||||||
// import setupLogin from '../script/login42';
|
|
||||||
// import React, { useEffect } from 'react';
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
function Header()
|
|
||||||
{
|
|
||||||
return (
|
|
||||||
<div className="header">
|
|
||||||
<a href="http://localhost" className="box menu"> <p className="userTxt">Menu</p> </a>
|
|
||||||
<div className="box headerName">
|
|
||||||
{/* <a href="https://api.intra.42.fr/oauth/authorize?client_id=u-s4t2ud-6d29dfa49ba7146577ffd8bf595ae8d9e5aaa3e0a9615df18777171ebf836a41&redirect_uri=http%3A%2F%2Flocalhost%3A8080%2Flogin42&response_type=code" */}
|
|
||||||
<a className="center pong">PONG</a>
|
|
||||||
</div>
|
|
||||||
<a href="http://localhost/pong" className="box username">
|
|
||||||
<p className="userTxt">Play</p>
|
|
||||||
{/* <img className="pp center" src="../../public/logo192.png" alt="profile picture"> */}
|
|
||||||
<img src={logo} className="pp center" alt="logo" />
|
|
||||||
</a>
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
export default Header;
|
|
||||||
@ -1,49 +0,0 @@
|
|||||||
import '../styles/old.css';
|
|
||||||
import '../styles/field.css';
|
|
||||||
|
|
||||||
import { useLocation } from 'react-router-dom';
|
|
||||||
import api from '../script/axiosApi';
|
|
||||||
|
|
||||||
function Home()
|
|
||||||
{
|
|
||||||
const login2 = () => {
|
|
||||||
console.log('Hello from myFunction');
|
|
||||||
api.get('/profile').then((response) => {
|
|
||||||
const data = response;
|
|
||||||
const myJSON = JSON.stringify(response.data);
|
|
||||||
console.log(`data response= ${myJSON}`)
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
const location = useLocation();
|
|
||||||
|
|
||||||
const handleButtonClick = () => {
|
|
||||||
const token = localStorage.getItem('token')
|
|
||||||
console.log(`token type= ${typeof token}`);
|
|
||||||
if (token !== null && typeof token === 'string')
|
|
||||||
{
|
|
||||||
console.log(`already token= ${localStorage.getItem('token')}`)
|
|
||||||
return ;
|
|
||||||
}
|
|
||||||
// else
|
|
||||||
let path = "https://api.intra.42.fr/oauth/authorize?client_id=u-s4t2ud-6d29dfa49ba7146577ffd8bf595ae8d9e5aaa3e0a9615df18777171ebf836a41&redirect_uri=http%3A%2F%2Flocalhost%3A80%2Fapi%2Fauth%2Flogin&response_type=code";
|
|
||||||
window.location.replace(path);
|
|
||||||
};
|
|
||||||
|
|
||||||
return (
|
|
||||||
<div className="notClicked">
|
|
||||||
<button onClick={handleButtonClick} className="playButton" >LOGIN</button>
|
|
||||||
<div className ="loginForm">
|
|
||||||
<button className="submit" onClick={login2}>test button</button>
|
|
||||||
</div>
|
|
||||||
<div className ="loginForm">
|
|
||||||
<button className="submit" onClick={() => api.post('/win')}>add win</button>
|
|
||||||
</div>
|
|
||||||
<div className ="loginForm">
|
|
||||||
<button className="submit" onClick={() => api.post('/loss')}>add loss</button>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
export default Home;
|
|
||||||
@ -1,23 +0,0 @@
|
|||||||
import '../styles/field.css';
|
|
||||||
// import { useHistory } from 'react-router-dom';
|
|
||||||
import { useNavigate } from "react-router-dom";
|
|
||||||
|
|
||||||
function PlayButton() {
|
|
||||||
|
|
||||||
const history = useNavigate();
|
|
||||||
|
|
||||||
const handleButtonClick = () => {
|
|
||||||
let path = `play`;
|
|
||||||
history(path);
|
|
||||||
};
|
|
||||||
|
|
||||||
return (
|
|
||||||
<div className="notClicked" id="canvas_container">
|
|
||||||
<button onClick={handleButtonClick} className="playButton">Play</button>
|
|
||||||
{/* !buttonClicked && <button onClick={handleButtonClick}>Draw on Canvas</button> */}
|
|
||||||
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
export default PlayButton;
|
|
||||||
@ -1,23 +0,0 @@
|
|||||||
import React, { useEffect } from 'react';
|
|
||||||
import axios from 'axios';
|
|
||||||
|
|
||||||
function MyComponent() {
|
|
||||||
useEffect(() => {
|
|
||||||
const api = axios.create({
|
|
||||||
baseURL: 'https://api.example.com',
|
|
||||||
withCredentials: true, // this is required to send cookies
|
|
||||||
headers: {
|
|
||||||
'X-Custom-Header': 'foobar', // you can also set other default headers
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
const response = api.get('/some-endpoint').then((response) => {
|
|
||||||
console.log(response.data);
|
|
||||||
response.data.username
|
|
||||||
});
|
|
||||||
}, []);
|
|
||||||
|
|
||||||
return <div>My Component</div>;
|
|
||||||
}
|
|
||||||
|
|
||||||
export default MyComponent;
|
|
||||||
@ -1,514 +0,0 @@
|
|||||||
// import io from 'socket.io-client';
|
|
||||||
|
|
||||||
import api from '../script/axiosApi';
|
|
||||||
|
|
||||||
// import { useEffect } from 'react';
|
|
||||||
import io from 'socket.io-client';
|
|
||||||
// const socket = io('http://192.168.1.14:4000');
|
|
||||||
// const socket = io('http://86.209.110.20:4000');
|
|
||||||
// const socket = io('http://172.29.113.91:4000');
|
|
||||||
|
|
||||||
export function drawCanvas() {
|
|
||||||
const socket = io('http://localhost:4000');
|
|
||||||
// const socket = io()
|
|
||||||
console.log("start function");
|
|
||||||
const canvas = document.getElementById('myCanvas');
|
|
||||||
const ctx = canvas.getContext('2d');
|
|
||||||
|
|
||||||
//========================================================================================================
|
|
||||||
//========================================================================================================
|
|
||||||
// Var Declaration
|
|
||||||
//========================================================================================================
|
|
||||||
//========================================================================================================
|
|
||||||
|
|
||||||
//socket
|
|
||||||
let myId = 0;
|
|
||||||
let gameId = 0;
|
|
||||||
let opName;
|
|
||||||
let opRank;
|
|
||||||
|
|
||||||
//general canvas
|
|
||||||
const scale = window.devicePixelRatio;
|
|
||||||
canvas.width = canvas.offsetWidth;
|
|
||||||
canvas.height = canvas.offsetHeight;
|
|
||||||
|
|
||||||
//paddle var
|
|
||||||
let paddleWidth = canvas.width * 0.01;
|
|
||||||
let paddleHeight = canvas.height * 0.25;
|
|
||||||
let paddleY = canvas.height / 2 - (paddleHeight / 2);
|
|
||||||
let paddleX = canvas.width / 40;
|
|
||||||
let paddleSpeed = canvas.height / 40;
|
|
||||||
|
|
||||||
//opponent var
|
|
||||||
let oPaddleY = paddleY;
|
|
||||||
|
|
||||||
//mouse and touch
|
|
||||||
let lastMouseY = 0;
|
|
||||||
let lastTouchY = 0;
|
|
||||||
|
|
||||||
//ball var
|
|
||||||
let ballX = canvas.width / 2;
|
|
||||||
let ballY = canvas.height / 2;
|
|
||||||
|
|
||||||
//ball display
|
|
||||||
let ballRadius = canvas.width * 0.01;
|
|
||||||
let circleRadius = ballRadius * 3;
|
|
||||||
ctx.lineWidth = (canvas.width / 300);
|
|
||||||
|
|
||||||
//ball vector
|
|
||||||
let vX = 0;
|
|
||||||
let vY = 0;
|
|
||||||
|
|
||||||
//score
|
|
||||||
let myScore = 0;
|
|
||||||
let hisScore = 0;
|
|
||||||
const maxScore = 5;
|
|
||||||
|
|
||||||
let lastUpdateTime = performance.now();
|
|
||||||
|
|
||||||
const maxAngle = 50;
|
|
||||||
let maxBounceAngle = (maxAngle * Math.PI) / 180;
|
|
||||||
|
|
||||||
//========================================================================================================
|
|
||||||
//========================================================================================================
|
|
||||||
// Socket handler
|
|
||||||
//========================================================================================================
|
|
||||||
//========================================================================================================
|
|
||||||
|
|
||||||
function matchmaking()
|
|
||||||
{
|
|
||||||
console.log(`id ion matcj= ${myId}`)
|
|
||||||
const info = {
|
|
||||||
id: myId,
|
|
||||||
};
|
|
||||||
socket.emit('pong:matchmaking', info);
|
|
||||||
}
|
|
||||||
|
|
||||||
// socket.on('pong:gameId', (data) => {
|
|
||||||
// console.log("gameId received")
|
|
||||||
// gameId = data;
|
|
||||||
// // api.get('/profile');
|
|
||||||
|
|
||||||
// let myName;
|
|
||||||
|
|
||||||
// api.get('/profile').then((data) => {
|
|
||||||
// // Faire quelque chose avec les données
|
|
||||||
// console.log(data);
|
|
||||||
// myName = data.data.username;
|
|
||||||
// console.log(`myname= ${myName}`);
|
|
||||||
// }).catch((error) => {
|
|
||||||
// console.log(error);
|
|
||||||
// // exit() ;
|
|
||||||
// return;
|
|
||||||
// });
|
|
||||||
|
|
||||||
// const info = {
|
|
||||||
// id: myId,
|
|
||||||
// name: myName,
|
|
||||||
// gameId: gameId,
|
|
||||||
// };
|
|
||||||
// console.log("emit to name")
|
|
||||||
// socket.emit('pong:name', info);
|
|
||||||
// });
|
|
||||||
|
|
||||||
socket.on('pong:gameId', async (data) => {
|
|
||||||
console.log("gameId received");
|
|
||||||
gameId = data;
|
|
||||||
|
|
||||||
try {
|
|
||||||
let response = await api.get('/profile');
|
|
||||||
const myName = response.data.username;
|
|
||||||
response = await api.get('/rank');
|
|
||||||
opRank = response.data
|
|
||||||
console.log(`rank= ${opRank}`);
|
|
||||||
console.log(`myname= ${myName}`);
|
|
||||||
|
|
||||||
const info = {
|
|
||||||
id: myId,
|
|
||||||
name: myName,
|
|
||||||
gameId: gameId,
|
|
||||||
rank: opRank,
|
|
||||||
};
|
|
||||||
|
|
||||||
console.log("emit to name");
|
|
||||||
socket.emit('pong:name', info);
|
|
||||||
} catch (error) {
|
|
||||||
console.log(error);
|
|
||||||
// Handle error here
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
socket.on('pong:name', (data) => {
|
|
||||||
opName = data;
|
|
||||||
console.log(`opponent Name= ${opName}`)
|
|
||||||
});
|
|
||||||
|
|
||||||
socket.on('connect', () => {
|
|
||||||
console.log('Connected to NestJS server');
|
|
||||||
});
|
|
||||||
|
|
||||||
socket.on('pong:clientId', (data) => {
|
|
||||||
console.log("receive id")
|
|
||||||
myId = data;
|
|
||||||
console.log(`id is= ${myId}`)
|
|
||||||
});
|
|
||||||
|
|
||||||
socket.on('pong:info', (data) => {
|
|
||||||
oPaddleY = (data.paddleY / data.height) * canvas.height//canvas.height - data.ballY;
|
|
||||||
ballX = canvas.width - (data.ballX * (canvas.width / data.width));//- data.ballX;
|
|
||||||
ballY = ((data.ballY / data.height) * canvas.height)//canvas.height - data.ballY;
|
|
||||||
|
|
||||||
vX = -data.vX;
|
|
||||||
vY = data.vY;
|
|
||||||
});
|
|
||||||
|
|
||||||
function send_info()
|
|
||||||
{
|
|
||||||
if (gameId === 0)
|
|
||||||
return ;
|
|
||||||
const info = {
|
|
||||||
id: myId,
|
|
||||||
width: canvas.width,
|
|
||||||
height: canvas.height,
|
|
||||||
paddleY: paddleY,
|
|
||||||
vX: vX,
|
|
||||||
vY: vY,
|
|
||||||
ballX: ballX,
|
|
||||||
ballY: ballY,
|
|
||||||
gameId: gameId,
|
|
||||||
};
|
|
||||||
socket.emit('pong:message', info);
|
|
||||||
}
|
|
||||||
|
|
||||||
socket.on('pong:paddle', (data) => {
|
|
||||||
console.log("paddle info receive")
|
|
||||||
oPaddleY = (data.paddleY / data.height) * canvas.height
|
|
||||||
});
|
|
||||||
|
|
||||||
function send_point()
|
|
||||||
{
|
|
||||||
if (gameId === 0)
|
|
||||||
return ;
|
|
||||||
console.log("send point");
|
|
||||||
const info = {
|
|
||||||
id: myId,
|
|
||||||
gameId: gameId,
|
|
||||||
point: hisScore,
|
|
||||||
}
|
|
||||||
socket.emit('pong:point', info);
|
|
||||||
}
|
|
||||||
|
|
||||||
socket.on('pong:point', (data) => {
|
|
||||||
// hisScore += 1;
|
|
||||||
console.log("gain point");
|
|
||||||
// if (vX != 0)
|
|
||||||
// {
|
|
||||||
// console.log("up point");
|
|
||||||
myScore = data.point;
|
|
||||||
// }
|
|
||||||
vX = 0;
|
|
||||||
vY = 0;
|
|
||||||
ballX = canvas.width / 2;
|
|
||||||
ballY = canvas.height / 2;
|
|
||||||
});
|
|
||||||
|
|
||||||
function send_paddle_info()
|
|
||||||
{
|
|
||||||
if (gameId === 0)
|
|
||||||
return ;
|
|
||||||
const info = {
|
|
||||||
id: myId,
|
|
||||||
paddleY: paddleY,
|
|
||||||
// width: canvas.width,
|
|
||||||
height: canvas.height,
|
|
||||||
gameId: gameId,
|
|
||||||
};
|
|
||||||
socket.emit('pong:paddle', info);
|
|
||||||
}
|
|
||||||
|
|
||||||
function send_forced_info()
|
|
||||||
{
|
|
||||||
if (gameId === 0)
|
|
||||||
return ;
|
|
||||||
const info = {
|
|
||||||
gameId: gameId,
|
|
||||||
width: canvas.width,
|
|
||||||
height: canvas.height,
|
|
||||||
id: myId,
|
|
||||||
paddleY: paddleY,
|
|
||||||
vX: vX,
|
|
||||||
vY: vY,
|
|
||||||
ballX: ballX,
|
|
||||||
ballY: ballY,
|
|
||||||
};
|
|
||||||
socket.emit('pong:forced', info);
|
|
||||||
}
|
|
||||||
|
|
||||||
//========================================================================================================
|
|
||||||
//========================================================================================================
|
|
||||||
// Drawer
|
|
||||||
//========================================================================================================
|
|
||||||
//========================================================================================================
|
|
||||||
|
|
||||||
function drawcenter()
|
|
||||||
{
|
|
||||||
// ctx.restore();
|
|
||||||
ctx.fillStyle = 'white';
|
|
||||||
ctx.fillRect(canvas.width / 2 - ctx.lineWidth / 2, 0, canvas.width / 300, canvas.height);
|
|
||||||
|
|
||||||
ctx.beginPath();
|
|
||||||
// ctx.lineWidth = 5;
|
|
||||||
ctx.arc(canvas.width / 2, canvas.height / 2, circleRadius, 0, 2 * Math.PI);
|
|
||||||
ctx.strokeStyle = 'white'; // couleur de dessin
|
|
||||||
ctx.stroke(); // dessin du contour
|
|
||||||
|
|
||||||
ctx.font = canvas.width * 0.1 + "px Arial";
|
|
||||||
ctx.textAlign = "center";
|
|
||||||
ctx.textBaseline = "middle";
|
|
||||||
ctx.fillText(myScore, canvas.width/4, canvas.height/8);
|
|
||||||
ctx.fillText(hisScore, canvas.width/1.25, canvas.height/8);
|
|
||||||
}
|
|
||||||
|
|
||||||
function drawPaddle() {
|
|
||||||
ctx.fillStyle = 'white';
|
|
||||||
ctx.fillRect(paddleX, paddleY, paddleWidth, paddleHeight);
|
|
||||||
ctx.fillRect(canvas.width - paddleX - paddleWidth, oPaddleY, paddleWidth, paddleHeight);
|
|
||||||
}
|
|
||||||
|
|
||||||
function drawball()
|
|
||||||
{
|
|
||||||
ctx.beginPath();
|
|
||||||
ctx.arc(ballX, ballY, ballRadius, 0, 2 * Math.PI);
|
|
||||||
// ctx.lineWidth = 2;
|
|
||||||
ctx.fillStyle = 'red ';
|
|
||||||
ctx.fill();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
//========================================================================================================
|
|
||||||
//========================================================================================================
|
|
||||||
// Loop
|
|
||||||
//========================================================================================================
|
|
||||||
//========================================================================================================
|
|
||||||
|
|
||||||
matchmaking();
|
|
||||||
// while (!gameId)
|
|
||||||
// ;
|
|
||||||
|
|
||||||
|
|
||||||
function draw(timestamp)
|
|
||||||
{
|
|
||||||
if (gameId === 0 )
|
|
||||||
{
|
|
||||||
requestAnimationFrame(draw);
|
|
||||||
return ;
|
|
||||||
}
|
|
||||||
if (myScore === maxScore || hisScore === maxScore)
|
|
||||||
{
|
|
||||||
const data = {
|
|
||||||
myScore: myScore,
|
|
||||||
opScore: hisScore,
|
|
||||||
opName: opName,
|
|
||||||
opRank: opRank,
|
|
||||||
};
|
|
||||||
if (myScore === maxScore)
|
|
||||||
{
|
|
||||||
api.post('/win', data);
|
|
||||||
console.log("send win");
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
api.post('/loss', data);
|
|
||||||
console.log("send loose");
|
|
||||||
}
|
|
||||||
window.location.replace("http://localhost/pong");
|
|
||||||
return ;
|
|
||||||
}
|
|
||||||
|
|
||||||
const deltaTime = timestamp - lastUpdateTime;
|
|
||||||
lastUpdateTime = timestamp;
|
|
||||||
ballX += vX * deltaTime * canvas.width;
|
|
||||||
ballY += vY * deltaTime * canvas.width;
|
|
||||||
|
|
||||||
ctx.clearRect(0, 0, canvas.width, canvas.height);
|
|
||||||
drawPaddle();
|
|
||||||
drawcenter();
|
|
||||||
drawball();
|
|
||||||
is_collision();
|
|
||||||
is_out();
|
|
||||||
requestAnimationFrame(draw);
|
|
||||||
}
|
|
||||||
requestAnimationFrame(draw);
|
|
||||||
|
|
||||||
//========================================================================================================
|
|
||||||
//========================================================================================================
|
|
||||||
// Logical Part
|
|
||||||
//========================================================================================================
|
|
||||||
//========================================================================================================
|
|
||||||
|
|
||||||
function updateVector()
|
|
||||||
{
|
|
||||||
const relativeBallY = ballY - (paddleY + paddleHeight / 2);
|
|
||||||
const normalizedRelativeBallY = relativeBallY / (paddleHeight / 2);
|
|
||||||
const bounceAngle = normalizedRelativeBallY * maxBounceAngle;
|
|
||||||
|
|
||||||
vY = vX * Math.sin(-bounceAngle);
|
|
||||||
if (vX < 0)
|
|
||||||
vX = -vX;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
function updatePaddlePosition(newY)
|
|
||||||
{
|
|
||||||
if (newY >= 0 && newY <= canvas.height - paddleHeight)
|
|
||||||
paddleY = newY;
|
|
||||||
}
|
|
||||||
|
|
||||||
function is_collision()
|
|
||||||
{
|
|
||||||
if (ballX <= paddleX + paddleWidth + ballRadius)
|
|
||||||
{
|
|
||||||
if (ballY <= paddleY + paddleHeight + ballRadius && ballY >= paddleY - ballRadius)//touch paddle
|
|
||||||
{
|
|
||||||
if (ballX + ballRadius > paddleX && ballX - ballRadius < paddleX + paddleWidth)
|
|
||||||
{
|
|
||||||
console.log("hehe here")
|
|
||||||
ballX = paddleX + paddleWidth + ballRadius;
|
|
||||||
}
|
|
||||||
updateVector();
|
|
||||||
}
|
|
||||||
send_info();
|
|
||||||
return ;
|
|
||||||
}
|
|
||||||
if (ballY - ballRadius - 2 <= 0 || ballY + ballRadius + 2 >= canvas.height) //touch up or down wall
|
|
||||||
{
|
|
||||||
vY = -vY;
|
|
||||||
// send_info();
|
|
||||||
}
|
|
||||||
else if (ballX + ballRadius + 2 >= canvas.width) //touch right wall
|
|
||||||
{
|
|
||||||
vX = -vX;
|
|
||||||
// send_info();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function is_out()
|
|
||||||
{
|
|
||||||
if (ballX < 0)
|
|
||||||
{
|
|
||||||
if (ballY <= paddleY + paddleHeight + ballRadius && ballY >= paddleY - ballRadius)
|
|
||||||
{
|
|
||||||
console.log('true hehe');
|
|
||||||
ballX = paddleX + paddleWidth + ballRadius;
|
|
||||||
updateVector();
|
|
||||||
return ;
|
|
||||||
}
|
|
||||||
ballX = canvas.width / 2;
|
|
||||||
ballY = canvas.height / 2;
|
|
||||||
vX = 0;
|
|
||||||
vY = 0;
|
|
||||||
hisScore += 1;
|
|
||||||
send_point();
|
|
||||||
// send_forced_info();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//========================================================================================================
|
|
||||||
//========================================================================================================
|
|
||||||
// Listener
|
|
||||||
//========================================================================================================
|
|
||||||
//========================================================================================================
|
|
||||||
|
|
||||||
|
|
||||||
document.addEventListener('mousemove', event => {
|
|
||||||
const mouseY = event.clientY;
|
|
||||||
|
|
||||||
if (!lastMouseY)
|
|
||||||
{
|
|
||||||
lastMouseY = mouseY;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
const newY = mouseY > lastMouseY ? paddleY - (lastMouseY - mouseY) : paddleY + (mouseY - lastMouseY);
|
|
||||||
updatePaddlePosition(newY);
|
|
||||||
lastMouseY = mouseY;
|
|
||||||
send_paddle_info();
|
|
||||||
});
|
|
||||||
|
|
||||||
document.addEventListener("touchmove", event => {
|
|
||||||
const touchY = event.touches[0].pageY;
|
|
||||||
|
|
||||||
// if (!lastTouchY)
|
|
||||||
// {
|
|
||||||
// vX = -0.01;
|
|
||||||
// lastTouchY = touchY;
|
|
||||||
// return;
|
|
||||||
// }
|
|
||||||
const newY = touchY > lastTouchY ? paddleY - (lastTouchY - touchY) : paddleY + (touchY - lastTouchY);
|
|
||||||
updatePaddlePosition(newY);
|
|
||||||
lastTouchY = touchY;
|
|
||||||
send_paddle_info();
|
|
||||||
});
|
|
||||||
|
|
||||||
document.addEventListener("keydown", event => {
|
|
||||||
// console.log(event.code);
|
|
||||||
if (event.code === "ArrowUp")
|
|
||||||
{
|
|
||||||
if ((paddleY - paddleSpeed) > 0)
|
|
||||||
paddleY -= paddleSpeed; // déplacer la raquette vers le haut
|
|
||||||
send_paddle_info();
|
|
||||||
}
|
|
||||||
else if (event.code === "ArrowDown")
|
|
||||||
{
|
|
||||||
if (paddleY + paddleSpeed < canvas.height - paddleHeight)
|
|
||||||
paddleY += paddleSpeed; // déplacer la raquette vers le bas
|
|
||||||
send_paddle_info();
|
|
||||||
}
|
|
||||||
else if (event.code === "Space")//space
|
|
||||||
{
|
|
||||||
console.log('vx change to -1');
|
|
||||||
vX = -0.0001;
|
|
||||||
|
|
||||||
// ballSpeed = 0.0001;
|
|
||||||
vY = 0;
|
|
||||||
send_forced_info();
|
|
||||||
// vX = 0.0001;
|
|
||||||
}
|
|
||||||
else if (event.code === "KeyE")
|
|
||||||
{
|
|
||||||
// console.log('vx change to -1');
|
|
||||||
vX = 0;
|
|
||||||
vY = 0;
|
|
||||||
ballX = canvas.width / 2;
|
|
||||||
ballY = canvas.height / 2;
|
|
||||||
send_forced_info();
|
|
||||||
}
|
|
||||||
else if (event.code === "KeyQ" )
|
|
||||||
{
|
|
||||||
if (vX < 0.003 * canvas.width && vX > -0.003 * canvas.width)
|
|
||||||
{
|
|
||||||
if (vX > 0)
|
|
||||||
vX += 0.0001;
|
|
||||||
else
|
|
||||||
vX -= 0.0001;
|
|
||||||
}
|
|
||||||
send_forced_info();
|
|
||||||
// console.log(`vx = ${vX}`);
|
|
||||||
}
|
|
||||||
else if (event.code === "KeyR")
|
|
||||||
{
|
|
||||||
paddleY = 0;
|
|
||||||
paddleHeight = canvas.height;
|
|
||||||
setTimeout(() => {
|
|
||||||
// code à exécuter après 5 secondes
|
|
||||||
paddleHeight = canvas.height * 0.25;
|
|
||||||
paddleY = canvas.height / 2 - paddleHeight / 2;
|
|
||||||
console.log('Cinq secondes se sont écoulées.');
|
|
||||||
}, 5000);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
}
|
|
||||||
@ -1,58 +0,0 @@
|
|||||||
import React from 'react';
|
|
||||||
import ReactDOM from 'react-dom/client';
|
|
||||||
|
|
||||||
import './styles/index.css';
|
|
||||||
import App from './components/App';
|
|
||||||
import Header from './components/Header';
|
|
||||||
// import Home from './components/Home';
|
|
||||||
// import Login42 from './components/Login42';
|
|
||||||
import Head from './components/Head';
|
|
||||||
// import Field from './components/Field';
|
|
||||||
// import PlayButton from './components/PlayButton';
|
|
||||||
import reportWebVitals from './reportWebVitals';
|
|
||||||
// import SuccessToken from './script/tokenSuccess'
|
|
||||||
import { BrowserRouter, Route, Routes, Navigate} from 'react-router-dom'
|
|
||||||
|
|
||||||
// let redirectToUrl;
|
|
||||||
// if (localStorage.getItem('token') !== null) //check condition
|
|
||||||
// {
|
|
||||||
// redirectToUrl = <Navigate to='/'/>;
|
|
||||||
// }
|
|
||||||
|
|
||||||
const root = ReactDOM.createRoot(document.getElementById('root'));
|
|
||||||
root.render(
|
|
||||||
<>
|
|
||||||
<Head />
|
|
||||||
<Header />
|
|
||||||
<BrowserRouter>
|
|
||||||
<App></App>
|
|
||||||
</BrowserRouter>
|
|
||||||
</>
|
|
||||||
);
|
|
||||||
|
|
||||||
// If you want to start measuring performance in your app, pass a function
|
|
||||||
// to log results (for example: reportWebVitals(console.log))
|
|
||||||
// or send to an analytics endpoint. Learn more: https://bit.ly/CRA-vitals
|
|
||||||
reportWebVitals();
|
|
||||||
|
|
||||||
{/* <Route exact path="/login42" element={<Login42 />}/> */}
|
|
||||||
// <Routes>
|
|
||||||
// {/* {redirectToUrl} */}
|
|
||||||
// <Route exact path="/" element={<Home/>}/>
|
|
||||||
// <Route exact path="/pong" element={<PlayButton />}/>
|
|
||||||
// <Route exact path="/pong/play" element={<Field />}/>
|
|
||||||
// <Route exact path="/token" element={<SuccessToken />}/>
|
|
||||||
|
|
||||||
// <Route path='*' element={<Navigate to='/' />} />
|
|
||||||
|
|
||||||
// {/* <Route path="*"><Navigate to="/" /></Route>
|
|
||||||
// */}
|
|
||||||
|
|
||||||
// {/* Gestion des pages inexistantes */}
|
|
||||||
|
|
||||||
// {/* ------- ROUTE FOR CHAT APP HERE --------- */}
|
|
||||||
// {/* <Route exact path="/chat" element={<NOM DU COMPONENT == index dans le tuto/>}/> */}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// </Routes>
|
|
||||||
@ -1 +0,0 @@
|
|||||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 841.9 595.3"><g fill="#61DAFB"><path d="M666.3 296.5c0-32.5-40.7-63.3-103.1-82.4 14.4-63.6 8-114.2-20.2-130.4-6.5-3.8-14.1-5.6-22.4-5.6v22.3c4.6 0 8.3.9 11.4 2.6 13.6 7.8 19.5 37.5 14.9 75.7-1.1 9.4-2.9 19.3-5.1 29.4-19.6-4.8-41-8.5-63.5-10.9-13.5-18.5-27.5-35.3-41.6-50 32.6-30.3 63.2-46.9 84-46.9V78c-27.5 0-63.5 19.6-99.9 53.6-36.4-33.8-72.4-53.2-99.9-53.2v22.3c20.7 0 51.4 16.5 84 46.6-14 14.7-28 31.4-41.3 49.9-22.6 2.4-44 6.1-63.6 11-2.3-10-4-19.7-5.2-29-4.7-38.2 1.1-67.9 14.6-75.8 3-1.8 6.9-2.6 11.5-2.6V78.5c-8.4 0-16 1.8-22.6 5.6-28.1 16.2-34.4 66.7-19.9 130.1-62.2 19.2-102.7 49.9-102.7 82.3 0 32.5 40.7 63.3 103.1 82.4-14.4 63.6-8 114.2 20.2 130.4 6.5 3.8 14.1 5.6 22.5 5.6 27.5 0 63.5-19.6 99.9-53.6 36.4 33.8 72.4 53.2 99.9 53.2 8.4 0 16-1.8 22.6-5.6 28.1-16.2 34.4-66.7 19.9-130.1 62-19.1 102.5-49.9 102.5-82.3zm-130.2-66.7c-3.7 12.9-8.3 26.2-13.5 39.5-4.1-8-8.4-16-13.1-24-4.6-8-9.5-15.8-14.4-23.4 14.2 2.1 27.9 4.7 41 7.9zm-45.8 106.5c-7.8 13.5-15.8 26.3-24.1 38.2-14.9 1.3-30 2-45.2 2-15.1 0-30.2-.7-45-1.9-8.3-11.9-16.4-24.6-24.2-38-7.6-13.1-14.5-26.4-20.8-39.8 6.2-13.4 13.2-26.8 20.7-39.9 7.8-13.5 15.8-26.3 24.1-38.2 14.9-1.3 30-2 45.2-2 15.1 0 30.2.7 45 1.9 8.3 11.9 16.4 24.6 24.2 38 7.6 13.1 14.5 26.4 20.8 39.8-6.3 13.4-13.2 26.8-20.7 39.9zm32.3-13c5.4 13.4 10 26.8 13.8 39.8-13.1 3.2-26.9 5.9-41.2 8 4.9-7.7 9.8-15.6 14.4-23.7 4.6-8 8.9-16.1 13-24.1zM421.2 430c-9.3-9.6-18.6-20.3-27.8-32 9 .4 18.2.7 27.5.7 9.4 0 18.7-.2 27.8-.7-9 11.7-18.3 22.4-27.5 32zm-74.4-58.9c-14.2-2.1-27.9-4.7-41-7.9 3.7-12.9 8.3-26.2 13.5-39.5 4.1 8 8.4 16 13.1 24 4.7 8 9.5 15.8 14.4 23.4zM420.7 163c9.3 9.6 18.6 20.3 27.8 32-9-.4-18.2-.7-27.5-.7-9.4 0-18.7.2-27.8.7 9-11.7 18.3-22.4 27.5-32zm-74 58.9c-4.9 7.7-9.8 15.6-14.4 23.7-4.6 8-8.9 16-13 24-5.4-13.4-10-26.8-13.8-39.8 13.1-3.1 26.9-5.8 41.2-7.9zm-90.5 125.2c-35.4-15.1-58.3-34.9-58.3-50.6 0-15.7 22.9-35.6 58.3-50.6 8.6-3.7 18-7 27.7-10.1 5.7 19.6 13.2 40 22.5 60.9-9.2 20.8-16.6 41.1-22.2 60.6-9.9-3.1-19.3-6.5-28-10.2zM310 490c-13.6-7.8-19.5-37.5-14.9-75.7 1.1-9.4 2.9-19.3 5.1-29.4 19.6 4.8 41 8.5 63.5 10.9 13.5 18.5 27.5 35.3 41.6 50-32.6 30.3-63.2 46.9-84 46.9-4.5-.1-8.3-1-11.3-2.7zm237.2-76.2c4.7 38.2-1.1 67.9-14.6 75.8-3 1.8-6.9 2.6-11.5 2.6-20.7 0-51.4-16.5-84-46.6 14-14.7 28-31.4 41.3-49.9 22.6-2.4 44-6.1 63.6-11 2.3 10.1 4.1 19.8 5.2 29.1zm38.5-66.7c-8.6 3.7-18 7-27.7 10.1-5.7-19.6-13.2-40-22.5-60.9 9.2-20.8 16.6-41.1 22.2-60.6 9.9 3.1 19.3 6.5 28.1 10.2 35.4 15.1 58.3 34.9 58.3 50.6-.1 15.7-23 35.6-58.4 50.6zM320.8 78.4z"/><circle cx="420.9" cy="296.5" r="45.7"/><path d="M520.5 78.1z"/></g></svg>
|
|
||||||
|
Before Width: | Height: | Size: 2.6 KiB |
@ -1,13 +0,0 @@
|
|||||||
const reportWebVitals = onPerfEntry => {
|
|
||||||
if (onPerfEntry && onPerfEntry instanceof Function) {
|
|
||||||
import('web-vitals').then(({ getCLS, getFID, getFCP, getLCP, getTTFB }) => {
|
|
||||||
getCLS(onPerfEntry);
|
|
||||||
getFID(onPerfEntry);
|
|
||||||
getFCP(onPerfEntry);
|
|
||||||
getLCP(onPerfEntry);
|
|
||||||
getTTFB(onPerfEntry);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
export default reportWebVitals;
|
|
||||||
@ -1,28 +0,0 @@
|
|||||||
// console.log(`toktoken= ${token}`)
|
|
||||||
import axios from 'axios';
|
|
||||||
|
|
||||||
// const token = localStorage.getItem('token');
|
|
||||||
|
|
||||||
|
|
||||||
function getToken() {
|
|
||||||
// your code to retrieve the token from localStorage or any other source
|
|
||||||
const token = localStorage.getItem('token');
|
|
||||||
if (typeof token === 'string') {
|
|
||||||
console.log("is a string !!!")
|
|
||||||
}
|
|
||||||
return token;
|
|
||||||
}
|
|
||||||
|
|
||||||
console.log(`getToken = ${getToken()}`)
|
|
||||||
console.log(`Bearer ${localStorage.getItem("token")}`)
|
|
||||||
|
|
||||||
let api = axios.create({
|
|
||||||
baseURL: 'http://localhost/api',
|
|
||||||
headers: {
|
|
||||||
// Authorization: `Bearer ${getToken()}`,
|
|
||||||
Authorization : `Bearer ${localStorage.getItem("token")}`
|
|
||||||
},
|
|
||||||
withCredentials: true,
|
|
||||||
});
|
|
||||||
|
|
||||||
export default api;
|
|
||||||
@ -1,35 +0,0 @@
|
|||||||
import { useLocation } from 'react-router-dom';
|
|
||||||
import queryString from 'query-string';
|
|
||||||
|
|
||||||
function SuccessToken() {
|
|
||||||
const location = useLocation();
|
|
||||||
const { data } = queryString.parse(location.search);
|
|
||||||
// localStorage data.token;
|
|
||||||
const cleanData = data.slice(1, -1);
|
|
||||||
// console.log(`prout token= ${cleanData}`)
|
|
||||||
localStorage.setItem('token', `${cleanData}`);
|
|
||||||
console.log(`prout token2= ${localStorage.getItem('token')}`)
|
|
||||||
window.location.replace("http://localhost/pong");
|
|
||||||
|
|
||||||
// return (
|
|
||||||
// <div>
|
|
||||||
// <h2>Success!</h2>
|
|
||||||
// <p>Data: {data}</p>
|
|
||||||
// </div>
|
|
||||||
// );
|
|
||||||
}
|
|
||||||
|
|
||||||
export default SuccessToken;
|
|
||||||
|
|
||||||
|
|
||||||
// // Store a value in localStorage
|
|
||||||
// localStorage.setItem('key', 'value');
|
|
||||||
|
|
||||||
// // Retrieve a value from localStorage
|
|
||||||
// const value = localStorage.getItem('key');
|
|
||||||
|
|
||||||
// // Remove a value from localStorage
|
|
||||||
// localStorage.removeItem('key');
|
|
||||||
|
|
||||||
// // Clear all values from localStorage
|
|
||||||
// localStorage.clear();
|
|
||||||
@ -1,38 +0,0 @@
|
|||||||
.App {
|
|
||||||
text-align: center;
|
|
||||||
}
|
|
||||||
|
|
||||||
.App-logo {
|
|
||||||
height: 40vmin;
|
|
||||||
pointer-events: none;
|
|
||||||
}
|
|
||||||
|
|
||||||
@media (prefers-reduced-motion: no-preference) {
|
|
||||||
.App-logo {
|
|
||||||
animation: App-logo-spin infinite 20s linear;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
.App-header {
|
|
||||||
background-color: #1f1919;
|
|
||||||
min-height: 100vh;
|
|
||||||
display: flex;
|
|
||||||
flex-direction: column;
|
|
||||||
align-items: center;
|
|
||||||
justify-content: center;
|
|
||||||
font-size: calc(10px + 2vmin);
|
|
||||||
color: white;
|
|
||||||
}
|
|
||||||
|
|
||||||
.App-link {
|
|
||||||
color: #61dafb;
|
|
||||||
}
|
|
||||||
|
|
||||||
@keyframes App-logo-spin {
|
|
||||||
from {
|
|
||||||
transform: rotate(0deg);
|
|
||||||
}
|
|
||||||
to {
|
|
||||||
transform: rotate(360deg);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,155 +0,0 @@
|
|||||||
@import url('https://fonts.googleapis.com/css2?family=Poppins:wght@100;200;300;400;500;600;700;800;900&display=swap');
|
|
||||||
|
|
||||||
* {
|
|
||||||
box-sizing: border-box;
|
|
||||||
margin: 0;
|
|
||||||
padding: 0;
|
|
||||||
font-family: 'Poppins', sans-serif;
|
|
||||||
}
|
|
||||||
.home__container {
|
|
||||||
width: 100%;
|
|
||||||
height: 100vh;
|
|
||||||
display: flex;
|
|
||||||
flex-direction: column;
|
|
||||||
justify-content: center;
|
|
||||||
align-items: center;
|
|
||||||
}
|
|
||||||
.home__container > * {
|
|
||||||
margin-bottom: 10px;
|
|
||||||
}
|
|
||||||
.home__header {
|
|
||||||
margin-bottom: 30px;
|
|
||||||
}
|
|
||||||
.username__input {
|
|
||||||
padding: 10px;
|
|
||||||
width: 50%;
|
|
||||||
}
|
|
||||||
.home__cta {
|
|
||||||
width: 200px;
|
|
||||||
padding: 10px;
|
|
||||||
font-size: 16px;
|
|
||||||
cursor: pointer;
|
|
||||||
background-color: #607eaa;
|
|
||||||
color: #f9f5eb;
|
|
||||||
outline: none;
|
|
||||||
border: none;
|
|
||||||
border-radius: 5px;
|
|
||||||
}
|
|
||||||
.chat {
|
|
||||||
width: 100%;
|
|
||||||
height: 100vh;
|
|
||||||
display: flex;
|
|
||||||
align-items: center;
|
|
||||||
}
|
|
||||||
.chat__sidebar {
|
|
||||||
height: 100%;
|
|
||||||
background-color: #f9f5eb;
|
|
||||||
flex: 0.2;
|
|
||||||
padding: 20px;
|
|
||||||
border-right: 1px solid #fdfdfd;
|
|
||||||
}
|
|
||||||
.chat__main {
|
|
||||||
height: 100%;
|
|
||||||
flex: 0.8;
|
|
||||||
}
|
|
||||||
.chat__header {
|
|
||||||
margin: 30px 0 20px 0;
|
|
||||||
}
|
|
||||||
.chat__users > * {
|
|
||||||
margin-bottom: 10px;
|
|
||||||
color: #607eaa;
|
|
||||||
font-size: 14px;
|
|
||||||
}
|
|
||||||
.online__users > * {
|
|
||||||
margin-bottom: 10px;
|
|
||||||
color: rgb(238, 102, 102);
|
|
||||||
font-style: italic;
|
|
||||||
}
|
|
||||||
.chat__mainHeader {
|
|
||||||
width: 100%;
|
|
||||||
height: 10vh;
|
|
||||||
display: flex;
|
|
||||||
align-items: center;
|
|
||||||
justify-content: space-between;
|
|
||||||
padding: 20px;
|
|
||||||
background-color: #f9f5eb;
|
|
||||||
}
|
|
||||||
.leaveChat__btn {
|
|
||||||
padding: 10px;
|
|
||||||
width: 150px;
|
|
||||||
border: none;
|
|
||||||
outline: none;
|
|
||||||
background-color: #d1512d;
|
|
||||||
cursor: pointer;
|
|
||||||
color: #eae3d2;
|
|
||||||
}
|
|
||||||
.message__container {
|
|
||||||
width: 100%;
|
|
||||||
height: 80vh;
|
|
||||||
background-color: #fff;
|
|
||||||
padding: 20px;
|
|
||||||
overflow-y: scroll;
|
|
||||||
}
|
|
||||||
|
|
||||||
.message__container > * {
|
|
||||||
margin-bottom: 10px;
|
|
||||||
}
|
|
||||||
.chat__footer {
|
|
||||||
padding: 10px;
|
|
||||||
background-color: #f9f5eb;
|
|
||||||
height: 10vh;
|
|
||||||
}
|
|
||||||
.form {
|
|
||||||
width: 100%;
|
|
||||||
height: 100%;
|
|
||||||
display: flex;
|
|
||||||
align-items: center;
|
|
||||||
justify-content: space-between;
|
|
||||||
}
|
|
||||||
.message {
|
|
||||||
width: 80%;
|
|
||||||
height: 100%;
|
|
||||||
border-radius: 10px;
|
|
||||||
border: 1px solid #ddd;
|
|
||||||
outline: none;
|
|
||||||
padding: 15px;
|
|
||||||
}
|
|
||||||
.sendBtn {
|
|
||||||
width: 150px;
|
|
||||||
background-color: green;
|
|
||||||
padding: 10px;
|
|
||||||
border: none;
|
|
||||||
outline: none;
|
|
||||||
color: #eae3d2;
|
|
||||||
cursor: pointer;
|
|
||||||
}
|
|
||||||
.sendBtn:hover {
|
|
||||||
background-color: rgb(129, 201, 129);
|
|
||||||
}
|
|
||||||
.message__recipient {
|
|
||||||
background-color: #f5ccc2;
|
|
||||||
width: 300px;
|
|
||||||
padding: 10px;
|
|
||||||
border-radius: 10px;
|
|
||||||
font-size: 15px;
|
|
||||||
}
|
|
||||||
.message__sender {
|
|
||||||
background-color: rgb(194, 243, 194);
|
|
||||||
max-width: 300px;
|
|
||||||
padding: 10px;
|
|
||||||
border-radius: 10px;
|
|
||||||
margin-left: auto;
|
|
||||||
font-size: 15px;
|
|
||||||
}
|
|
||||||
.message__chats > p {
|
|
||||||
font-size: 13px;
|
|
||||||
}
|
|
||||||
.sender__name {
|
|
||||||
text-align: right;
|
|
||||||
}
|
|
||||||
.message__status {
|
|
||||||
position: fixed;
|
|
||||||
bottom: 50px;
|
|
||||||
font-size: 13px;
|
|
||||||
font-style: italic;
|
|
||||||
}
|
|
||||||
@ -1,55 +0,0 @@
|
|||||||
.playButton {
|
|
||||||
background-color: rgb(0, 0, 0);
|
|
||||||
border-radius: 5vh;
|
|
||||||
color: white;
|
|
||||||
display: block;
|
|
||||||
margin: auto;
|
|
||||||
margin-top: 30vh;
|
|
||||||
padding: 2vh 5vw;
|
|
||||||
height: 10vh;
|
|
||||||
width: 20vw;
|
|
||||||
font-size: 300%;
|
|
||||||
}
|
|
||||||
|
|
||||||
.clicked{
|
|
||||||
/* justify-content: center; */
|
|
||||||
/* display: flex;
|
|
||||||
justify-content: center; */
|
|
||||||
background-color: rgb(0, 0, 0);
|
|
||||||
width: 70vw;
|
|
||||||
/* height: 70vh; */
|
|
||||||
margin:auto;
|
|
||||||
margin-right: 15vw;
|
|
||||||
margin-left: 15vw;
|
|
||||||
margin-top: 10vh;
|
|
||||||
position: relative;
|
|
||||||
padding-top: 35%;
|
|
||||||
/* padding-top: 25; */
|
|
||||||
/* padding-top: 177.77% */
|
|
||||||
}
|
|
||||||
|
|
||||||
#myCanvas {
|
|
||||||
background-color: rgb(75, 33, 33);
|
|
||||||
position: absolute;
|
|
||||||
top: 0;
|
|
||||||
left: 0;
|
|
||||||
cursor: none;
|
|
||||||
width: 100%;
|
|
||||||
height: 100%;
|
|
||||||
margin: 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
@media screen and (max-width: 768px) {
|
|
||||||
#canvas_container {
|
|
||||||
transform: rotate(90deg);
|
|
||||||
transform-origin: top right;
|
|
||||||
position: relative;
|
|
||||||
/* margin-right: 100vw; */
|
|
||||||
/* height: 100vw; */
|
|
||||||
width: 100vh;
|
|
||||||
}
|
|
||||||
/* #myCanvas {
|
|
||||||
height: 100%;
|
|
||||||
width: 100%;
|
|
||||||
} */
|
|
||||||
}
|
|
||||||
@ -1,13 +0,0 @@
|
|||||||
body {
|
|
||||||
margin: 0;
|
|
||||||
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen',
|
|
||||||
'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue',
|
|
||||||
sans-serif;
|
|
||||||
-webkit-font-smoothing: antialiased;
|
|
||||||
-moz-osx-font-smoothing: grayscale;
|
|
||||||
}
|
|
||||||
|
|
||||||
code {
|
|
||||||
font-family: source-code-pro, Menlo, Monaco, Consolas, 'Courier New',
|
|
||||||
monospace;
|
|
||||||
}
|
|
||||||
@ -1,165 +0,0 @@
|
|||||||
body {
|
|
||||||
/* display: flex; */
|
|
||||||
margin: 0%;
|
|
||||||
width: 100vw;
|
|
||||||
height: 100vh;
|
|
||||||
background-color: rgb(71, 71, 71);
|
|
||||||
color: white;
|
|
||||||
}
|
|
||||||
|
|
||||||
footer {
|
|
||||||
text-align: center;
|
|
||||||
position: absolute;
|
|
||||||
bottom: 0;
|
|
||||||
width: 100%;
|
|
||||||
background-color: rgb(0, 0, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
.pp {
|
|
||||||
height: 7vw;
|
|
||||||
width: 7vw;
|
|
||||||
max-height: 7vh;
|
|
||||||
max-width: 7vh;
|
|
||||||
/* max-width: ; */
|
|
||||||
border-radius: 50%;
|
|
||||||
border: 5px solid rgb(255, 255, 255);
|
|
||||||
}
|
|
||||||
|
|
||||||
.loginHere{
|
|
||||||
font-size: 5vh;
|
|
||||||
font-family: 'Rubik Iso';
|
|
||||||
text-align: center;
|
|
||||||
margin-top: 10vh;
|
|
||||||
}
|
|
||||||
|
|
||||||
::placeholder {
|
|
||||||
font-size: 3vh;
|
|
||||||
text-align: center;
|
|
||||||
align-items: center;
|
|
||||||
margin:auto;
|
|
||||||
}
|
|
||||||
|
|
||||||
.submit{
|
|
||||||
height: 5vh;
|
|
||||||
border-radius: 100vh;
|
|
||||||
}
|
|
||||||
|
|
||||||
.submit:hover {
|
|
||||||
background-color: blueviolet;
|
|
||||||
}
|
|
||||||
|
|
||||||
input{
|
|
||||||
height: 5vh;
|
|
||||||
border-radius: 100vh;
|
|
||||||
}
|
|
||||||
|
|
||||||
.pp:hover {
|
|
||||||
border: 5px solid rgb(100, 0, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
.userTxt:hover {
|
|
||||||
color:blueviolet;;
|
|
||||||
}
|
|
||||||
|
|
||||||
.userTxt {
|
|
||||||
margin-right: 5%;
|
|
||||||
}
|
|
||||||
|
|
||||||
.username {
|
|
||||||
/* justify-content: center; */
|
|
||||||
margin-right: 1vw;
|
|
||||||
display: flex;
|
|
||||||
align-items: center;
|
|
||||||
font-size: 2vw;
|
|
||||||
max-width: 33%;
|
|
||||||
color: aqua;
|
|
||||||
justify-content: right;
|
|
||||||
text-decoration: none;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* .loginButton {
|
|
||||||
display: flex;
|
|
||||||
justify-content: center;
|
|
||||||
align-items: center;
|
|
||||||
text-decoration: none;
|
|
||||||
background-color: black;
|
|
||||||
color: white;
|
|
||||||
border-radius: ;
|
|
||||||
padding: 10px 20px;
|
|
||||||
margin-left: 40vw;
|
|
||||||
margin-top: 40vh;
|
|
||||||
width: 20vw;
|
|
||||||
height: 10vh;
|
|
||||||
font-size: 5vh;
|
|
||||||
} */
|
|
||||||
|
|
||||||
.loginButton {
|
|
||||||
background-color: rgb(0, 0, 0);
|
|
||||||
border-radius: 5vh;
|
|
||||||
color: white;
|
|
||||||
display: block;
|
|
||||||
margin: auto;
|
|
||||||
margin-top: 30vh;
|
|
||||||
padding: 2vh 5vw;
|
|
||||||
height: 10vh;
|
|
||||||
width: 20vw;
|
|
||||||
font-size: 300%;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* .loginButton {
|
|
||||||
border-radius: 100vh;
|
|
||||||
max-height: 10vh;
|
|
||||||
background-color: black;
|
|
||||||
font-family: 'Rubik Iso';
|
|
||||||
font-size: 5vh;
|
|
||||||
align-items: center;
|
|
||||||
height: 50vh;
|
|
||||||
display: flex;
|
|
||||||
flex-direction: column;
|
|
||||||
justify-content: space-around;
|
|
||||||
} */
|
|
||||||
|
|
||||||
|
|
||||||
.menu {
|
|
||||||
margin-left: 2vw;
|
|
||||||
color: aqua;
|
|
||||||
/* font-size: 4vh; */
|
|
||||||
font-size: 2vw;
|
|
||||||
text-decoration: none;
|
|
||||||
}
|
|
||||||
|
|
||||||
.pong{
|
|
||||||
font-family:'Rubik Iso';
|
|
||||||
}
|
|
||||||
|
|
||||||
.box {
|
|
||||||
width: 33%;
|
|
||||||
}
|
|
||||||
|
|
||||||
.center {
|
|
||||||
align-self: center;
|
|
||||||
}
|
|
||||||
|
|
||||||
.headerName {
|
|
||||||
display:flex;
|
|
||||||
max-width: 33%;
|
|
||||||
height: 100%;
|
|
||||||
/* font-size: 50px; */
|
|
||||||
color:blueviolet;
|
|
||||||
/* font-size: 10vw; */
|
|
||||||
font-size: min(10vw, 10vh);
|
|
||||||
justify-content: center;
|
|
||||||
}
|
|
||||||
|
|
||||||
.header {
|
|
||||||
display: flex;
|
|
||||||
margin: 0;
|
|
||||||
height: 10vw;
|
|
||||||
max-height: 10vh;
|
|
||||||
align-items: center;
|
|
||||||
background-color: rgb(0, 0, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
h1 {
|
|
||||||
color:blueviolet
|
|
||||||
}
|
|
||||||
@ -28,7 +28,7 @@
|
|||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<noscript>You need to enable JavaScript to run this app.</noscript>
|
<noscript>You need to enable JavaScript to run this app.</noscript>
|
||||||
<div id="root"></div>
|
<div id="root" style=" height: 100%;"></div>
|
||||||
<!--
|
<!--
|
||||||
This HTML file is a template.
|
This HTML file is a template.
|
||||||
If you open it directly in the browser, you will see an empty page.
|
If you open it directly in the browser, you will see an empty page.
|
||||||
|
|||||||
@ -36,8 +36,8 @@ function Chat(){
|
|||||||
</TouchDiv>
|
</TouchDiv>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<Conversation/>
|
{/* <Conversation/> */}
|
||||||
<Input/>
|
{/* <Input/> */}
|
||||||
</div>
|
</div>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,7 +1,15 @@
|
|||||||
import React from "react";
|
import React, { useState, useEffect } from "react";
|
||||||
import '../../styles/Messages.css'
|
import '../../styles/Messages.css'
|
||||||
import styled from "styled-components";
|
import styled from "styled-components";
|
||||||
import DefaultPic from '../../assets/profile.jpg'
|
import DefaultPic from '../../assets/profile.jpg'
|
||||||
|
import api from '../../script/axiosApi';
|
||||||
|
|
||||||
|
import io from 'socket.io-client';
|
||||||
|
import { TbSend } from 'react-icons/tb';
|
||||||
|
import MessageYou from "./MessageYou"
|
||||||
|
import Message from "./Message"
|
||||||
|
import Input from "./Input";
|
||||||
|
|
||||||
|
|
||||||
const UserChat = styled.div `
|
const UserChat = styled.div `
|
||||||
padding: 5px;
|
padding: 5px;
|
||||||
@ -28,36 +36,111 @@ const SideP = styled.p`
|
|||||||
`
|
`
|
||||||
|
|
||||||
function Chats(){
|
function Chats(){
|
||||||
|
|
||||||
|
const [conversations, setConversation] = useState([]);
|
||||||
|
const [user, setUser] = useState([]);
|
||||||
|
const [currentChat, setCurrentChat] = useState(null);
|
||||||
|
const [messages, setMessage] = useState([]);
|
||||||
|
const [newMessages, setNewMessage] = useState("");
|
||||||
|
const [socket, setSocket] = useState(null);
|
||||||
|
|
||||||
|
useEffect(()=> {
|
||||||
|
// setSocket(io("http://localhost:4001"));
|
||||||
|
}, [])
|
||||||
|
|
||||||
|
useEffect(()=> {
|
||||||
|
|
||||||
|
const getConv = async ()=>{
|
||||||
|
try{
|
||||||
|
const convs = await api.get("/conv")
|
||||||
|
const tmpUser = await api.get("/profile")
|
||||||
|
console.log(convs);
|
||||||
|
setUser(tmpUser);
|
||||||
|
setConversation(convs.data);
|
||||||
|
}
|
||||||
|
catch(err){
|
||||||
|
console.log(err);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
getConv();
|
||||||
|
}, [])
|
||||||
|
|
||||||
|
useEffect(()=> {
|
||||||
|
const getMessage = async ()=>
|
||||||
|
{
|
||||||
|
const data = {
|
||||||
|
convId: currentChat.id
|
||||||
|
};
|
||||||
|
try{
|
||||||
|
const res = await api.post('/getMessage', data);
|
||||||
|
setMessage(res.data);
|
||||||
|
} catch(err){
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
getMessage()
|
||||||
|
}, [currentChat])
|
||||||
|
|
||||||
|
const handleSubmit = async (e)=>{
|
||||||
|
e.preventDefault();
|
||||||
|
const message = {
|
||||||
|
sender: user.data.username,
|
||||||
|
text: newMessages,
|
||||||
|
convId: currentChat.id
|
||||||
|
};
|
||||||
|
try{
|
||||||
|
const res = await api.post('/message', message);
|
||||||
|
setMessage([...messages, res.data]);
|
||||||
|
} catch(err){
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="chat">
|
<div className="chat">
|
||||||
<UserChat>
|
{conversations.map(c=> (
|
||||||
<img className="pic-user" src={DefaultPic} alt="User" />
|
<div onClick={() => setCurrentChat(c)}>
|
||||||
<div className="infoSideBar">
|
<UserChat>
|
||||||
<SideSpan>Dummy</SideSpan>
|
<img className="pic-user" src={DefaultPic} alt="User" />
|
||||||
<SideP>yo</SideP>
|
<div className="infoSideBar">
|
||||||
|
<span>{c.name}</span>
|
||||||
|
<SideP>Desc?</SideP>
|
||||||
|
</div>
|
||||||
|
</UserChat>
|
||||||
</div>
|
</div>
|
||||||
</UserChat>
|
))}
|
||||||
<UserChat>
|
|
||||||
<img className="pic-user" src={DefaultPic} alt="User" />
|
{
|
||||||
<div className="infoSideBar">
|
currentChat ? (
|
||||||
<SideSpan>Dummy</SideSpan>
|
<>
|
||||||
<SideP>yo</SideP>
|
<div className="messages">
|
||||||
</div>
|
{messages.map(m=>(
|
||||||
</UserChat><UserChat>
|
<Message message = {m} own={m.sender === user.data.username}/>
|
||||||
<img className="pic-user" src={DefaultPic} alt="User" />
|
))}
|
||||||
<div className="infoSideBar">
|
{/* <Input/> */}
|
||||||
<SideSpan>Dummy</SideSpan>
|
<div className="input">
|
||||||
<SideP>yo</SideP>
|
<input
|
||||||
</div>
|
type="text"
|
||||||
</UserChat><UserChat>
|
placeholder="What do you want to say"
|
||||||
<img className="pic-user" src={DefaultPic} alt="User" />
|
onChange={(e) => setNewMessage(e.target.value)}
|
||||||
<div className="infoSideBar">
|
value={newMessages}
|
||||||
<SideSpan>Dummy</SideSpan>
|
/>
|
||||||
<SideP>yo</SideP>
|
<div className="send">
|
||||||
</div>
|
<TbSend onClick={handleSubmit}></TbSend>
|
||||||
</UserChat>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
</div></>) : (<span className="noConv">Open a conversation</span>)}
|
||||||
|
</div>
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export default Chats
|
export default Chats
|
||||||
@ -1,39 +1,47 @@
|
|||||||
import MessageYou from "./MessageYou"
|
import MessageYou from "./MessageYou"
|
||||||
import MessageMe from "./MessageMe"
|
import MessageMe from "./MessageMe"
|
||||||
// import { useRef } from "react";
|
// import { useRef } from "react";
|
||||||
// import { useEffect } from "react";
|
import { useEffect, useState } from "react";
|
||||||
import '../../styles/Messages.css'
|
import '../../styles/Messages.css'
|
||||||
|
import Input from "./Input";
|
||||||
|
|
||||||
function Conversation(){
|
function Conversation(){
|
||||||
// const scrollRef = useRef();
|
|
||||||
|
|
||||||
// useEffect(() => {
|
const [currentChat, setCurrentChat] = useState(null);
|
||||||
// scrollRef.current?.scrollIntoView({ behavior: "smooth"})
|
const [message, setMessage] = useState([]);
|
||||||
// }, [])
|
|
||||||
|
// setCurrentChat(true)
|
||||||
return (
|
return (
|
||||||
<div className="messages">
|
<div className="messages">
|
||||||
<MessageYou/>
|
{
|
||||||
<MessageMe/>
|
currentChat ? (
|
||||||
<MessageYou/>
|
<>
|
||||||
<MessageMe/>
|
<div>
|
||||||
<MessageMe/>
|
<MessageYou/>
|
||||||
<MessageYou/>
|
<MessageMe/>
|
||||||
<MessageMe/>
|
<MessageYou/>
|
||||||
<MessageMe/>
|
<MessageMe/>
|
||||||
<MessageYou/>
|
<MessageMe/>
|
||||||
<MessageYou/>
|
<MessageYou/>
|
||||||
<MessageMe/>
|
<MessageMe/>
|
||||||
<MessageYou/>
|
<MessageMe/>
|
||||||
<MessageMe/>
|
<MessageYou/>
|
||||||
<MessageYou/>
|
<MessageYou/>
|
||||||
<MessageMe/>
|
<MessageMe/>
|
||||||
<MessageMe/>
|
<MessageYou/>
|
||||||
<MessageYou/>
|
<MessageMe/>
|
||||||
<MessageMe/>
|
<MessageYou/>
|
||||||
<MessageMe/>
|
<MessageMe/>
|
||||||
<MessageYou/>
|
<MessageMe/>
|
||||||
<MessageMe/>
|
<MessageYou/>
|
||||||
|
<MessageMe/>
|
||||||
|
<MessageMe/>
|
||||||
|
<MessageYou/>
|
||||||
|
<MessageMe/>
|
||||||
|
<Input/>
|
||||||
|
</div></>) : (<span className="noConv">Open a conversation</span>)}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
47
containers/react/src/components/Messages/Message.jsx
Normal file
47
containers/react/src/components/Messages/Message.jsx
Normal file
@ -0,0 +1,47 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* Message.jsx :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2023/06/01 18:24:46 by apommier #+# #+# */
|
||||||
|
/* Updated: 2023/06/01 18:33:43 by apommier ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
import React from "react"
|
||||||
|
import styled from "styled-components"
|
||||||
|
import DefaultPic from '../../assets/profile.jpg'
|
||||||
|
import { useRef } from "react";
|
||||||
|
import { useEffect } from "react";
|
||||||
|
import '../../styles/Messages.css'
|
||||||
|
|
||||||
|
const MeStyleP = styled.p`
|
||||||
|
background-color: lightgray;
|
||||||
|
padding 10px 20px;
|
||||||
|
border-radius 10px 0px 10px 10px;
|
||||||
|
color: black;
|
||||||
|
margin-right: 20px;
|
||||||
|
`
|
||||||
|
|
||||||
|
function MessageMe({message, own}){
|
||||||
|
const scrollRef = useRef();
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
scrollRef.current?.scrollIntoView({ behavior: "smooth"})
|
||||||
|
}, [])
|
||||||
|
return (
|
||||||
|
<div className={own ? "meMessage" : "youMessage"} ref={scrollRef}>
|
||||||
|
<div>
|
||||||
|
<img className="messageInfo" src={DefaultPic} alt="profile" />
|
||||||
|
</div>
|
||||||
|
<div className="usernameMesage">{message.sender}</div>
|
||||||
|
<div className="messageContent">
|
||||||
|
<MeStyleP>{message.text}</MeStyleP>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
export default MessageMe
|
||||||
@ -12,7 +12,7 @@ import './styles/App.css'
|
|||||||
|
|
||||||
const root = ReactDOM.createRoot(document.getElementById('root'));
|
const root = ReactDOM.createRoot(document.getElementById('root'));
|
||||||
root.render(
|
root.render(
|
||||||
<div className='App'>
|
<div className="App">
|
||||||
<Head />
|
<Head />
|
||||||
<BrowserRouter>
|
<BrowserRouter>
|
||||||
<Header />
|
<Header />
|
||||||
|
|||||||
@ -30,6 +30,7 @@ export function drawCanvas() {
|
|||||||
//general canvas
|
//general canvas
|
||||||
const scale = window.devicePixelRatio;
|
const scale = window.devicePixelRatio;
|
||||||
canvas.width = canvas.offsetWidth;
|
canvas.width = canvas.offsetWidth;
|
||||||
|
// canvas.height = canvas.width * 0.7
|
||||||
canvas.height = canvas.offsetHeight;
|
canvas.height = canvas.offsetHeight;
|
||||||
|
|
||||||
//paddle var
|
//paddle var
|
||||||
@ -423,6 +424,12 @@ requestAnimationFrame(draw);
|
|||||||
//========================================================================================================
|
//========================================================================================================
|
||||||
//========================================================================================================
|
//========================================================================================================
|
||||||
|
|
||||||
|
document.addEventListener('resize', event => {
|
||||||
|
// event.height
|
||||||
|
// event.width
|
||||||
|
const { clientWidth, clientHeight } = canvas.parentElement;
|
||||||
|
console.log(`resize detected widht= ${clientWidth} height= ${clientHeight}`)
|
||||||
|
});
|
||||||
|
|
||||||
document.addEventListener('mousemove', event => {
|
document.addEventListener('mousemove', event => {
|
||||||
const mouseY = event.clientY;
|
const mouseY = event.clientY;
|
||||||
|
|||||||
@ -1,11 +1,7 @@
|
|||||||
// console.log(`toktoken= ${token}`)
|
|
||||||
import axios from 'axios';
|
import axios from 'axios';
|
||||||
|
|
||||||
// const token = localStorage.getItem('token');
|
|
||||||
|
|
||||||
|
|
||||||
function getToken() {
|
function getToken() {
|
||||||
// your code to retrieve the token from localStorage or any other source
|
|
||||||
const token = localStorage.getItem('token');
|
const token = localStorage.getItem('token');
|
||||||
if (typeof token === 'string') {
|
if (typeof token === 'string') {
|
||||||
console.log("is a string !!!")
|
console.log("is a string !!!")
|
||||||
|
|||||||
@ -1,6 +1,7 @@
|
|||||||
.App {
|
.App {
|
||||||
text-align: center;
|
text-align: center;
|
||||||
background-color: black;
|
background-color: black;
|
||||||
|
height: 100%;
|
||||||
}
|
}
|
||||||
|
|
||||||
.App-logo {
|
.App-logo {
|
||||||
|
|||||||
@ -11,6 +11,19 @@
|
|||||||
font-size: 300%;
|
font-size: 300%;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.field {
|
||||||
|
background-color: rgb(249, 249, 249);
|
||||||
|
/* border-radius: 5vh; */
|
||||||
|
/* color: rgb(100, 42, 42); */
|
||||||
|
display: block;
|
||||||
|
margin: auto;
|
||||||
|
margin-top: 5vh;
|
||||||
|
/* padding: 2vh 5vw; */
|
||||||
|
height: 80%;
|
||||||
|
width: 80%;
|
||||||
|
/* font-size: 300%; */
|
||||||
|
}
|
||||||
|
|
||||||
.clicked{
|
.clicked{
|
||||||
/* justify-content: center; */
|
/* justify-content: center; */
|
||||||
/* display: flex;
|
/* display: flex;
|
||||||
@ -29,26 +42,28 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
#myCanvas {
|
#myCanvas {
|
||||||
background-color: rgb(75, 33, 33);
|
background-color: rgb(124, 47, 47);
|
||||||
position: absolute;
|
/* position: absolute; */
|
||||||
top: 0;
|
/* top: 0; */
|
||||||
left: 0;
|
/* left: 0; */
|
||||||
cursor: none;
|
/* cursor: none; */
|
||||||
width: 100%;
|
width: 100%;
|
||||||
height: 100%;
|
height: 100%;
|
||||||
|
margin: 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@media screen and (max-width: 768px) {
|
/* @media screen and (max-width: 768px) { */
|
||||||
#canvas_container {
|
/* #canvas_container { */
|
||||||
transform: rotate(90deg);
|
/* width: 50%; */
|
||||||
|
/* transform: rotate(90deg);
|
||||||
transform-origin: top right;
|
transform-origin: top right;
|
||||||
position: relative;
|
position: relative;
|
||||||
/* margin-right: 100vw; */
|
/* margin-right: 100vw; */
|
||||||
/* height: 100vw; */
|
/* height: 100vw; */
|
||||||
width: 100vh;
|
/* width: 100vh; */
|
||||||
}
|
/* } */
|
||||||
/* #myCanvas {
|
/* #myCanvas {
|
||||||
height: 100%;
|
height: 100%;
|
||||||
width: 100%;
|
width: 100%;
|
||||||
} */
|
} */
|
||||||
}
|
/* } */
|
||||||
@ -5,6 +5,7 @@ body {
|
|||||||
sans-serif;
|
sans-serif;
|
||||||
-webkit-font-smoothing: antialiased;
|
-webkit-font-smoothing: antialiased;
|
||||||
-moz-osx-font-smoothing: grayscale;
|
-moz-osx-font-smoothing: grayscale;
|
||||||
|
/* height: 100%; */
|
||||||
}
|
}
|
||||||
|
|
||||||
code {
|
code {
|
||||||
|
|||||||
@ -85,7 +85,7 @@ services:
|
|||||||
# networks:
|
# networks:
|
||||||
# - pongNetwork
|
# - pongNetwork
|
||||||
# volumes:
|
# volumes:
|
||||||
# - ./chat:/app
|
# - ./containers/chat:/app
|
||||||
# entrypoint: ["sh", "-c" , "npm install && npm run start:dev"]
|
# entrypoint: ["sh", "-c" , "npm install && npm run start:dev"]
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user