diff --git a/pkg/interface/publish/src/css/custom.css b/pkg/interface/publish/src/css/custom.css
index 17664b86c..08d2c849a 100644
--- a/pkg/interface/publish/src/css/custom.css
+++ b/pkg/interface/publish/src/css/custom.css
@@ -69,8 +69,8 @@ a {
.db-ns {
display: block;
}
- .flex-basis-300-ns {
- flex-basis: 300px;
+ .flex-basis-250-ns {
+ flex-basis: 250px;
}
.h-100-m-40-ns {
height: calc(100% - 40px);
diff --git a/pkg/interface/publish/src/js/components/lib/group-item.js b/pkg/interface/publish/src/js/components/lib/group-item.js
new file mode 100644
index 000000000..89e29e8cc
--- /dev/null
+++ b/pkg/interface/publish/src/js/components/lib/group-item.js
@@ -0,0 +1,44 @@
+import React, { Component } from 'react';
+import { NotebookItem } from './notebook-item';
+
+export class GroupItem extends Component {
+ render() {
+ const { props, state } = this;
+ let association = !!props.association ? props.association : {};
+
+ let title = association["app-path"] ? association["app-path"] : "Unmanaged Notebooks";
+ if (association.metadata && association.metadata.title) {
+ title = association.metadata.title !== ""
+ ? association.metadata.title : title;
+ }
+
+ let groupedBooks = !!props.groupedBooks ? props.groupedBooks : [];
+ let first = (props.index === 0) ? "pt1" : "pt4";
+
+ let notebookItems = groupedBooks.map((each, i) => {
+ let unreads = props.notebooks[each]["num-unread"] || 0;
+ let title = each.substr(1);
+ if (props.notebooks[each].title) {
+ title = (props.notebooks[each].title !== "")
+ ? props.notebooks[each].title : title;
+ }
+ return (
+
+ )
+ })
+ return (
+
-
{props.title}
-
by
-
- {name}
-
-
-
- {postCount}
-
- {unread}
-
-
+
+
{props.title}
+ {unread}
);
diff --git a/pkg/interface/publish/src/js/components/lib/sidebar.js b/pkg/interface/publish/src/js/components/lib/sidebar.js
index 6efe1b702..b9c5dac02 100644
--- a/pkg/interface/publish/src/js/components/lib/sidebar.js
+++ b/pkg/interface/publish/src/js/components/lib/sidebar.js
@@ -1,95 +1,11 @@
import React, { Component } from 'react'
import { Route, Link } from 'react-router-dom';
-import { Dropdown } from './dropdown';
-import { NotebookItem } from './notebook-item';
import { SidebarInvite } from './sidebar-invite';
import { Welcome } from './welcome';
+import { GroupItem } from './group-item';
+import { alphabetiseAssociations } from '../../lib/util';
export class Sidebar extends Component {
- constructor(props) {
- super(props);
- this.state = {
- sort: "oldest",
- sortedBooks: new Map()
- }
- this.sort = this.sort.bind(this);
- this.sortChange = this.sortChange.bind(this);
- }
-
- componentDidMount() {
- this.sort();
- }
-
- componentDidUpdate(prevProps, prevState) {
- if ((prevState.sort !== this.state.sort) || (prevProps !== this.props)) {
- this.sort();
- }
- }
-
- sort() {
- let { props, state } = this;
- let notebooks = new Map();
- Object.keys(props.notebooks).map(host => {
- Object.keys(props.notebooks[host]).map(notebook => {
- let title = `${host}/${notebook}`;
- notebooks.set(title, props.notebooks[host][notebook])
- })
- });
- switch (state.sort) {
- case "oldest":
- notebooks = new Map(
- [...notebooks.entries()].sort(
- (a, b) => {
- if ((a[1]) && (b[1])) {
- return a[1]["date-created"] - b[1]["date-created"]
- }
- }
- )
- );
- break;
- case "newest":
- notebooks = new Map(
- [...notebooks.entries()].sort(
- (a, b) => {
- if ((a[1]) && (b[1])) {
- return b[1]["date-created"] - a[1]["date-created"]
- }
- }
- )
- );
- break;
- case "alphabetical":
- notebooks = new Map(
- [...notebooks.entries()].sort((a, b) => {
- if ((a[1]) && (b[1])) {
- return a[1]["title"].toLowerCase().localeCompare(
- b[1]["title"].toLowerCase()
- );
- }
- })
- );
- break;
- case "reverseAlphabetical":
- notebooks = new Map(
- [...notebooks.entries()].sort((a, b) => {
- if ((a[1]) && (b[1])) {
- return b[1]["title"].toLowerCase().localeCompare(
- a[1]["title"].toLowerCase()
- );
- }
- })
- );
- break;
- default:
- break;
- }
- this.setState({ sortedBooks: notebooks });
- }
-
- sortChange(event) {
- this.setState({sort: event.target.value});
- }
-
render() {
const { props, state } = this;
let activeClasses = (props.active === "sidebar") ? " " : "dn-s ";
@@ -111,24 +27,70 @@ export class Sidebar extends Component {
key={i} />
)
});
+ let associations = !!props.associations ? alphabetiseAssociations(props.associations.contacts) : {};
- let notebookItems = [...state.sortedBooks].map(([path, book]) => {
- let selected = (props.path === path);
- let author = path.split("/")[0];
- return (
-
- );
- })
+ let notebooks = {};
+ Object.keys(props.notebooks).map(host => {
+ Object.keys(props.notebooks[host]).map(notebook => {
+ let title = `${host}/${notebook}`;
+ notebooks[title] = props.notebooks[host][notebook];
+ })
+ });
+
+ let groupedNotebooks = {};
+ Object.keys(notebooks).map(book => {
+ if (notebooks[book]["subscribers-group-path"].startsWith("/~/")) {
+ if (groupedNotebooks["/~/"]) {
+ let array = groupedNotebooks["/~/"];
+ array.push(book);
+ groupedNotebooks["/~/"] = array;
+ } else {
+ groupedNotebooks["/~/"] = [book];
+ };
+ };
+ let path = !!notebooks[book]["subscribers-group-path"]
+ ? notebooks[book]["subscribers-group-path"] : book;
+ if (path in associations) {
+ if (groupedNotebooks[path]) {
+ let array = groupedNotebooks[path];
+ array.push[book];
+ groupedNotebooks[path] = array;
+ } else {
+ groupedNotebooks[path] = [book];
+ }
+ }
+ });
+
+ let groupedItems = Object.keys(associations)
+ .map((each, i) => {
+ let books = groupedNotebooks[each];
+ if (books.length === 0) return;
+ if (groupedNotebooks["/~/"] && groupedNotebooks["/~/"].length !== 0) {
+ i = i + 1;
+ }
+ return(
+
+ )
+ })
+ if (groupedNotebooks["/~/"] && groupedNotebooks["/~/"].length !== 0) {
+ groupedItems.unshift(
+
+ )
+ }
return (
⟵ Landscape
-
+
New Notebook
Join Notebook
-
- {this.setState({sort: "oldest"})}
- },
- {
- cls: "white-d w-100 tl pointer db ph2 pv3 hover-bg-gray4 hover-bg-gray1-d bg-transparent",
- txt: "Newest",
- action: () => {this.setState({sort: "newest"})}
- },
- {
- cls: "white-d w-100 tl pointer db ph2 pv3 hover-bg-gray4 hover-bg-gray1-d bg-transparent",
- txt: "A -> Z",
- action: () => {this.setState({sort: "alphabetical"})}
- },
- {
- cls: "white-d w-100 tl pointer db ph2 pv3 hover-bg-gray4 hover-bg-gray1-d bg-transparent",
- txt: "Z -> A",
- action: () => {this.setState({sort: "reverseAlphabetical"})}
- }
- ]}
- buttonText="Sort By"
- />
-
{sidebarInvites}
- {notebookItems}
+ {groupedItems}
);
diff --git a/pkg/interface/publish/src/js/components/root.js b/pkg/interface/publish/src/js/components/root.js
index 3ef14fcdd..566aa9c55 100644
--- a/pkg/interface/publish/src/js/components/root.js
+++ b/pkg/interface/publish/src/js/components/root.js
@@ -38,6 +38,7 @@ export class Root extends Component {
spinner={state.spinner}
invites={state.invites}
notebooks={state.notebooks}
+ associations={associations}
contacts={contacts}>
@@ -62,6 +63,7 @@ export class Root extends Component {
spinner={state.spinner}
invites={state.invites}
notebooks={state.notebooks}
+ associations={associations}
contacts={contacts}>
{
+ let aName = a.substr(1);
+ let bName = b.substr(1);
+ if (a.metadata && a.metadata.title) {
+ aName = a.metadata.title !== ""
+ ? a.metadata.title
+ : a.substr(1);
+ }
+ if (b.metadata && b.metadata.title) {
+ bName = b.metadata.title !== ""
+ ? b.metadata.title
+ : b.substr(1);
+ }
+ return aName.toLowerCase().localeCompare(bName.toLowerCase());
+ }).map((each) => {
+ result[each] = associations[each];
+ })
+ return result;
}
\ No newline at end of file