Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sprint 3 #9

Merged
merged 43 commits into from
Oct 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
25b2278
added utils
LevanovaElena Oct 2, 2023
c587c0a
added router
LevanovaElena Oct 4, 2023
eeffb58
added routing
LevanovaElena Oct 4, 2023
ed5486c
added routing
LevanovaElena Oct 4, 2023
7186ddc
added api auth
LevanovaElena Oct 4, 2023
ad2820b
added auth users with page
LevanovaElena Oct 5, 2023
75dc9a7
added store user?fixed errors
LevanovaElena Oct 6, 2023
b8f21ad
added user settings api
LevanovaElena Oct 6, 2023
5fb87de
added modal controller
LevanovaElena Oct 6, 2023
eb466a2
added change avatar modal
LevanovaElena Oct 7, 2023
7dcce83
fixed error
LevanovaElena Oct 7, 2023
84eb9a7
added modal-prompt, api chats, service chats
LevanovaElena Oct 7, 2023
0897b32
added menu-message, menu-item
LevanovaElena Oct 8, 2023
3cdd611
added menu-chat
LevanovaElena Oct 8, 2023
095fbe9
added deleting and adding user
LevanovaElena Oct 8, 2023
c33a645
added alert for errors
LevanovaElena Oct 8, 2023
e57d93e
refactoring,added state,fixed errors
LevanovaElena Oct 9, 2023
eb7944d
add socket
LevanovaElena Oct 11, 2023
64f89f8
added messages in chat
LevanovaElena Oct 12, 2023
74e6eb7
fixed errors
LevanovaElena Oct 12, 2023
e1b69a4
fixed errors
LevanovaElena Oct 12, 2023
657712e
fixed errors
LevanovaElena Oct 12, 2023
3fb6e52
fixed linter errors
LevanovaElena Oct 12, 2023
73e4f94
fixed linter errors
LevanovaElena Oct 12, 2023
4bfcb0d
fixed linter errors
LevanovaElena Oct 12, 2023
a1d7810
fixed test errors
LevanovaElena Oct 12, 2023
3322fbd
fixed test errors
LevanovaElena Oct 12, 2023
98c75a6
fixed test errors
LevanovaElena Oct 12, 2023
b8ff43b
fixed test errors
LevanovaElena Oct 12, 2023
b86f931
fixed errors
LevanovaElena Oct 13, 2023
97bd231
added modal for load avatar for chat
LevanovaElena Oct 13, 2023
7c2c87b
added modal for load file for send message
LevanovaElena Oct 13, 2023
9b15d6b
fixed eslint
LevanovaElena Oct 13, 2023
d96e2ec
fixed submit
LevanovaElena Oct 15, 2023
11e5c68
added states to profile
LevanovaElena Oct 15, 2023
51e7237
delete routes:/setting-password and /settings-edit
LevanovaElena Oct 15, 2023
709002e
delete routes:/login, fixed errors
LevanovaElena Oct 15, 2023
0fa47e7
fixed json
LevanovaElena Oct 15, 2023
c133d5c
fixed json
LevanovaElena Oct 15, 2023
8faf80f
fixed json
LevanovaElena Oct 15, 2023
0ea94be
added submit message
LevanovaElena Oct 15, 2023
9848919
fixed errors
LevanovaElena Oct 15, 2023
deb2c3b
fixed errors
LevanovaElena Oct 15, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"build": "eslint . &&tsc && vite build",
"preview": "vite preview",
"start": "tsc && vite build && node ./server.js",
"stylelint": "stylelint src/**/*.pcss",
"stylelint": "stylelint src/**/*.pcss ",
"eslint": "eslint . "
},
"devDependencies": {
Expand Down
1 change: 1 addition & 0 deletions public/_redirects
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/* /index.html 200
6 changes: 4 additions & 2 deletions server.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// server.js
const express = require('express');
const PORT = 3000;
const path = require('path');
const PORT = process.env.PORT || 3000;

const app = express();

Expand All @@ -11,4 +12,5 @@ app.listen(PORT, function () {
console.log(`⚡️[server]: Server is running at http://localhost:${PORT} ${__dirname}`);
});


app.use('/', express.static(path.join(__dirname, 'dist')));
app.use('*', express.static(path.join(__dirname, 'dist/index.html')));
27 changes: 27 additions & 0 deletions src/api/auth.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import HTTPTransport from "../core/http.ts";
import {IAuthData, IUser} from "../models/IUser.ts";

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • При добавлении пользователя в чат через нажатие на Enter страница перезагружается. Это нужно предотвращать во время сабмита формы. И при попытке добавить новый чат это происходит

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • Нужно отображать историю сообщений при входе в чат

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

export class AuthApi {
private httpTransport = new HTTPTransport();
private readonly baseUrl: string | null = null;

constructor(baseUrl?: string) {
if (baseUrl) this.baseUrl = baseUrl;
}

public signUp(userData: IUser) {
return this.httpTransport.post(this.baseUrl + '/signup', {data: userData});
}

public signIn(userData: IAuthData) {
return this.httpTransport.post(this.baseUrl + '/signin', {data: userData});
}
public getAuthUser() {
return this.httpTransport.get(this.baseUrl + '/user');
}
public logOut() {
return this.httpTransport.post(this.baseUrl + '/logout');
}
}

export default AuthApi
42 changes: 42 additions & 0 deletions src/api/chat.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import HTTPTransport from "../core/http.ts";
import {IChatUsersData} from "../models/IChat.ts";

export class ChatApi {
private httpTransport = new HTTPTransport();
private readonly baseUrl: string = '/chats';

constructor(baseUrl?: string) {
if (baseUrl) this.baseUrl = baseUrl;
}

public getChats() {
return this.httpTransport.get(this.baseUrl);
}

public createChat(title: string) {
return this.httpTransport.post(this.baseUrl, {data: {title: title}});
}

public addChatUsers(userData: IChatUsersData) {
return this.httpTransport.put(this.baseUrl + '/users', {data: userData});
}

public deleteChatUsers(userData: IChatUsersData) {
return this.httpTransport.delete(this.baseUrl + '/users', {data: userData});
}

public getChatUsers(id: string) {
return this.httpTransport.get(this.baseUrl + `/${id}/users`);
}

public getChatToken(id: string) {
return this.httpTransport.post(this.baseUrl + `/token/${id}`);
}

public updateChatAvatar(file: FormData, chatId: number) {
file.append('chatId', String(chatId));
return this.httpTransport.put(this.baseUrl + '/avatar', {data: file});
}
}

export default ChatApi
16 changes: 16 additions & 0 deletions src/api/resources.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import HTTPTransport from "../core/http.ts";

export class ResourcesApi {
private httpTransport = new HTTPTransport();
private readonly baseUrl: string = '/resources';

constructor(baseUrl?: string) {
if (baseUrl) this.baseUrl = baseUrl;
}

public uploadResource(file: FormData) {
return this.httpTransport.post(this.baseUrl, {data: file});
}
}

export default ResourcesApi
79 changes: 79 additions & 0 deletions src/api/socket.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
//'wss://ya-praktikum.tech/ws/chats/<USER_ID>/<CHAT_ID>/<TOKEN_VALUE>'
class SocketIO {
private STATES = ['CONNECTING', 'OPEN', 'CLOSING', 'CLOSED'];
private readonly socket: WebSocket | null = null;

constructor(url: string, user_id?: string, chat_id?: string, token?: string) {
let _url = url;
if (user_id) _url = _url + '/' + user_id;
if (chat_id) _url = _url + '/' + chat_id;
if (token) _url = _url + '/' + token;
this.socket = this.init(_url)
}

private init = (url: string) => {
return new WebSocket(url);
}

public getState = () => {
if (!this.socket) return this.STATES[3];
return this.STATES[this.socket.readyState];
}
public open = (callBack: () => void) => {
this.socket?.addEventListener('open', callBack);
}

public close = (callBack: (event: CloseEvent) => void) => {
const funk = (event: CloseEvent) => {
callBack(event);

}
this.socket?.addEventListener('close', funk);
}

public message = (callBack: (event: MessageEvent) => void) => {
const funk = (event: MessageEvent) => {
callBack(event);
}
this.socket?.addEventListener('message', funk);
}

public error(callBack: (event: Event) => void) {
this.socket?.addEventListener('error', callBack);
}

public sendMessage = (message: string) => {
const _message = JSON.stringify(
{
content: message,
type: "message"
})
this.socket?.send(_message);
}
public sendFile = (idResource: string) => {
const _message = JSON.stringify(
{
content: idResource,
type: "file"
})
this.socket?.send(_message);
}
public sendRequestForgetMessage = (limit: number = 0) => {
const _message = JSON.stringify(
{
content: String(limit),
type: "get old"
})
this.socket?.send(_message);
}

public ping = () => {
this.socket?.send(JSON.stringify({
type: "ping"
}));
}


}

export default SocketIO;
29 changes: 29 additions & 0 deletions src/api/user-settings.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import HTTPTransport from "../core/http.ts";
import {IPasswords, IUser} from "../models/IUser.ts";

export class UserSettingsApi {
private httpTransport = new HTTPTransport();
private readonly baseUrl: string | null = null;

constructor(baseUrl?: string) {
if (baseUrl) this.baseUrl = baseUrl;
}

public changeUserProfile(userData: IUser) {
return this.httpTransport.put(this.baseUrl + '/profile', {data: userData});
}

public changeUserAvatar(file: FormData) {
return this.httpTransport.put(this.baseUrl + '/profile/avatar', {data: file});
}

public changeUserPassword(data: IPasswords) {
return this.httpTransport.put(this.baseUrl + '/password', {data: data});
}

public searchUser(login: string) {
return this.httpTransport.post(this.baseUrl + '/search', {data:{login: login}});
}
}

export default UserSettingsApi
15 changes: 15 additions & 0 deletions src/assets/icons/chat-avatar.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7 changes: 7 additions & 0 deletions src/assets/icons/circle-plus.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions src/assets/icons/circle-x.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions src/assets/icons/close.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
12 changes: 12 additions & 0 deletions src/assets/icons/file.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion src/assets/icons/image.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions src/assets/icons/location.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
27 changes: 27 additions & 0 deletions src/components/alert/alert.pcss
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
.alert {
display: flex;
align-items: center;
justify-content: center;
padding: 10px;
min-height: 100px;
z-index:1000;

.alert__message {
text-align: center;
font-size: 1.2em;
}

.alert__close {
position: absolute;
right: 0;
top:0;
}
}

.dialog-alert {
border: none;
width: 340px;
inset: 0;
position: fixed;
margin: auto;
}
36 changes: 36 additions & 0 deletions src/components/alert/alert.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import {IProps, Block} from "../../core/block.ts";
import alertController from "../../core/alert-controller.ts";

interface IModalProps extends IProps {
message: string,
okClick?: (event: Event) => void,
}

export class Alert extends Block {
constructor(props: IModalProps) {
props.okClick=()=>{
alertController.closeModal();
}

super({
...props
})
}

public get props() {
return this._props as IModalProps;
}

protected render(): string {
const {message = ''} = this.props;
return (`
<div class="alert">
<p class="alert__message">
${message}
</p>
<div class="alert__close">
{{{ Button onClick=okClick type='close'}}}</div>
</div>
`)
}
}
2 changes: 2 additions & 0 deletions src/components/alert/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import './alert.pcss';
export { Alert as default } from './alert.ts';
2 changes: 1 addition & 1 deletion src/components/avatar/avatar.pcss
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
.avatar {
border-radius: 100px;
border: 1px var(--red) solid;
cursor: pointer;
display: flex;
justify-content: center;
align-items: center;
Expand Down Expand Up @@ -31,6 +30,7 @@
}

.avatar__hover {
cursor: pointer;
transition: .5s ease;
opacity: 0;
position: absolute;
Expand Down
Loading
Loading