mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-13 21:05:19 +00:00
fix(editor): time issues of comment initialization (#13031)
#### PR Dependency Tree * **PR #13031** 👈 This tree was auto-generated by [Charcoal](https://github.com/danerwilliams/charcoal) <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **New Features** * Added the ability to filter comments by their resolution status (resolved, unresolved, or all) when viewing or managing comments. * **Refactor** * Improved the way commented text is identified and retrieved, resulting in more reliable comment selection and filtering. * Enhanced comment retrieval to support asynchronous data loading, ensuring up-to-date comment information. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
This commit is contained in:
@@ -138,8 +138,10 @@ class AffineCommentService implements CommentProvider {
|
||||
this.commentEntity.highlightComment(id);
|
||||
}
|
||||
|
||||
getComments(): string[] {
|
||||
return this.commentEntity.getComments();
|
||||
async getComments(
|
||||
type: 'resolved' | 'unresolved' | 'all' = 'all'
|
||||
): Promise<string[]> {
|
||||
return this.commentEntity.getComments(type);
|
||||
}
|
||||
|
||||
onCommentAdded(callback: (id: string, selections: BaseSelection[]) => void) {
|
||||
|
||||
@@ -14,7 +14,16 @@ import {
|
||||
onStart,
|
||||
} from '@toeverything/infra';
|
||||
import { nanoid } from 'nanoid';
|
||||
import { catchError, of, Subject, switchMap, tap, timer } from 'rxjs';
|
||||
import {
|
||||
catchError,
|
||||
filter,
|
||||
first,
|
||||
of,
|
||||
Subject,
|
||||
switchMap,
|
||||
tap,
|
||||
timer,
|
||||
} from 'rxjs';
|
||||
|
||||
import { type DocDisplayMetaService } from '../../doc-display-meta';
|
||||
import { GlobalContextService } from '../../global-context';
|
||||
@@ -280,8 +289,30 @@ export class DocCommentEntity extends Entity<{
|
||||
this.commentHighlighted$.next(id);
|
||||
}
|
||||
|
||||
getComments(): CommentId[] {
|
||||
return this.comments$.value.map(comment => comment.id);
|
||||
async getComments(
|
||||
type: 'resolved' | 'unresolved' | 'all' = 'all'
|
||||
): Promise<CommentId[]> {
|
||||
return new Promise<CommentId[]>(resolve => {
|
||||
this.revalidate();
|
||||
this.loading$
|
||||
.pipe(
|
||||
filter(loading => !loading),
|
||||
first()
|
||||
)
|
||||
.subscribe(() => {
|
||||
resolve(
|
||||
this.comments$.value
|
||||
.filter(comment =>
|
||||
type === 'all'
|
||||
? true
|
||||
: type === 'resolved'
|
||||
? comment.resolved
|
||||
: !comment.resolved
|
||||
)
|
||||
.map(comment => comment.id)
|
||||
);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
onCommentAdded(
|
||||
|
||||
@@ -214,9 +214,12 @@ export class Editor extends Entity {
|
||||
const std = editorContainer.host.std;
|
||||
|
||||
// First try to find inline commented texts
|
||||
const inlineCommentedSelections = findCommentedTexts(std, commentId);
|
||||
const inlineCommentedSelections = findCommentedTexts(
|
||||
std.store,
|
||||
commentId
|
||||
);
|
||||
if (inlineCommentedSelections.length > 0) {
|
||||
const firstSelection = inlineCommentedSelections[0][0];
|
||||
const firstSelection = inlineCommentedSelections[0];
|
||||
finalId = firstSelection.from.blockId;
|
||||
finalKey = 'blockIds';
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user