From b6dc6e1a6219e73fcabe54d68b5bb08209ffa021 Mon Sep 17 00:00:00 2001 From: bobzel Date: Mon, 22 Mar 2021 22:27:26 -0400 Subject: added user filter to pdf/web sidebar. --- src/client/views/SidebarAnnos.scss | 6 +++++- src/client/views/SidebarAnnos.tsx | 15 ++++++++++++++- 2 files changed, 19 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/client/views/SidebarAnnos.scss b/src/client/views/SidebarAnnos.scss index 9eea83d59..9686cce85 100644 --- a/src/client/views/SidebarAnnos.scss +++ b/src/client/views/SidebarAnnos.scss @@ -4,7 +4,8 @@ overflow: auto; flex-flow: row; flex-wrap: wrap; - .sidebarAnnos-filterTag, .sidebarAnnos-filterTag-active { + .sidebarAnnos-filterTag, .sidebarAnnos-filterTag-active, + .sidebarAnnos-filterUser, .sidebarAnnos-filterUser-active { font-weight: bold; padding-left: 6; padding-right: 6; @@ -14,6 +15,9 @@ height: 20; background-color: lightgrey; } + .sidebarAnnos-filterUser, .sidebarAnnos-filterUser-active { + border-radius: 15px; + } .sidebarAnnos-filterTag-active { background-color: white; } diff --git a/src/client/views/SidebarAnnos.tsx b/src/client/views/SidebarAnnos.tsx index 9d085e2b6..a859dcab4 100644 --- a/src/client/views/SidebarAnnos.tsx +++ b/src/client/views/SidebarAnnos.tsx @@ -37,6 +37,11 @@ export class SidebarAnnos extends React.Component { DocListCast(this.props.rootDoc[this.sidebarKey()]).forEach(doc => SearchBox.documentKeys(doc).forEach(key => keys.add(key))); return Array.from(keys.keys()).filter(key => key[0]).filter(key => !key.startsWith("_") && (key[0] === "#" || key[0] === key[0].toUpperCase())).sort(); } + @computed get allUsers() { + const keys = new Set(); + DocListCast(this.props.rootDoc[this.sidebarKey()]).forEach(doc => keys.add(StrCast(doc.author))); + return Array.from(keys.keys()).sort(); + } get filtersKey() { return "_" + this.sidebarKey() + "-docFilters"; } anchorMenuClick = (anchor: Doc) => { @@ -73,7 +78,7 @@ export class SidebarAnnos extends React.Component { docFilters = () => [...StrListCast(this.props.layoutDoc._docFilters), ...StrListCast(this.props.layoutDoc[this.filtersKey])]; sidebarStyleProvider = (doc: Opt, props: Opt, property: string) => { - if (property === StyleProp.ShowTitle) return "title"; + if (property === StyleProp.ShowTitle) return StrCast(this.props.layoutDoc["sidebar-childShowTitle"], "title"); return this.props.styleProvider?.(doc, props, property) } render() { @@ -84,6 +89,13 @@ export class SidebarAnnos extends React.Component { {tag} ; }; + const renderUsers = (user: string) => { + const active = StrListCast(this.props.rootDoc[this.filtersKey]).includes(`author:${user}:check`); + return
Doc.setDocFilter(this.props.rootDoc, "author", user, "check", true, this.sidebarKey(), e.shiftKey)}> + {user} +
; + }; return !this.props.layoutDoc._showSidebar ? (null) :
{ />
+ {this.allUsers.map(renderUsers)} {this.allHashtags.map(renderTag)}
; -- cgit v1.2.3-70-g09d2