2023-11-01 11:06:37 +00:00
|
|
|
import { IMentionHighlight, IMentionSuggestion } from "@plane/lite-text-editor";
|
|
|
|
import { RootStore } from "../root";
|
|
|
|
import { computed, makeObservable } from "mobx";
|
|
|
|
|
|
|
|
export interface IMentionsStore {
|
2023-11-08 15:01:46 +00:00
|
|
|
mentionSuggestions: IMentionSuggestion[];
|
|
|
|
mentionHighlights: IMentionHighlight[];
|
2023-11-01 11:06:37 +00:00
|
|
|
}
|
|
|
|
|
2023-11-08 15:01:46 +00:00
|
|
|
export class MentionsStore implements IMentionsStore {
|
|
|
|
// root store
|
|
|
|
rootStore;
|
2023-11-01 11:06:37 +00:00
|
|
|
|
2023-11-08 15:01:46 +00:00
|
|
|
constructor(_rootStore: RootStore) {
|
|
|
|
// rootStore
|
|
|
|
this.rootStore = _rootStore;
|
2023-11-01 11:06:37 +00:00
|
|
|
|
2023-11-08 15:01:46 +00:00
|
|
|
makeObservable(this, {
|
|
|
|
mentionHighlights: computed,
|
|
|
|
mentionSuggestions: computed,
|
|
|
|
});
|
|
|
|
}
|
2023-11-01 11:06:37 +00:00
|
|
|
|
2023-11-08 15:01:46 +00:00
|
|
|
get mentionSuggestions() {
|
|
|
|
const projectMembers = this.rootStore.project.projectMembers;
|
2023-11-01 11:06:37 +00:00
|
|
|
|
2023-11-08 15:01:46 +00:00
|
|
|
const suggestions =
|
|
|
|
projectMembers === null
|
|
|
|
? []
|
|
|
|
: projectMembers.map((member) => ({
|
2023-11-01 11:06:37 +00:00
|
|
|
id: member.member.id,
|
|
|
|
type: "User",
|
|
|
|
title: member.member.display_name,
|
|
|
|
subtitle: member.member.email ?? "",
|
|
|
|
avatar: member.member.avatar,
|
|
|
|
redirect_uri: `/${member.workspace.slug}/profile/${member.member.id}`,
|
2023-11-08 15:01:46 +00:00
|
|
|
}));
|
2023-11-01 11:06:37 +00:00
|
|
|
|
2023-11-08 15:01:46 +00:00
|
|
|
return suggestions;
|
|
|
|
}
|
2023-11-01 11:06:37 +00:00
|
|
|
|
2023-11-08 15:01:46 +00:00
|
|
|
get mentionHighlights() {
|
|
|
|
const user = this.rootStore.user.currentUser;
|
|
|
|
return user ? [user.id] : [];
|
|
|
|
}
|
|
|
|
}
|