2023-07-27 07:31:52 +02:00
|
|
|
/*
|
2024-02-13 16:59:27 +01:00
|
|
|
* SPDX-FileCopyrightText: syuilo and misskey-project
|
2023-07-27 07:31:52 +02:00
|
|
|
* SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
*/
|
|
|
|
|
2024-02-06 08:45:21 +01:00
|
|
|
import * as Misskey from 'misskey-js';
|
2022-05-01 15:51:07 +02:00
|
|
|
import { defineAsyncComponent, Ref, ref } from 'vue';
|
2023-09-19 09:37:43 +02:00
|
|
|
import { popup } from '@/os.js';
|
2023-12-14 06:11:20 +01:00
|
|
|
import { defaultStore } from '@/store.js';
|
2021-03-05 05:49:46 +01:00
|
|
|
|
|
|
|
class ReactionPicker {
|
|
|
|
private src: Ref<HTMLElement | null> = ref(null);
|
|
|
|
private manualShowing = ref(false);
|
2024-02-06 08:45:21 +01:00
|
|
|
private targetNote: Ref<Misskey.entities.Note | null> = ref(null);
|
2021-11-18 15:32:43 +01:00
|
|
|
private onChosen?: (reaction: string) => void;
|
|
|
|
private onClosed?: () => void;
|
2021-03-05 05:49:46 +01:00
|
|
|
|
|
|
|
constructor() {
|
|
|
|
// nop
|
|
|
|
}
|
|
|
|
|
|
|
|
public async init() {
|
2023-12-14 06:11:20 +01:00
|
|
|
const reactionsRef = defaultStore.reactiveState.reactions;
|
2022-08-30 17:24:33 +02:00
|
|
|
await popup(defineAsyncComponent(() => import('@/components/MkEmojiPickerDialog.vue')), {
|
2021-03-05 05:49:46 +01:00
|
|
|
src: this.src,
|
2023-12-14 06:11:20 +01:00
|
|
|
pinnedEmojis: reactionsRef,
|
2021-03-05 05:49:46 +01:00
|
|
|
asReactionPicker: true,
|
2024-02-06 08:45:21 +01:00
|
|
|
targetNote: this.targetNote,
|
2022-12-22 08:01:59 +01:00
|
|
|
manualShowing: this.manualShowing,
|
2021-03-05 05:49:46 +01:00
|
|
|
}, {
|
|
|
|
done: reaction => {
|
2023-12-14 06:11:20 +01:00
|
|
|
if (this.onChosen) this.onChosen(reaction);
|
2021-03-05 05:49:46 +01:00
|
|
|
},
|
|
|
|
close: () => {
|
|
|
|
this.manualShowing.value = false;
|
|
|
|
},
|
|
|
|
closed: () => {
|
|
|
|
this.src.value = null;
|
2023-12-14 06:11:20 +01:00
|
|
|
if (this.onClosed) this.onClosed();
|
2022-12-22 08:01:59 +01:00
|
|
|
},
|
2021-03-05 05:49:46 +01:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2024-02-06 08:45:21 +01:00
|
|
|
public show(src: HTMLElement | null, targetNote: Misskey.entities.Note | null, onChosen?: ReactionPicker['onChosen'], onClosed?: ReactionPicker['onClosed']) {
|
2021-03-05 05:49:46 +01:00
|
|
|
this.src.value = src;
|
2024-02-06 08:45:21 +01:00
|
|
|
this.targetNote.value = targetNote;
|
2021-03-05 05:49:46 +01:00
|
|
|
this.manualShowing.value = true;
|
|
|
|
this.onChosen = onChosen;
|
|
|
|
this.onClosed = onClosed;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export const reactionPicker = new ReactionPicker();
|