-
Notifications
You must be signed in to change notification settings - Fork 140
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
Задание на проверку ТГ: @my4kish #82
Open
my4kish
wants to merge
3
commits into
RYAZHAPOVILNUR:master
Choose a base branch
from
my4kish:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,19 @@ | ||
import { ApplicationConfig } from '@angular/core'; | ||
import { ApplicationConfig, isDevMode } from '@angular/core'; | ||
import { provideRouter } from '@angular/router'; | ||
|
||
import { routes } from './app.routes'; | ||
import { provideHttpClient } from '@angular/common/http'; | ||
import { provideStore } from '@ngrx/store'; | ||
import { userReducer } from './users-list/store/user.reducer'; | ||
import { provideStoreDevtools } from '@ngrx/store-devtools'; | ||
|
||
export const appConfig: ApplicationConfig = { | ||
providers: [provideRouter(routes)] | ||
providers: [ | ||
provideRouter(routes), | ||
provideHttpClient(), | ||
provideStore({ | ||
users: userReducer | ||
}), | ||
provideStoreDevtools({ maxAge: 25, logOnly: !isDevMode() }) | ||
] | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,9 @@ | ||
import { Routes } from '@angular/router'; | ||
import { UserListComponent } from './users-list/users-list.component'; | ||
|
||
export const routes: Routes = []; | ||
export const routes: Routes = [ | ||
{ | ||
path: 'users', | ||
component: UserListComponent, | ||
} | ||
]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<mat-toolbar class="header"> | ||
<span>Junior task</span> | ||
<div class="nav"> | ||
<a mat-button href="http://localhost:4200">Главная</a> | ||
<a mat-button href="http://localhost:4200/users">Пользователи</a> | ||
</div> | ||
</mat-toolbar> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
.header{ | ||
display: flex; | ||
gap: 220px; | ||
box-shadow: 0 -6px 10px 5px rgba(0,0,0,0.5); | ||
} | ||
|
||
.nav{ | ||
display: flex; | ||
gap: 20px; | ||
} | ||
|
||
.nav>a{ | ||
font-size: medium; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { Component } from "@angular/core"; | ||
import {MatToolbarModule} from '@angular/material/toolbar'; | ||
import { MatButtonModule } from "@angular/material/button"; | ||
|
||
@Component({ | ||
selector: 'header', | ||
standalone: true, | ||
templateUrl: './header.component.html', | ||
styleUrl: './header.component.scss', | ||
imports: [MatToolbarModule, MatButtonModule], | ||
}) | ||
export class Header{ | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { Injectable } from '@angular/core'; | ||
import { User } from './users-list/users-list.component'; | ||
|
||
@Injectable({ | ||
providedIn: 'root', | ||
}) | ||
export class LocalStorageService { | ||
getItem(key: string): User[] | null { | ||
const data = localStorage.getItem(key); | ||
return data ? JSON.parse(data) : null; | ||
} | ||
|
||
setItem(key: string, data: object): void { | ||
localStorage.setItem(key, JSON.stringify(data)); | ||
} | ||
|
||
removeItem(key: string): boolean { | ||
localStorage.removeItem(key); | ||
return true; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { HttpClient } from '@angular/common/http'; | ||
import { inject, Injectable } from '@angular/core'; | ||
|
||
@Injectable({ providedIn: 'root' }) | ||
export class UsersApiService { | ||
private readonly apiService = inject(HttpClient); | ||
|
||
getUsers() { | ||
return this.apiService.get('https://jsonplaceholder.typicode.com/users'); | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
src/app/users-list/create-edit-user-dialog/create-edit-user-dialog.component.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<div class="dialog"> | ||
<h1>{{this.data.isEdit ? 'Редактирование пользователя' : 'Создание пользователя'}}</h1> | ||
<form [formGroup] = "form" class="form"> | ||
<mat-form-field> | ||
<mat-label>Имя</mat-label> | ||
<input matInput class="form-input" formControlName="name" /> | ||
</mat-form-field> | ||
<mat-form-field> | ||
<mat-label>Почта</mat-label> | ||
<input matInput class="form-input" formControlName="email" /> | ||
</mat-form-field> | ||
<mat-form-field> | ||
<mat-label>Вебсайт</mat-label> | ||
<input matInput class="form-input" formControlName="website" /> | ||
</mat-form-field> | ||
<mat-form-field> | ||
<mat-label>Компания</mat-label> | ||
<input matInput class="form-input" formControlName="companyName" /> | ||
</mat-form-field> | ||
<button color="accent" mat-flat-button [mat-dialog-close]="form.value" [disabled]="form.invalid">{{this.data.isEdit ? 'Edit user' : 'Create user'}}</button> | ||
</form> | ||
</div> |
9 changes: 9 additions & 0 deletions
9
src/app/users-list/create-edit-user-dialog/create-edit-user-dialog.component.scss
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
|
||
.dialog{ | ||
margin: 30px; | ||
} | ||
|
||
.form{ | ||
display: flex; | ||
flex-direction: column; | ||
} |
32 changes: 32 additions & 0 deletions
32
src/app/users-list/create-edit-user-dialog/create-edit-user-dialog.component.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import { Component, EventEmitter, inject, Output } from "@angular/core"; | ||
import { FormControl, FormGroup, ReactiveFormsModule, Validators } from "@angular/forms"; | ||
import { MAT_DIALOG_DATA, MatDialogClose, MatDialogRef } from "@angular/material/dialog"; | ||
import {MatInputModule} from '@angular/material/input'; | ||
import {MatFormFieldModule} from '@angular/material/form-field'; | ||
import {MatButtonModule} from '@angular/material/button'; | ||
|
||
@Component({ | ||
selector:'app-create-user-dialog', | ||
templateUrl:'./create-edit-user-dialog.component.html', | ||
styleUrl:'./create-edit-user-dialog.component.scss', | ||
imports:[ReactiveFormsModule, MatDialogClose, MatInputModule, MatFormFieldModule, MatButtonModule], | ||
standalone: true, | ||
}) | ||
export class CreateEditUserDialogComponent{ | ||
public readonly data = inject(MAT_DIALOG_DATA) | ||
private readonly dialogRef = inject(MatDialogRef<CreateEditUserDialogComponent>); | ||
|
||
@Output() | ||
isEditable = new EventEmitter(); | ||
|
||
public form = new FormGroup({ | ||
name: new FormControl(this.data?.user?.name, [Validators.required]), | ||
email:new FormControl(this.data?.user?.email, [Validators.required, Validators.email]), | ||
website:new FormControl(this.data?.user?.website, [Validators.required, Validators.minLength(3)]), | ||
companyName:new FormControl(this.data?.user?.company.name, [Validators.required]), | ||
}) | ||
|
||
public editUser() { | ||
this.dialogRef?.close(this.form.value) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import { createReducer, on } from '@ngrx/store'; | ||
import { UsersActions } from './users.actions'; | ||
import { User } from '../users-list.component'; | ||
|
||
const initialState: { users: User[] } = { | ||
users: [], | ||
}; | ||
|
||
export const userReducer = createReducer( | ||
initialState, | ||
on(UsersActions.set, (state, payload) => ({ | ||
...state, | ||
users: payload.users, | ||
})), | ||
on(UsersActions.edit, (state, payload) => ({ | ||
...state, | ||
users: state.users.map((user) => { | ||
if (user.id === payload.user.id) { | ||
return payload.user; | ||
} else { | ||
return user; | ||
} | ||
}), | ||
})), | ||
on(UsersActions.create, (state, payload) => ({ | ||
...state, | ||
users: [...state.users, payload.user], | ||
})), | ||
on(UsersActions.delete, (state, payload) => ({ | ||
...state, | ||
users: state.users.filter((user) => user.id !== payload.id), | ||
})) | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { createActionGroup, props } from '@ngrx/store'; | ||
import { User } from '../users-list.component'; | ||
|
||
export const UsersActions = createActionGroup({ | ||
source: 'Users', | ||
events: { | ||
set: props<{ users: User[] }>(), | ||
edit: props<{ user: User }>(), | ||
create: props<{ user: User }>(), | ||
delete: props<{ id: number }>(), | ||
}, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { createSelector } from '@ngrx/store'; | ||
import { User } from '../users-list.component'; | ||
|
||
interface UserState { | ||
users: User[]; | ||
} | ||
|
||
interface AppState { | ||
users: UserState; | ||
} | ||
|
||
export const selectUsersFeature = (state: AppState) => state.users; | ||
|
||
export const selectUsers = createSelector( | ||
selectUsersFeature, | ||
(state: UserState) => state.users | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<mat-card class="users-card"> | ||
<mat-card-header> | ||
<mat-card-title> | ||
<p>{{user.name}}</p> | ||
</mat-card-title> | ||
</mat-card-header> | ||
<mat-card-content> | ||
<p>{{user.email}}</p> | ||
<p>{{user.website}}</p> | ||
<p>{{user.company.name}}</p> | ||
</mat-card-content> | ||
<mat-card-actions class="users-card-btns"> | ||
<button class="users-card-btn" mat-raised-button (click)="onUserEdit(user)">Редактировать юзера</button> | ||
<button class="users-card-btn delete" mat-raised-button (click)="onDeleteUser(user.id)">Удалить юзера</button> | ||
</mat-card-actions> | ||
</mat-card> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
|
||
.users-card{ | ||
max-width: 400px; | ||
} | ||
|
||
.users-card-btns{ | ||
gap: 10px; | ||
margin: 10px; | ||
} | ||
|
||
.users-card-btn.delete{ | ||
background-image: linear-gradient(147deg, #fe8a39 0%, #fd3838 74%); | ||
color: whitesmoke; | ||
} | ||
|
||
.users-card-btn:disabled{ | ||
background-image: none; | ||
color: grey; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import { Component, EventEmitter, Input, Output } from "@angular/core"; | ||
import {MatCardModule} from '@angular/material/card'; | ||
import {MatButton} from '@angular/material/button'; | ||
|
||
@Component({ | ||
selector:'app-user-card', | ||
templateUrl:'./user-card.component.html', | ||
styleUrl:'./user-card.component.scss', | ||
standalone:true, | ||
imports: [MatCardModule, MatButton], | ||
}) | ||
export class UserCardComponent{ | ||
|
||
@Input() | ||
user:any | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. типизируйте, не стоит использовать any |
||
|
||
@Output() | ||
deleteUser = new EventEmitter() | ||
|
||
@Output() | ||
userEdit = new EventEmitter() | ||
|
||
onDeleteUser(userId:number) { | ||
this.deleteUser.emit(userId) | ||
} | ||
|
||
onUserEdit(user: any) { | ||
this.userEdit.emit(user) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<div class="users-list"> | ||
<button class="add-user-btn" mat-raised-button (click)="openDialog()">Добавить пользователя</button> | ||
<div class="users-list-cards"> | ||
<div *ngFor="let item of users$ | async"> | ||
<app-user-card [user]="item" (deleteUser)="deleteUser($event)" (userEdit)="openDialog($event)"></app-user-card> | ||
</div> | ||
</div> | ||
</div> |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
удалите лишнюю строку