ObsiViewer/src/app/editor/services/comment.service.ts
Bruno Charest ee3085ce38 feat: add Nimbus Editor with Unsplash integration
- Integrated Unsplash API for image search functionality with environment configuration
- Added new Nimbus Editor page component with navigation from sidebar and mobile drawer
- Enhanced TOC with highlight animation for editor heading navigation
- Improved CDK overlay z-index hierarchy for proper menu layering
- Removed obsolete logging validation script
2025-11-11 11:38:27 -05:00

90 lines
2.0 KiB
TypeScript

import { Injectable, signal, computed } from '@angular/core';
export interface Comment {
id: string;
blockId: string;
author: string;
text: string;
createdAt: Date;
resolved?: boolean;
}
@Injectable({
providedIn: 'root'
})
export class CommentService {
private comments = signal<Comment[]>([]);
/**
* Get all comments for a specific block
*/
getCommentsForBlock(blockId: string): Comment[] {
return this.comments().filter(c => c.blockId === blockId);
}
/**
* Get comment count for a specific block
*/
getCommentCount(blockId: string): number {
return this.comments().filter(c => c.blockId === blockId && !c.resolved).length;
}
/**
* Add a comment to a block
*/
addComment(blockId: string, text: string, author: string = 'User'): void {
const newComment: Comment = {
id: this.generateId(),
blockId,
author,
text,
createdAt: new Date()
};
this.comments.update(comments => [...comments, newComment]);
}
/**
* Delete a comment
*/
deleteComment(commentId: string): void {
this.comments.update(comments => comments.filter(c => c.id !== commentId));
}
/**
* Mark comment as resolved
*/
resolveComment(commentId: string): void {
this.comments.update(comments =>
comments.map(c => c.id === commentId ? { ...c, resolved: true } : c)
);
}
/**
* Get all comments
*/
getAllComments(): Comment[] {
return this.comments();
}
private generateId(): string {
return Math.random().toString(36).substring(2, 11);
}
/**
* Add test comments to specific blocks (for demo purposes)
*/
addTestComments(blockIds: string[]): void {
blockIds.forEach((blockId, index) => {
// Add 1-3 random comments per block
const commentCount = Math.floor(Math.random() * 3) + 1;
for (let i = 0; i < commentCount; i++) {
this.addComment(
blockId,
`Test comment ${i + 1} for block`,
`User ${index + 1}`
);
}
});
}
}