スレッドモードの場合、コメントへの返信を動的に読み込むように設定し、「返信を表示する」ボタンをクリックすることで、返信を読み込めます。
loadRepliesOnDemandプロパティをtrueに設定すると、返信の動的読み込み機能を有効に設定できます。
また、collapseRepliesModeプロパティを利用して、返信を動的に読み込む場合の折りたたみ表示を設定することができます。commentInfoActionプロパティには、GcCommentCollapseRepliesMode列挙体の次の値を設定することができます。
GcCommentCollapseRepliesModeの値
説明
NotAllowed
折りたたみ表示しない
TopLevel
第1階層の返信のみを折りたたむことができる
EveryLevel
すべての階層の返信を折りたたむことができる
import "./styles.css";
import "@mescius/inputman.comment/CSS/gc.inputman.comment.css";
import "@mescius/inputman.richtexteditor/CSS/gc.inputman.richtexteditor.css";
import { InputMan } from "@mescius/inputman.comment";
import * as RichTextEditorControl from "@mescius/inputman.richtexteditor";
import { postedComments } from './data';
const gcComment = new InputMan.GcComment(document.getElementById('gcComment'), {
commentMode: InputMan.GcCommentMode.ThreadMode,
collapseRepliesMode: InputMan.GcCommentCollapseRepliesMode.EveryLevel,
loadRepliesOnDemand: true,
loadCommentReplies: async (comment, loadedCount) => {
let replies = postedComments.filter(c => c.parentCommentId === comment.id);
let repliesCount = replies.length;
let loadOnceCount = 1;
return {
comments: replies.splice(loadedCount, loadOnceCount),
hasMore: loadedCount + loadOnceCount < repliesCount
};
},
editorConfig: {
editorType: InputMan.GcCommentEditorType.GcRichTextEditor,
baseUrl: '$IMDEMOROOT$/lib/purejs/node_modules/@mescius/inputman.richtexteditor/JS',
plugins: [RichTextEditorControl.InputMan.GcRichTextEditorPluginItem.All],
height: 150,
menubar: [],
toolbar: [
RichTextEditorControl.InputMan.GcRichTextEditorToolbarItem.FontFamily,
RichTextEditorControl.InputMan.GcRichTextEditorToolbarItem.Bold,
RichTextEditorControl.InputMan.GcRichTextEditorToolbarItem.Italic,
RichTextEditorControl.InputMan.GcRichTextEditorToolbarItem.Strikethrough,
RichTextEditorControl.InputMan.GcRichTextEditorToolbarItem.Underline,
]
},
userInfo: {
id: '1',
name: '森上 偉久馬',
avatar: '$IMDEMOROOT$/ja/samples/comment/replies/repliesOnDemand/img/avatar1.png',
},
loadComments: () => ({
comments: postedComments.filter((c) => c.replyCount !== undefined && !c.parentCommentId),
hasMore: false,
}),
});
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<meta name="description" content="コメントコンポーネント 使い方" lang="ja" xml:lang="ja" />
<title>コメントコンポーネント - 返信の動的読み込み</title>
<!-- SystemJS -->
<script src="node_modules/systemjs/dist/system.src.js"></script>
<script src="systemjs.config.js"></script>
<script>
window.onload = function () {
System.import('./src/app');
}
</script>
</head>
<body>
<div id="gcComment"></div>
</body>
</html>
body {
box-sizing: content-box !important;
height: 551px !important;
}
export const postedComments = [
{
id: '1',
userInfo: {
id: '1',
name: '森上 偉久馬',
avatar: '$IMDEMOROOT$/ja/samples/comment/replies/repliesOnDemand/img/avatar1.png',
},
content: `<b>このサンプルではコメントの返信を動的読み込み機能を有効にしています。</b>
<p>「返信を表示する」をクリックすると、動的に読み込むことができます。</p>`,
postTime: new Date(2024, 1, 1, 8, 0, 0),
updateTime: new Date(2024, 1, 1, 8, 0, 0),
replyCount: 2
},
{
id: '2',
userInfo: {
id: '4',
name: '川村 匡',
avatar: '$IMDEMOROOT$/ja/samples/comment/replies/repliesOnDemand/img/avatar4.png',
},
content: 'すべての返信が読み込まれると、「返信を非表示にする」ボタンが表示され、返信を折りたたみに設定できます。',
postTime: new Date(2024, 4, 20, 8, 1, 1),
updateTime: new Date(2024, 4, 20, 8, 1, 1),
parentCommentId: '1',
reactions: [
{
reactionChar: '👍',
count: 1,
},
],
replyCount: 4
},
{
id: '3',
userInfo: {
id: '1',
name: '森上 偉久馬',
avatar: '$IMDEMOROOT$/ja/samples/comment/replies/repliesOnDemand/img/avatar1.png',
},
content: '森上です。こちらは動的読み込みの返信です。',
postTime: new Date(2024, 6, 15, 8, 1, 26),
updateTime: new Date(2024, 6, 15, 8, 1, 26),
parentCommentId: '2',
reactions: [
{
reactionChar: '👍',
count: 1,
},
],
},
{
id: '4',
userInfo: {
id: '6',
name: '成宮 真紀',
avatar: '$IMDEMOROOT$/ja/samples/comment/replies/repliesOnDemand/img/avatar6.png',
},
content: '成宮です。こちらは動的読み込みの返信です。',
postTime: new Date(2024, 6, 15, 8, 1, 0),
updateTime: new Date(2024, 6, 15, 8, 1, 0),
parentCommentId: '2',
reactions: [
{
reactionChar: '👍',
count: 1,
},
],
},
{
id: '5',
userInfo: {
id: '2',
name: '葛城 孝史',
avatar: '$IMDEMOROOT$/ja/samples/comment/replies/repliesOnDemand/img/avatar2.png',
},
content: '葛城です。こちらは動的読み込みの返信です。',
postTime: new Date(2024, 6, 15, 8, 1, 10),
updateTime: new Date(2024, 6, 15, 8, 1, 10),
parentCommentId: '2',
reactions: [
{
reactionChar: '🔥',
count: 1,
},
],
},
{
id: '6',
userInfo: {
id: '6',
name: '成宮 真紀',
avatar: '$IMDEMOROOT$/ja/samples/comment/replies/repliesOnDemand/img/avatar4.png',
},
content: '成宮です。こちらは動的読み込みの返信です。',
postTime: new Date(2024, 6, 20, 8, 1, 15),
updateTime: new Date(2024, 6, 20, 8, 1, 15),
parentCommentId: '1',
reactions: [
{
reactionChar: '👍',
count: 1,
},
],
},
{
id: '7',
userInfo: {
id: '2',
name: '葛城 孝史',
avatar: '$IMDEMOROOT$/ja/samples/comment/replies/repliesOnDemand/img/avatar2.png',
},
content: '葛城です。こちらは動的読み込みの返信です。',
postTime: new Date(2024, 6, 20, 8, 1, 20),
updateTime: new Date(2024, 6, 20, 8, 1, 20),
parentCommentId: '2',
reactions: [
{
reactionChar: '🔥',
count: 1,
},
],
},
{
id: '8',
userInfo: {
id: '1',
name: '森上 偉久馬',
avatar: '$IMDEMOROOT$/ja/samples/comment/replies/repliesOnDemand/img/avatar1.png',
},
content: '森上です。こちらは動的読み込みの返信です。',
postTime: new Date(2024, 6, 20, 8, 1, 25),
updateTime: new Date(2024, 6, 20, 8, 1, 25),
parentCommentId: '2',
reactions: [
{
reactionChar: '🔥',
count: 1,
},
],
},
];
System.config({
transpiler: 'plugin-babel',
babelOptions: {
es2015: true
},
meta: {
'*.css': { loader: 'css' }
},
paths: {
// paths serve as alias
'npm:': 'node_modules/'
},
// map tells the System loader where to look for things
map: {
'@mescius/inputman': 'npm:@mescius/inputman/index.js',
'@mescius/inputman/CSS': 'npm:@mescius/inputman/CSS',
'@mescius/inputman.richtexteditor': 'npm:@mescius/inputman.richtexteditor/index.js',
'@mescius/inputman.richtexteditor/CSS': 'npm:@mescius/inputman.richtexteditor/CSS',
'@mescius/inputman.comment': 'npm:@mescius/inputman.comment/index.js',
'@mescius/inputman.comment/CSS': 'npm:@mescius/inputman.comment/CSS',
'css': 'npm:systemjs-plugin-css/css.js',
'plugin-babel': 'npm:systemjs-plugin-babel/plugin-babel.js',
'systemjs-babel-build': 'npm:systemjs-plugin-babel/systemjs-babel-browser.js'
},
// packages tells the System loader how to load when no filename and/or no extension
packages: {
src: {
defaultExtension: 'js'
},
"node_modules": {
defaultExtension: 'js'
},
}
});