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

feat: initial mention suggestions #1482

Open
wants to merge 1 commit into
base: test-server
Choose a base branch
from
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
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ <h6 class="com-mt-0 com-mb-2">Updates</h6>
[addAttachment]="true"
(contentChange)="createEventUpdate($event)"
(uploadImages)="uploadImages($event)"
[mentionParams]="{ parent_type: 'Event', parent_id: event.id }"
></commudle-editor>

<div *ngIf="showPreviewImages" class="image-preview-section">
Expand Down
5 changes: 3 additions & 2 deletions libs/editor/src/lib/components/editor/editor.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ export class EditorComponent implements OnInit, OnDestroy {
@Input() status: NbComponentStatus = 'basic';
@Input() appearance: NbButtonAppearance = 'filled';
@Input() addAttachment = false;
@Input() mentionParams: { parent_type: string; parent_id: number } = { parent_type: '', parent_id: 0 };

@Output() contentChange = new EventEmitter<string>();
@Output() uploadImages = new EventEmitter<any>();
Expand Down Expand Up @@ -87,9 +88,9 @@ export class EditorComponent implements OnInit, OnDestroy {
History,
Link,
KeyboardHandler,
CustomMention(this.injector),
CustomMention(this.injector, this.mentionParams),
],
viewer: [Document, Text, Paragraph, Link, CustomMention(this.injector)],
viewer: [Document, Text, Paragraph, Link, CustomMention(this.injector, this.mentionParams)],
};
}

Expand Down
4 changes: 2 additions & 2 deletions libs/editor/src/lib/extensions/mention.ts
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ const Mention = (injector: Injector): Node => {
});
};

export function CustomMention(injector: Injector) {
export function CustomMention(injector: Injector, params: Record<string, any>) {
const mentionService = injector.get(MentionsService);

return Mention(injector).configure({
Expand All @@ -168,7 +168,7 @@ export function CustomMention(injector: Injector) {
suggestion: {
items: ({ query }) => {
return mentionService
.getMentions(query)
.getMentions(query, params.parent_type, params.parent_id)
.pipe(map((res) => res.results))
.toPromise();
},
Expand Down
4 changes: 2 additions & 2 deletions libs/editor/src/lib/services/mentions.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import { IMention } from '../models/mentions.model';
export class MentionsService {
constructor(private http: HttpClient, private baseApiService: BaseApiService) {}

getMentions(query: string): Observable<IMention> {
const params = new HttpParams().set('query', query);
getMentions(query: string, parent_type: string, parent_id: number): Observable<IMention> {
const params = new HttpParams().set('query', query).set('parent_type', parent_type).set('parent_id', parent_id);
return this.http.get<IMention>(this.baseApiService.getRoute(API_ROUTES.MENTIONS.INDEX), { params });
}
}