title: $:/plugins/Gk0Wk/CPL-Repo/views/comments-center
caption: 💬 <$text text={{{ [[$:/language]get[text]removeprefix[$:/languages/]else[en-GB]search[zh]then[评论中心]else[Comment Center]] }}} />
created: 20260603000000000
modified: 20260603000000000
subtitle: <$text text={{{ [[$:/language]get[text]removeprefix[$:/languages/]else[en-GB]search[zh]then[浏览所有插件评论]else[Browse all comments]] }}} />
type: text/vnd.tiddlywiki

\whitespace trim

\import [[$:/plugins/Gk0Wk/CPL-Repo/procedures/fetch-plugin-activity]] [[$:/plugins/Gk0Wk/CPL-Repo/procedures/fetch-comments]]

<$let
  chinese={{{ [[$:/language]get[text]removeprefix[$:/languages/]else[en-GB]search[zh]then[yes]else[no]] }}}
  isAdmin={{{ [[$:/temp/CPL-Server/is-admin]get[text]else[no]] }}}
  userStatus={{{ [[$:/temp/CPL-Server/user-status]get[text]else[anonymous]] }}}
  githubClientId={{{ [[$:/temp/CPL-Server/github-client-id]get[text]] }}}
  searchState="$:/temp/CPL-Comments/search-query"
>

<div class="cpl-comments-center">

<!-- Login prompt for anonymous users -->
<$list filter="[<userStatus>!match[authenticated]]" variable="notLoggedIn">
<div class="cpl-comment-login-prompt" style="margin-bottom:20px;">
      <span class="cpl-status-muted"><$text text={{{ [<chinese>match[yes]then[登录后即可发表评论]else[Login to post comments]] }}}/></span>
  <$list filter="[<githubClientId>!is[blank]]" variable="hasGithubOAuth">
    <$button class="tc-btn-primary cpl-comment-login-button" style="margin-top:8px;">
      <$action-sendmessage $message="cpl-github-login"/>
      <$text text={{{ [<chinese>match[yes]then[使用 GitHub 登录]else[Login with GitHub]] }}}/>
    </$button>
  </$list>
  <$list filter="[<githubClientId>is[blank]]" variable="missingGithubOAuth">
    <span class="cpl-status-muted"><$text text={{{ [<chinese>match[yes]then[GitHub 登录暂未配置。]else[GitHub login is not configured.]] }}}/></span>
  </$list>
</div>
</$list>

<!-- Recent Comments (everyone) -->
<div class="cpl-comments-center-section">
<div class="cpl-comments-toolbar">
    <h3 class="cpl-card-heading-bordered" style="flex:1;margin:0;">
      🕐 <$text text={{{ [<chinese>match[yes]then[最新评论]else[Recent Comments]] }}}/>
    </h3>
    <$button class="tc-btn-invisible cpl-inline-button-link">
<<cpl-fetch-comments>>
      🔄 <$text text={{{ [<chinese>match[yes]then[刷新]else[Refresh]] }}}/>
    </$button>
  </div>

  <!-- Search bar -->
  <div class="cpl-comments-search-bar">
    <$edit-text tiddler=<<searchState>> field="text" default="" placeholder={{{ [<chinese>match[yes]then[搜索评论内容、用户名或插件名...]else[Search comments, users, or plugins...]] }}} class="cpl-form-input" tag="input" />
    <$list filter="[<searchState>get[text]!is[blank]]" variable="hasSearch">
      <$button class="tc-btn-invisible cpl-inline-button-link">
        <$action-setfield $tiddler=<<searchState>> text="" />
        ✕ <$text text={{{ [<chinese>match[yes]then[清除]else[Clear]] }}}/>
      </$button>
    </$list>
  </div>

  <$list filter="[{$:/temp/CPL-Server/all-recent-comments}jsonindexes[comments]]" variable="idx">
    <$let searchText={{{ [<searchState>get[text]] }}} commentJson={{{ [{$:/temp/CPL-Server/all-recent-comments}jsonextract[comments],<idx>] }}}>
        <$list filter="[<searchText>is[blank]] [<commentJson>search:words<searchText>] +[limit[1]]" variable="match">
          <$let
            commentUsername={{{ [{$:/temp/CPL-Server/all-recent-comments}jsonget[comments],<idx>,[username]else[Anonymous]] }}}
            commentContent={{{ [{$:/temp/CPL-Server/all-recent-comments}jsonget[comments],<idx>,[content]] }}}
            commentDate={{{ [{$:/temp/CPL-Server/all-recent-comments}jsonget[comments],<idx>,[createdAt]] }}}
            commentAvatar={{{ [{$:/temp/CPL-Server/all-recent-comments}jsonget[comments],<idx>,[avatar]] }}}
            commentPlugin={{{ [{$:/temp/CPL-Server/all-recent-comments}jsonget[comments],<idx>,[pluginTitle]] }}}
            commentStatus={{{ [{$:/temp/CPL-Server/all-recent-comments}jsonget[comments],<idx>,[status]else[approved]] }}}
            commentId={{{ [{$:/temp/CPL-Server/all-recent-comments}jsonget[comments],<idx>,[id]] }}}
          >
            <div class="cpl-comment-item">
              <div class="cpl-comment-meta">
                <$list filter="[<commentAvatar>!is[blank]]" variable="hasAvatar">
                  <img src=<<commentAvatar>> class="cpl-comment-avatar-small" alt=""/>
                </$list>
                <strong><$text text=<<commentUsername>>/></strong>
                <span class="cpl-comment-date"><$text text=<<commentDate>>/></span>
                <$list filter="[<commentPlugin>!is[blank]]" variable="hasPlugin">
                  <$button class="tc-btn-invisible cpl-comment-plugin-pill">
                    <$action-navigate $to=<<commentPlugin>>/>
                    📦 <$text text=<<commentPlugin>>/>
                  </$button>
                </$list>
              </div>
              <div class="cpl-comment-body">
                <$text text=<<commentContent>>/>
              </div>
            </div>
          </$let>
        </$list>
      </$let>
    </$list>

  <$list filter="[{$:/temp/CPL-Server/all-recent-comments}jsonindexes[comments]count[]match[0]]" variable="emptyRecent">
    <div class="cpl-comment-empty">
      <$text text={{{ [<chinese>match[yes]then[暂无评论。]else[No comments yet.]] }}}/>
    </div>
  </$list>

  <$list filter="[[$:/temp/CPL-Server/all-recent-comments]get[text]is[blank]]" variable="loading2">
    <div class="cpl-comment-empty">
      <$text text={{{ [<chinese>match[yes]then[点击「刷新」加载评论...]else[Click Refresh to load comments...]] }}}/>
    </div>
  </$list>

</div>

</div>
</$let>
