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

Feature/profile add about me #206

Merged
merged 3 commits into from
Dec 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 0 additions & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,6 @@
"@angular-eslint/template/attributes-order": "warn",
"@angular-eslint/template/banana-in-box": "error",
"@angular-eslint/template/conditional-complexity": "error",
"@angular-eslint/template/cyclomatic-complexity": "error",
"@angular-eslint/template/no-interpolation-in-attributes": "error",
"@angular-eslint/template/no-negated-async": "error",
"@angular-eslint/template/no-positive-tabindex": "error",
Expand Down
4 changes: 2 additions & 2 deletions src/app/app.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import { AppInstanceIdInterceptor } from '@shared/util/logging/app-instance-id.i
import { defaultStoreProvider } from '@state-adapt/angular';
import { DancierBackendMockedService } from '@shared/data-access/dancier-backend-mocked.service';
import { UnauthorizedInterceptor } from '@shared/util/auth/unauthorized.interceptor';
import { AuthWithCredentialsInterceptor } from '@shared/util/auth/auth-with-credentials.interceptor';
import { WithCredentialsInterceptor } from '@shared/util/auth/with-credentials-interceptor.service';

const httpInterceptorProviders = [
{
Expand All @@ -32,7 +32,7 @@ const httpInterceptorProviders = [
},
{
provide: HTTP_INTERCEPTORS,
useClass: AuthWithCredentialsInterceptor,
useClass: WithCredentialsInterceptor,
multi: true,
},
{
Expand Down
6 changes: 3 additions & 3 deletions src/app/chat/data-access/chat-http.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import {
MessageResponse,
MessageResponseWithChatId,
} from './chat.types';
import { ProfileService } from '@shared/data-access/profile/profile.service';
import { ProfileOldService } from '@shared/data-access/profile/profile-old.service';

@Injectable({
providedIn: 'root',
Expand All @@ -30,7 +30,7 @@ export class ChatHttpService {
private readonly chatApiUrl: string;
private readonly dancerApiUrl: string;

private profileService = inject(ProfileService);
private profileService = inject(ProfileOldService);

constructor(
private http: HttpClient,
Expand Down Expand Up @@ -66,7 +66,7 @@ export class ChatHttpService {
this.http
// .get<ChatList>('/chats', this.defaultOptions)
.get<ChatList>(this.chatApiUrl, this.defaultOptions)
.pipe(map((chatList) => chatList.chats))
.pipe(map((chatList) => chatList.chats || []))
);
}

Expand Down
40 changes: 19 additions & 21 deletions src/app/chat/data-access/chat-state.adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,27 +9,25 @@ import {
import { HttpErrorResponse } from '@angular/common/http';

export const chatStateAdapter = createAdapter<ChatAdaptState>()({
chatsFetched: (state, chatsDto: ChatDto[]) => ({
...state,
chatsFetchState: 'loaded',
chatCreated: false,
chats: [
// only add new chats (chat id not in state yet)
...state.chats,
...chatsDto
.filter(
(chatDto) =>
!state.chats.find((stateChat) => stateChat.id === chatDto.chatId)
)
.map((chatDto) => ({
id: chatDto.chatId,
participants: chatDto.dancerIds.map((dancerId) => ({
id: dancerId,
})),
messages: [],
})),
],
}),
chatsFetched: (state, chatsDto: ChatDto[]) => {
const newChats = chatsDto
.filter(
(chatDto) =>
!state.chats.find((stateChat) => stateChat.id === chatDto.chatId)
)
.map((chatDto) => ({
id: chatDto.chatId,
participants: chatDto.dancerIds.map((dancerId) => ({ id: dancerId })),
messages: [],
}));

return {
...state,
chatsFetchState: 'loaded',
chatCreated: false,
chats: [...state.chats, ...newChats],
};
},

chatsFetchedError: (state, chatsFetchError: HttpErrorResponse) => ({
...state,
Expand Down
4 changes: 2 additions & 2 deletions src/app/chat/ui/chat-conversation-header.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { CommonModule } from '@angular/common';
import { ChatStateService } from '../data-access/chat-state.service';
import { ChatParticipant } from '../data-access/chat.types';
import { toSignal } from '@angular/core/rxjs-interop';
import { ProfileService } from '@shared/data-access/profile/profile.service';
import { ProfileOldService } from '@shared/data-access/profile/profile-old.service';
import { startWith } from 'rxjs/operators';
import { Profile } from '../../profile/data-access/types/profile.types';
import { map } from 'rxjs';
Expand Down Expand Up @@ -37,7 +37,7 @@ export class ChatConversationHeaderComponent {
private chatState = inject(ChatStateService);

ownProfileId: Signal<string | undefined> = toSignal(
inject(ProfileService).profile$.pipe(
inject(ProfileOldService).profile$.pipe(
startWith({
id: 'dancerId1',
} as Profile),
Expand Down
4 changes: 2 additions & 2 deletions src/app/chat/ui/chat-messages/chat-messages.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { AsyncPipe, JsonPipe, NgClass, NgFor, NgIf } from '@angular/common';
import { ChatMessage } from '../../data-access/chat.types';
import { ChatStateService } from '../../data-access/chat-state.service';
import { toSignal } from '@angular/core/rxjs-interop';
import { ProfileService } from '@shared/data-access/profile/profile.service';
import { ProfileOldService } from '@shared/data-access/profile/profile-old.service';
import { startWith } from 'rxjs/operators';
import { Profile } from '../../../profile/data-access/types/profile.types';
import { map } from 'rxjs';
Expand Down Expand Up @@ -50,7 +50,7 @@ import { map } from 'rxjs';
export class ChatMessagesComponent {
chatState = inject(ChatStateService);
ownUserId: Signal<string | undefined> = toSignal(
inject(ProfileService).profile$.pipe(
inject(ProfileOldService).profile$.pipe(
startWith({
id: 'dancerId1',
} as Profile),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {
} from '../../data-access/chat-state.service';
import { ImageService } from '@shared/data-access/image.service';
import { ChatParticipant } from '../../data-access/chat.types';
import { ProfileService } from '@shared/data-access/profile/profile.service';
import { ProfileOldService } from '@shared/data-access/profile/profile-old.service';
import { map } from 'rxjs';
import { toSignal } from '@angular/core/rxjs-interop';
import { startWith } from 'rxjs/operators';
Expand Down Expand Up @@ -62,7 +62,7 @@ import { Profile } from '../../../profile/data-access/types/profile.types';
export class ChatConversationListEntryComponent {
chatState = inject(ChatStateService);
ownProfileId: Signal<string | undefined> = toSignal(
inject(ProfileService).profile$.pipe(
inject(ProfileOldService).profile$.pipe(
startWith({
id: 'dancerId1',
} as Profile),
Expand Down Expand Up @@ -115,7 +115,7 @@ export class ChatConversationListEntryComponent {
// constructor(
// public imageService: ImageService,
// public chatStore: ChatStore,
// public profileService: ProfileService,
// public profileService: ProfileOldService,
// public router: Router
// ) {
// this.profileService.profile$.subscribe((profile) => {
Expand Down
4 changes: 2 additions & 2 deletions src/app/chat/ui/old/chat.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
// } from '../../common/types/chat.types';
// import { combineLatest, map, Observable, shareReplay, switchMap } from 'rxjs';
// import { Router } from '@angular/router';
// import { ProfileService } from '@shared/profile/profile.service';
// import { ProfileOldService } from '@shared/profile/profile.service';
//
// type FetchChatsDto = {
// chats: ChatDto[];
Expand Down Expand Up @@ -47,7 +47,7 @@
// private http: HttpClient,
// private environment: EnvironmentService,
// private authStorageService: AuthStorageService,
// private profileService: ProfileService,
// private profileService: ProfileOldService,
// private router: Router
// ) {
// this.chatApiUrl = `${this.environment.getApiUrl()}/chats`;
Expand Down
4 changes: 2 additions & 2 deletions src/app/chat/ui/old/chat.store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
// withLatestFrom,
// } from 'rxjs';
// import { ChatService } from './chat.service';
// import { ProfileService } from '@shared/profile/profile.service';
// import { ProfileOldService } from '@shared/profile/profile.service';
// import { EnvironmentService } from '@shared/common/environment.service';
//
// export type ChatState = {
Expand Down Expand Up @@ -47,7 +47,7 @@
// {
// constructor(
// private chatService: ChatService,
// private profileService: ProfileService,
// private profileService: ProfileOldService,
// private environmentService: EnvironmentService // @Inject(IntervalSchedulerToken) private scheduler: SchedulerLike
// ) {
// super(defaultState);
Expand Down
12 changes: 12 additions & 0 deletions src/app/profile/data-access/profile.service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { Injectable } from '@angular/core';

@Injectable({
providedIn: 'root',
})
export class ProfileService {
constructor() {}

// public getOwnProfile(): void {}
//
// public getProfile(dancerId: string): void {}
}
2 changes: 1 addition & 1 deletion src/app/profile/data-access/types/profile.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ export type Dance = {
};

export type PersonalData = {
aboutMe: string;
size: number;
gender: Gender;
birthDate: string;
Expand All @@ -60,7 +61,6 @@ export type PersonalData = {

export type Profile = PersonalData & {
id?: string;
aboutMe: string;
dancerName: string;
ableTo: Dance[];
wantsTo: Dance[];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ <h2 class="my-4 text-2xl">Profilbild</h2>
? croppedImage
: (profileService.getProfileImageSrc() | async)
"
(error)="handleMissingImage($event)"
/>
</div>

Expand Down
12 changes: 10 additions & 2 deletions src/app/profile/feature/edit-profile/edit-profile.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
ReactiveFormsModule,
} from '@angular/forms';
import { APIError, APIResponse } from '@shared/util/http/response.types';
import { ProfileService } from '@shared/data-access/profile/profile.service';
import { ProfileOldService } from '@shared/data-access/profile/profile-old.service';
import {
Profile,
UploadedImageDao,
Expand All @@ -23,6 +23,7 @@ import { DanceExperienceFormComponent } from '../../ui/dance-experience-form/dan
import { PersonalDataFormComponent } from '../../ui/personal-data-form/personal-data-form.component';
import { AsyncPipe, NgIf } from '@angular/common';
import { MatButtonModule } from '@angular/material/button';
import { ImageService } from '@shared/data-access/image.service';

type EditProfileForm = {
personalData: FormGroup<Partial<PersonalDataForm>>;
Expand Down Expand Up @@ -60,8 +61,9 @@ export class EditProfileComponent {

constructor(
private fb: NonNullableFormBuilder,
public profileService: ProfileService,
public profileService: ProfileOldService,
private imageUploadService: ImageUploadService,
private imageService: ImageService,
private router: Router
) {}

Expand All @@ -88,6 +90,7 @@ export class EditProfileComponent {
if (this.profileForm.valid) {
const formValues = this.profileForm.getRawValue();
const profile: Partial<Profile> = {
aboutMe: formValues.personalData!.aboutMe!,
size: formValues.personalData!.size!,
birthDate: format(formValues.personalData!.birthDate!, 'yyyy-MM-dd', {
locale: de,
Expand Down Expand Up @@ -123,4 +126,9 @@ export class EditProfileComponent {
this.profileForm.markAllAsTouched();
}
}

handleMissingImage($event: ErrorEvent): void {
($event.target as HTMLImageElement).src =
this.imageService.getDefaultDancerImage();
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Component } from '@angular/core';
import { Router } from '@angular/router';
import { ProfileService } from '@shared/data-access/profile/profile.service';
import { ProfileOldService } from '@shared/data-access/profile/profile-old.service';
import { FormGroup, ReactiveFormsModule } from '@angular/forms';
import { DanceExperienceForm } from '../../../ui/dance-experience-form/dance-form.type';
import { Dance } from '../../../data-access/types/profile.types';
Expand Down Expand Up @@ -30,7 +30,10 @@ export class InitDanceExperienceComponent {

apiError?: APIError;

constructor(public profileService: ProfileService, private router: Router) {}
constructor(
public profileService: ProfileOldService,
private router: Router
) {}

submitForm(): void {
if (this.form.valid && this.form.value.dances) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Component } from '@angular/core';
import { Router } from '@angular/router';
import { ProfileService } from '@shared/data-access/profile/profile.service';
import { ProfileOldService } from '@shared/data-access/profile/profile-old.service';
import { FormGroup, ReactiveFormsModule } from '@angular/forms';
import { DanceExperienceForm } from '../../../ui/dance-experience-form/dance-form.type';
import { Dance } from '../../../data-access/types/profile.types';
Expand Down Expand Up @@ -30,7 +30,10 @@ export class InitPartnerDanceExperienceComponent {

apiError?: APIError;

constructor(public profileService: ProfileService, private router: Router) {}
constructor(
public profileService: ProfileOldService,
private router: Router
) {}

submitForm(): void {
if (this.form.valid && this.form.value.dances) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Component } from '@angular/core';
import { FormGroup, ReactiveFormsModule } from '@angular/forms';
import { Router } from '@angular/router';
import { ProfileService } from '@shared/data-access/profile/profile.service';
import { ProfileOldService } from '@shared/data-access/profile/profile-old.service';
import { PersonalData } from '../../../data-access/types/profile.types';
import { UntilDestroy } from '@ngneat/until-destroy';
import { APIError } from '@shared/util/http/response.types';
Expand Down Expand Up @@ -34,7 +34,10 @@ export class InitPersonalDataComponent {

error?: APIError;

constructor(public profileService: ProfileService, private router: Router) {}
constructor(
public profileService: ProfileOldService,
private router: Router
) {}

submitForm(): void {
if (this.personalDataForm.valid) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Component } from '@angular/core';
import { ImageUploadService } from '../../../data-access/image-upload.service';
import { ImageCroppedEvent, ImageCropperModule } from 'ngx-image-cropper';
import { ProfileService } from '@shared/data-access/profile/profile.service';
import { ProfileOldService } from '@shared/data-access/profile/profile-old.service';
import { APIResponse } from '@shared/util/http/response.types';
import { UploadedImageDao } from '../../../data-access/types/profile.types';
import { Router } from '@angular/router';
Expand All @@ -22,7 +22,7 @@ export class InitProfileImageComponent {

constructor(
private imageUploadService: ImageUploadService,
private profileService: ProfileService,
private profileService: ProfileOldService,
private router: Router
) {}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,11 @@ describe('Setting up username', () => {
}),
},
MockProvider(AuthStorageService, {
authData$: of({ isLoggedIn: true, isHuman: true }),
authData$: of({
isLoggedIn: true,
isHuman: true,
jwt: 'token',
}),
}),
],
stubsEnabled: false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
} from '@angular/forms';
import { Router } from '@angular/router';
import { ProfileHttpService } from '@shared/data-access/profile/profile-http.service';
import { ProfileService } from '@shared/data-access/profile/profile.service';
import { ProfileOldService } from '@shared/data-access/profile/profile-old.service';
import {
APIError,
APIResponse,
Expand Down Expand Up @@ -44,7 +44,7 @@ export class InitUserNameComponent {
error?: APIError;

constructor(
public profileService: ProfileService,
public profileService: ProfileOldService,
private profileHttpService: ProfileHttpService,
private fb: NonNullableFormBuilder,
private router: Router
Expand Down
Loading
Loading