Skip to content
Open
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
2 changes: 1 addition & 1 deletion server/src/dto/diary.dto.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger';
import { IsDateString, IsInt, IsNotEmpty, IsNumber, IsOptional, IsString, Max, Min, ValidateIf } from 'class-validator';
import { IsDateString, IsNotEmpty, IsNumber, IsOptional, IsString, Max, Min, ValidateIf } from 'class-validator';
import { string } from 'joi';
import { DiaryEncryption, DiaryEntity } from 'src/entities/diary.entity';

Expand Down
2 changes: 1 addition & 1 deletion server/src/entities/diary.entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,4 @@ export class DiaryEntity {

@Column({ type: 'varchar', default: DiaryEncryption.NONE })
encryption: DiaryEncryption;
}
}
3 changes: 1 addition & 2 deletions server/src/interfaces/diary.interface.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { AuthDto } from 'src/dto/auth.dto';
import { DiaryEntity } from 'src/entities/diary.entity';
import { UserEntity } from 'src/entities/user.entity';

Expand All @@ -10,4 +9,4 @@ export interface IDiaryRepository {
delete(id: string);
}

export const IDiaryRepository = 'IDiaryRepository';
export const IDiaryRepository = 'IDiaryRepository';
4 changes: 2 additions & 2 deletions server/src/repositories/diary.repository.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Inject, Injectable } from '@nestjs/common';
import { Injectable } from '@nestjs/common';
import { InjectRepository } from '@nestjs/typeorm';
import { DiaryEntity } from 'src/entities/diary.entity';
import { UserEntity } from 'src/entities/user.entity';
Expand Down Expand Up @@ -44,4 +44,4 @@ export class DiaryRepository implements IDiaryRepository {
const { id } = await this.diaryRepository.save(user);
return this.diaryRepository.findOneOrFail({ where: { id }, withDeleted: true });
}
}
}
10 changes: 5 additions & 5 deletions server/src/services/diary.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,28 +8,28 @@ export class DiaryService {
constructor(@Inject(IDiaryRepository) private diaryRepository: IDiaryRepository) {}

async create(auth: AuthDto, dto: DiaryCreateDto): Promise<DiaryResponseDto> {
let diary = await this.diaryRepository.getByDateAndUser(dto.date, auth.user);
const diary = await this.diaryRepository.getByDateAndUser(dto.date, auth.user);
if (diary) throw new BadRequestException('Diary entry already exists');

return this.diaryRepository.create({ ...dto, user: auth.user }).then(mapDiary);
}

async delete(auth: AuthDto, date: string): Promise<void> {
let diary = await this.diaryRepository.getByDateAndUser(date, auth.user);
const diary = await this.diaryRepository.getByDateAndUser(date, auth.user);
if (!diary) throw new BadRequestException('Diary not found');

return this.diaryRepository.delete(diary.id);
}

async edit(auth: AuthDto, date: string, dto: DiaryEditDto) {
let diary = await this.diaryRepository.getByDateAndUser(date, auth.user);
const diary = await this.diaryRepository.getByDateAndUser(date, auth.user);
if (!diary) throw new BadRequestException('Diary not found');

return mapDiary(await this.diaryRepository.update({ id: diary.id, ...dto }));
}

async get(auth: AuthDto, date: string) {
let diary = await this.diaryRepository.getByDateAndUser(date, auth.user);
const diary = await this.diaryRepository.getByDateAndUser(date, auth.user);
if (!diary) throw new BadRequestException('Diary not found');

return mapDiary(diary);
Expand All @@ -42,4 +42,4 @@ export class DiaryService {
diaries: diaries.map((diary) => mapDiary(diary)),
};
}
}
}
4 changes: 1 addition & 3 deletions web/src/lib/Navbar.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,7 @@
>
<h1 class="font-bold text-4xl ml-2">PRM</h1>
<div class="flex justify-between gap-16 pr-6">

<section class="flex place-items-center justify-end gap-4 max-sm:w-full">
</section>
<section class="flex place-items-center justify-end gap-4 max-sm:w-full"></section>
</div>
</div>
</section>
7 changes: 3 additions & 4 deletions web/src/lib/UserPageLayout.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,11 @@
import Navbar from '$lib/Navbar.svelte';

export let hideNavbar = false;

</script>

<header>
{#if !hideNavbar}
<Navbar/>
<Navbar />
{/if}

<slot name="header" />
Expand All @@ -18,10 +17,10 @@
class="relative grid h-screen grid-cols-[theme(spacing.18)_auto] overflow-hidden bg-prm-bg pt-[var(--navbar-height)] md:grid-cols-[theme(spacing.64)_auto]"
>
<slot name="sidebar">
<Sidebar/>
<Sidebar />
</slot>

<section class="relative">
<slot/>
<slot />
</section>
</main>
75 changes: 39 additions & 36 deletions web/src/lib/components/shared-components/selector.svelte
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<script>
import { onMount } from 'svelte';
import { writable } from 'svelte/store';

export let contacts = [];
Expand Down Expand Up @@ -27,8 +26,8 @@
const match = value.match(/@(\w*)$/);
if (match) {
const query = match[1].toLowerCase();
const filteredContacts = contacts.filter(contact =>
contact.name.toLowerCase().startsWith(query) || contact.lastname.toLowerCase().startsWith(query)
const filteredContacts = contacts.filter(
(contact) => contact.name.toLowerCase().startsWith(query) || contact.lastname.toLowerCase().startsWith(query),
);
suggestions.set(filteredContacts);
highlightedIndex.set(-1);
Expand All @@ -43,16 +42,18 @@
}

function selectSuggestion(contact) {
inputValue.update(value => {
inputValue.update((value) => {
const lastAtIndex = value.lastIndexOf('@');
const newValue = value.slice(0, lastAtIndex) + `<span contenteditable="false" class="mention-span">@${contact.name} ${contact.lastname}</span>&nbsp;`;
const newValue =
value.slice(0, lastAtIndex) +
`<span contenteditable="false" class="mention-span">@${contact.name} ${contact.lastname}</span>&nbsp;`;
editableDiv.innerHTML = newValue;
renderedText.set(newValue);
updateBackendText(newValue);
setCursorToEnd(editableDiv);
return newValue;
});
selectedContactIds.update(ids => [...ids, contact.id]);
selectedContactIds.update((ids) => [...ids, contact.id]);
hiddenInputElement.value = $selectedContactIds.join(',');
showSuggestions.set(false);
}
Expand All @@ -61,10 +62,10 @@
if ($showSuggestions) {
if (event.key === 'ArrowDown') {
event.preventDefault();
highlightedIndex.update(n => (n + 1) % $suggestions.length);
highlightedIndex.update((n) => (n + 1) % $suggestions.length);
} else if (event.key === 'ArrowUp') {
event.preventDefault();
highlightedIndex.update(n => (n - 1 + $suggestions.length) % $suggestions.length);
highlightedIndex.update((n) => (n - 1 + $suggestions.length) % $suggestions.length);
} else if (event.key === 'Enter') {
event.preventDefault();
if ($highlightedIndex >= 0) {
Expand Down Expand Up @@ -115,9 +116,9 @@
mentionedNames.push(match[1]);
}

selectedContactIds.update(ids => {
const newIds = ids.filter(id => {
const contact = contacts.find(contact => contact.id === id);
selectedContactIds.update((ids) => {
const newIds = ids.filter((id) => {
const contact = contacts.find((contact) => contact.id === id);
if (contact) {
const fullName = `${contact.name} ${contact.lastname}`;
return mentionedNames.includes(fullName);
Expand All @@ -135,7 +136,7 @@

function updateBackendText(value) {
let text = value;
contacts.forEach(contact => {
contacts.forEach((contact) => {
const fullName = `${contact.name} ${contact.lastname}`;
const mentionText = `<span contenteditable="false" class="mention-span">@${fullName}</span>`;
if (text.includes(mentionText)) {
Expand All @@ -146,6 +147,32 @@
}
</script>

<div>
<div
bind:this={editableDiv}
contenteditable="true"
on:input={handleInput}
on:keydown={handleKeyDown}
class="editable-div {submitState == 'no_content' ? 'red-outline' : ''}"
{placeholder}
>
{@html content}
</div>
<input bind:this={hiddenInputElement} type="hidden" />
{#if $showSuggestions}
<div class="bg-gray-800 suggestions">
{#each $suggestions as contact, index}
<div
class="suggestion {index === $highlightedIndex ? 'highlighted' : ''}"
on:click={() => selectSuggestion(contact)}
>
{`${contact.name} ${contact.lastname}`}
</div>
{/each}
</div>
{/if}
</div>

<style>
.suggestions {
border: 1px solid #ccc;
Expand Down Expand Up @@ -186,27 +213,3 @@
width: 100%;
}
</style>

<div>
<div
bind:this={editableDiv}
contenteditable="true"
on:input={handleInput}
on:keydown={handleKeyDown}
class="editable-div {submitState == 'no_content' ? 'red-outline' : ''}"
placeholder={placeholder}
>{@html content}</div>
<input bind:this={hiddenInputElement} type="hidden" />
{#if $showSuggestions}
<div class="bg-gray-800 suggestions">
{#each $suggestions as contact, index}
<div
class="suggestion {index === $highlightedIndex ? 'highlighted' : ''}"
on:click={() => selectSuggestion(contact)}
>
{`${contact.name} ${contact.lastname}`}
</div>
{/each}
</div>
{/if}
</div>
6 changes: 4 additions & 2 deletions web/src/lib/components/shared-components/sidebar-link.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@
let currentTab = 'home';
let path = $page.url.pathname;

if (path == '/diary') currentTab = 'diary';
if (path == '/diary') {
currentTab = 'diary';
}
</script>

<div class="roboto bar-container">
Expand Down Expand Up @@ -135,4 +137,4 @@
top: 6vh;
}
}
</style>
</style>
6 changes: 3 additions & 3 deletions web/src/lib/modals/CustomModal.svelte
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<script>
export let showModal;
export let showCloseButton = true;
export let classes = "";
export let width = "80";
export let height = "80";
export let classes = '';
export let width = '80';
export let height = '80';

let dialog;

Expand Down