diff --git a/webui-src/app/channels/channel_view.js b/webui-src/app/channels/channel_view.js index 4fc4dd4..5ab1832 100644 --- a/webui-src/app/channels/channel_view.js +++ b/webui-src/app/channels/channel_view.js @@ -329,95 +329,105 @@ const AddComment = () => { ]), }; }; - -function DisplayComment(commentStruct, identity) { - const comment = commentStruct.comment; +function DisplayComment() { + // No reliance on initialisation signature return { oninit: (v) => { - console.log(comment.mComment); + console.log(v.attrs.commentStruct.comment.mComment); }, - view: (v) => [ - m('tr', [ - m('i.fas.fa-angle-right', { - class: 'fa-rotate-' + (commentStruct.showReplies ? '90' : '0'), - style: 'margin-top:12px', - onclick: () => { - commentStruct.showReplies = !commentStruct.showReplies; - // console.log(commentStruct.showReplies); - }, - }), - - m('td', comment.mComment), - m( - 'select[id=options]', - { - onchange: (e) => { - if (e.target.selectedIndex === 1) { - // reply - util.popupMessage( - m(AddComment, { - parent_comment: comment.mComment, - channelId: comment.mMeta.mGroupId, - authorId: identity, - threadId: comment.mMeta.mThreadId, - parentId: comment.mMeta.mMsgId, - }) - ); - } else if (e.target.selectedIndex === 2) { - // voteUP - AddVote( - util.GXS_VOTE_UP, - comment.mMeta.mGroupId, - comment.mMeta.mThreadId, - identity, - comment.mMeta.mMsgId - ); - } else if (e.target.selectedIndex === 3) { - AddVote( - util.GXS_VOTE_DOWN, - comment.mMeta.mGroupId, - comment.mMeta.mThreadId, - identity, - comment.mMeta.mMsgId - ); - } + view: ({ attrs: { commentStruct, identity } }) => { + // Use component / vnode interface instead + const comment = commentStruct.comment; + let parMap = []; + if (Data.ParentCommentMap[comment.mMeta.mMsgId]) { + parMap = Array.from(Data.ParentCommentMap[comment.mMeta.mMsgId]); + } // console.log(parMap); + // console.log(Array.from(Data.ParentCommentMap[comment.mMeta.mMsgId])); + return [ + m('tr', [ + (parMap.length > 0)?m('td', m('i.fas.fa-angle-right', { + class: 'fa-rotate-' + (commentStruct.showReplies ? '90' : '0'), + style: 'margin-top:12px', + onclick: () => { + commentStruct.showReplies = !commentStruct.showReplies; }, - }, - [ - m('option[hidden][selected]', 'Options'), - util.optionSelect.opts.map((option) => - m('option', { value: option }, option.toLocaleString()) - ), - ] - ), - m('td', rs.userList.userMap[comment.mMeta.mAuthorId]), - m( - 'td', - typeof comment.mMeta.mPublishTs === 'object' - ? new Date(comment.mMeta.mPublishTs.xint64 * 1000).toLocaleString() - : 'undefined' - ), - m('td', comment.mScore), - m('td', comment.mUpVotes), - m('td', comment.mDownVotes), - ]), - commentStruct.showReplies - ? Data.ParentCommentMap[comment.mMeta.mMsgId] - // ? m('tr', m('td', 'hello world')) - ? Data.ParentCommentMap[comment.mMeta.mMsgId].forEach( - (value) => - Data.Comments[value.mMeta.mThreadId] && - Data.Comments[value.mMeta.mThreadId][value.mMeta.mMsgId] - ? - m(DisplayComment( - Data.Comments[value.mMeta.mThreadId][value.mMeta.mMsgId], - identity - )) - : '' - ) - : '' - : '', - ], + })):m('td', ''), + + m('td', comment.mComment), + m( + 'select[id=options]', + { + onchange: (e) => { + if (e.target.selectedIndex === 1) { + // reply + util.popupMessage( + m(AddComment, { + parent_comment: comment.mComment, + channelId: comment.mMeta.mGroupId, + authorId: identity, + threadId: comment.mMeta.mThreadId, + parentId: comment.mMeta.mMsgId, + }) + ); + } else if (e.target.selectedIndex === 2) { + // voteUP + AddVote( + util.GXS_VOTE_UP, + comment.mMeta.mGroupId, + comment.mMeta.mThreadId, + identity, + comment.mMeta.mMsgId + ); + } else if (e.target.selectedIndex === 3) { + AddVote( + util.GXS_VOTE_DOWN, + comment.mMeta.mGroupId, + comment.mMeta.mThreadId, + identity, + comment.mMeta.mMsgId + ); + } + }, + }, + [ + m('option[hidden][selected]', 'Options'), + util.optionSelect.opts.map((option) => + m('option', { value: option }, option.toLocaleString()) + ), + ] + ), + m('td', rs.userList.userMap[comment.mMeta.mAuthorId]), + m( + 'td', + typeof comment.mMeta.mPublishTs === 'object' + ? new Date(comment.mMeta.mPublishTs.xint64 * 1000).toLocaleString() + : 'undefined' + ), + m('td', comment.mScore), + m('td', comment.mUpVotes), + m('td', comment.mDownVotes), + ]), + commentStruct.showReplies && + // Data.ParentCommentMap[comment.mMeta.mMsgId] && + // Data.ParentCommentMap[comment.mMeta.mMsgId].forEach( + // (value) => + parMap.map( + (value) => + // console.log(value) + // Data.Comments[Data.ParentCommentMap[comment.mMeta.mMsgId][key].mMeta.mThreadId] && + // Data.Comments[Data.ParentCommentMap[comment.mMeta.mMsgId][key].mMeta.mThreadId][ + // Data.ParentCommentMap[comment.mMeta.mMsgId][key].mMeta.mMsgId + // ] && + m(DisplayComment, { + commentStruct: + Data.Comments[value.mMeta.mThreadId][ + value.mMeta.mMsgId + ], + identity, + }) + ), + ]; + }, }; } @@ -525,14 +535,14 @@ const PostView = () => { Object.keys(topComments).map((key, index) => Data.Comments[topComments[key].mMeta.mThreadId] && Data.Comments[topComments[key].mMeta.mThreadId][topComments[key].mMeta.mMsgId] - ? m( - DisplayComment( + ? m(DisplayComment, { + // Do not call DisplayComment as a function, invoke like a component + identity: ownId, // supply the input as named attributes + commentStruct: Data.Comments[topComments[key].mMeta.mThreadId][ topComments[key].mMeta.mMsgId ], - ownId - ) - ) + }) : '' ) ) diff --git a/webui-src/app/forums/forums.css b/webui-src/app/forums/forums.css index 3b93d22..a684445 100644 --- a/webui-src/app/forums/forums.css +++ b/webui-src/app/forums/forums.css @@ -1,7 +1,7 @@ .forums-node-panel { position: relative; - bottom: 100px; - margin-left: 300px; + bottom: 200px; + margin-left: 200px; animation: fadein 0.5s; } @@ -31,12 +31,12 @@ table.forums tr.hidden{ #searchforum{ position:relative; margin-left: 250px; - top: 50px; + /* top: 50px; */ } #forumdetails{ position: relative; - margin-left: 10px; + margin-left: 150px; padding: 10px; } .p{ diff --git a/webui-src/app/forums/forums.js b/webui-src/app/forums/forums.js index 8d756d8..82b24a4 100644 --- a/webui-src/app/forums/forums.js +++ b/webui-src/app/forums/forums.js @@ -7,12 +7,17 @@ const getForums = { All: [], PopularForums: [], SubscribedForums: [], + MyForums: [], async load() { const res = await rs.rsJsonApiRequest('/rsgxsforums/getForumsSummaries'); getForums.All = res.body.forums; getForums.PopularForums = getForums.All; getForums.SubscribedForums = getForums.All.filter( - (forum) => forum.mSubscribeFlags === util.GROUP_SUBSCRIBE_SUBSCRIBED + (forum) => forum.mSubscribeFlags === util.GROUP_SUBSCRIBE_SUBSCRIBED || + forum.mSubscribeFlags === util.GROUP_MY_FORUM + ); + getForums.MyForums = getForums.All.filter( + (forum) => forum.mSubscribeFlags === util.GROUP_MY_FORUM ); }, }; @@ -24,7 +29,11 @@ const sections = { }; const Layout = { - onupdate: getForums.load, + oninit : () => { + rs.setBackgroundTask(getForums.load, 5000, () => { + // return m.route.get() === '/files/files'; + }); + }, view: (vnode) => m('.tab-page', [ m(util.SearchBar, { @@ -35,7 +44,7 @@ const Layout = { baseRoute: '/forums/', }), m( - '.forum-node-panel', + '.forums-node-panel', Object.prototype.hasOwnProperty.call(vnode.attrs.pathInfo, 'mGroupId') ? m(util.MessageView, { diff --git a/webui-src/app/forums/forums_util.js b/webui-src/app/forums/forums_util.js index e9e8fbb..c38ffbe 100644 --- a/webui-src/app/forums/forums_util.js +++ b/webui-src/app/forums/forums_util.js @@ -5,6 +5,9 @@ const GROUP_SUBSCRIBE_ADMIN = 0x01; // means: you have the admin key for this gr const GROUP_SUBSCRIBE_PUBLISH = 0x02; // means: you have the publish key for thiss group. Typical use: publish key in forums are shared with specific friends. const GROUP_SUBSCRIBE_SUBSCRIBED = 0x04; // means: you are subscribed to a group, which makes you a source for this group to your friend nodes. const GROUP_SUBSCRIBE_NOT_SUBSCRIBED = 0x08; +const GROUP_MY_FORUM = + GROUP_SUBSCRIBE_ADMIN + GROUP_SUBSCRIBE_SUBSCRIBED + GROUP_SUBSCRIBE_PUBLISH; + const Data = { DisplayForums: {}, @@ -153,4 +156,5 @@ module.exports = { GROUP_SUBSCRIBE_NOT_SUBSCRIBED, GROUP_SUBSCRIBE_PUBLISH, GROUP_SUBSCRIBE_SUBSCRIBED, + GROUP_MY_FORUM };