Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
22 changes: 20 additions & 2 deletions frontend/src/app/components/add-post-modal/add-post.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ export class AddPostComponent {
}

async addBucketPost() {
const boardID: string = this.data.bucket!.bucketID;
const bucketID: string = this.data.bucket!.bucketID;
const post: Post = {
postID: generateUniqueID(),
userID: this.user.userID,
Expand All @@ -123,14 +123,32 @@ export class AddPostComponent {
displayAttributes: null,
};

return await this.canvasService.createBucketPost(boardID, post);
return await this.canvasService.createBucketPost(bucketID, post);
}

async addListPost() {
const post: Post = {
postID: generateUniqueID(),
userID: this.user.userID,
boardID: this.board.boardID,
author: this.user.username,
type: PostType.BUCKET,
Comment thread
LunarFang416 marked this conversation as resolved.
Outdated
title: this.title,
desc: this.message,
tags: this.tags,
displayAttributes: null,
};

return await this.canvasService.createListPost(post);
}

async handleDialogSubmit() {
let post: Post;

if (this.data.type == PostType.BUCKET && this.data.bucket) {
post = await this.addBucketPost();
} else if (this.data.type == PostType.BUCKET) {
Comment thread
LunarFang416 marked this conversation as resolved.
Outdated
post = await this.addListPost();
} else {
post = await this.addPost();
}
Expand Down
9 changes: 5 additions & 4 deletions frontend/src/app/components/canvas/canvas.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,7 @@ export class CanvasComponent implements OnInit, OnDestroy {
ListModalComponent,
{
board: this.board,
user: this.user,
},
'95vw'
);
Expand Down Expand Up @@ -462,13 +463,13 @@ export class CanvasComponent implements OnInit, OnDestroy {
}

onResize(event) {
let scaleX = event.target.innerWidth / this.canvas.getWidth();
const scaleX = event.target.innerWidth / this.canvas.getWidth();
// Without toolbar height
let scaleY = (event.target.innerHeight - 64) / this.canvas.getHeight();
let objects = this.canvas.getObjects();
const scaleY = (event.target.innerHeight - 64) / this.canvas.getHeight();
const objects = this.canvas.getObjects();

// Resize all objects inside the canvas
for (var i in objects) {
for (const i in objects) {
objects[i].scaleX = objects[i].getObjectScaling().scaleX * scaleY;
objects[i].scaleY = objects[i].getObjectScaling().scaleY * scaleY;
objects[i].left = (objects[i].left || 0) * scaleX;
Expand Down
12 changes: 11 additions & 1 deletion frontend/src/app/components/list-modal/list-modal.component.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
<h1 mat-dialog-title>
<span>CK List</span>
<div style="display: flex;">
<span>CK List</span>
<button
mat-icon-button
matTooltip="Create Post"
(click)="openAddPostDialog()"
style="margin:0; padding:0;line-height: inherit;height: inherit;"
>
<mat-icon class="material-icons-outlined">note_add</mat-icon>
</button>
</div>
<button mat-icon-button [mat-dialog-close] aria-label="Close">
<mat-icon>close</mat-icon>
</button>
Expand Down
36 changes: 34 additions & 2 deletions frontend/src/app/components/list-modal/list-modal.component.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,23 @@
import { Component, Inject, OnDestroy, OnInit } from '@angular/core';
import { MatDialogRef, MAT_DIALOG_DATA } from '@angular/material/dialog';
import {
MatDialog,
MatDialogRef,
MAT_DIALOG_DATA,
} from '@angular/material/dialog';
import { Board } from 'src/app/models/board';
import Post from 'src/app/models/post';
import Post, { PostType } from 'src/app/models/post';
import { BucketService } from 'src/app/services/bucket.service';
import { PostService } from 'src/app/services/post.service';
import { SocketService } from 'src/app/services/socket.service';
import { SocketEvent } from 'src/app/utils/constants';
import { HTMLPost } from '../html-post/html-post.component';
import Converters from '../../utils/converters';
import { Tag } from 'src/app/models/tag';
import {
AddPostComponent,
AddPostDialog,
} from 'src/app/components/add-post-modal/add-post.component';
import User from 'src/app/models/user';
Comment thread
LunarFang416 marked this conversation as resolved.

@Component({
selector: 'app-list-modal',
Expand All @@ -17,6 +26,7 @@ import { Tag } from 'src/app/models/tag';
})
export class ListModalComponent implements OnInit, OnDestroy {
board: Board;
user: User;

loading = true;
loadingMore = false;
Expand All @@ -31,13 +41,15 @@ export class ListModalComponent implements OnInit, OnDestroy {

constructor(
public dialogRef: MatDialogRef<ListModalComponent>,
public dialog: MatDialog,
public bucketService: BucketService,
public postService: PostService,
public socketService: SocketService,
public converters: Converters,
@Inject(MAT_DIALOG_DATA) public data: any
) {
this.board = data.board;
this.user = data.user;
}

ngOnInit(): void {
Expand Down Expand Up @@ -171,6 +183,26 @@ export class ListModalComponent implements OnInit, OnDestroy {
}
}

openAddPostDialog() {
const dialogData: AddPostDialog = {
type: PostType.BUCKET,
spawnPosition: {
top: 150,
left: 150,
},
board: this.board,
user: this.user,
onComplete: async (post: Post) => {
const htmlPost = await this.converters.toHTMLPost(post);
this.posts.push(htmlPost);
},
};
this.dialog.open(AddPostComponent, {
width: '500px',
data: dialogData,
});
}

ngOnDestroy(): void {
this.posts = [];
}
Expand Down
6 changes: 6 additions & 0 deletions frontend/src/app/services/canvas.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,12 @@ export class CanvasService {
return savedPost;
}

async createListPost(post: Post) {
const savedPost = await this.postService.create(post);

return savedPost;
}

async createBoardPostFromBucket(post: Post) {
const upvotes = await this.upvotesService.getUpvotesByPost(post.postID);
const comments = await this.commentService.getCommentsByPost(post.postID);
Expand Down