From e85077bcc6885a0db96a173b899340548183eb90 Mon Sep 17 00:00:00 2001 From: Rogerio Chaves Date: Tue, 21 Apr 2020 08:41:10 +0200 Subject: [PATCH] Improve communities design --- app/lib/express.js | 4 +- app/lib/queries.js | 17 +++++--- app/public/style.css | 11 +++++ .../{communities.ejs => communities/list.ejs} | 4 +- app/views/communities/show.ejs | 42 +++++++++++++++++++ app/views/community.ejs | 30 ------------- 6 files changed, 68 insertions(+), 40 deletions(-) rename app/views/{communities.ejs => communities/list.ejs} (80%) create mode 100644 app/views/communities/show.ejs delete mode 100644 app/views/community.ejs diff --git a/app/lib/express.js b/app/lib/express.js index 4a21da3..6508899 100644 --- a/app/lib/express.js +++ b/app/lib/express.js @@ -484,7 +484,7 @@ router.get("/communities", async (req, res) => { } const communities = await queries.getCommunities(ssbServer); - res.render("communities", { communities }); + res.render("communities/list", { communities }); }); router.get("/communities/:name", async (req, res) => { @@ -497,7 +497,7 @@ router.get("/communities/:name", async (req, res) => { queries.getCommunityPosts(ssbServer, name), ]); - res.render("community", { community: { name, members, posts } }); + res.render("communities/show", { community: { name, members, posts } }); }); router.get("/search", async (req, res) => { diff --git a/app/lib/queries.js b/app/lib/queries.js index 4837661..d564c26 100644 --- a/app/lib/queries.js +++ b/app/lib/queries.js @@ -4,7 +4,7 @@ const debugPosts = require("debug")("queries:posts"), debugMessages = require("debug")("queries:messages"), debugFriends = require("debug")("queries:friends"), debugFriendshipStatus = require("debug")("queries:friendship_status"), - debugPeople = require("debug")("queries:people"), + debugSearch = require("debug")("queries:search"), debugProfile = require("debug")("queries:profile"), debugCommunities = require("debug")("queries:communities"), debugCommunityMembers = require("debug")("queries:communityMembers"), @@ -189,7 +189,7 @@ const getSecretMessages = async (ssbServer, profile) => { }; const search = async (ssbServer, search) => { - debugPeople("Fetching"); + debugSearch("Fetching"); // https://stackoverflow.com/questions/3446170/escape-string-for-use-in-javascript-regex const normalizedSearch = search @@ -202,7 +202,7 @@ const search = async (ssbServer, search) => { const loosenSpacesSearch = safelyEscapedSearch.replace(" ", ".*"); const searchRegex = new RegExp(`.*${loosenSpacesSearch}.*`, "i"); - const people = await promisePull( + const peoplePromise = promisePull( ssbServer.query.read({ reverse: true, query: [ @@ -229,7 +229,7 @@ const search = async (ssbServer, search) => { paramap(mapProfiles(ssbServer)) ); - const communitiesPosts = await promisePull( + const communitiesPostsPromise = promisePull( ssbServer.query.read({ reverse: true, query: [ @@ -249,6 +249,11 @@ const search = async (ssbServer, search) => { }) ); + const [people, communitiesPosts] = await Promise.all([ + peoplePromise, + communitiesPostsPromise, + ]); + const communities = Array.from( new Set(communitiesPosts.map((p) => p.value.content.channel)) ).filter((name) => { @@ -258,7 +263,7 @@ const search = async (ssbServer, search) => { return searchRegex.exec(normalizedName); }); - debugPeople("Done"); + debugSearch("Done"); return { people: Object.values(mapValues(people)), communities }; }; @@ -518,7 +523,7 @@ const getCommunityPosts = async (ssbServer, name) => { debugCommunityPosts("Done"); - return mapValues(Object.values(communityPostsByKey)); + return Object.values(communityPostsByKey); }; setInterval(() => { diff --git a/app/public/style.css b/app/public/style.css index 81c69d1..e83b564 100644 --- a/app/public/style.css +++ b/app/public/style.css @@ -352,3 +352,14 @@ h2 { border-radius: 3px; padding: 10px; } + +.community-topic-link { + justify-content: space-between; + padding: 8px 0; + border-top: 1px solid #ccc; + text-decoration: none; +} + +.community-topic-link:hover .community-topic-name { + text-decoration: underline; +} diff --git a/app/views/communities.ejs b/app/views/communities/list.ejs similarity index 80% rename from app/views/communities.ejs rename to app/views/communities/list.ejs index b6da9a1..7eb97f1 100644 --- a/app/views/communities.ejs +++ b/app/views/communities/list.ejs @@ -1,4 +1,4 @@ -<%- include('_header') %> +<%- include('../_header') %>

Communities

@@ -10,4 +10,4 @@ <% }) %> -<%- include('_footer') %> \ No newline at end of file +<%- include('../_footer') %> \ No newline at end of file diff --git a/app/views/communities/show.ejs b/app/views/communities/show.ejs new file mode 100644 index 0000000..87e83d1 --- /dev/null +++ b/app/views/communities/show.ejs @@ -0,0 +1,42 @@ +<%- include('../_header', { main_class: "screen-center" }) %> + + +
+
+

#<%= community.name %>

+
+
+ +
+ +
+ +<%- include('../_footer') %> \ No newline at end of file diff --git a/app/views/community.ejs b/app/views/community.ejs deleted file mode 100644 index fe80287..0000000 --- a/app/views/community.ejs +++ /dev/null @@ -1,30 +0,0 @@ -<%- include('_header') %> - - -
-
-

#<%= community.name %>

-
-
- -
-
-
-

Members

- <%- include('_friends', { friends: community.members }) %> -
-
-

Topics

- <% community.posts.map(post => { %> -

<%= post.content.text.substr(0, 70) %>. Replies <%= post.replies.length %>

- <% }) %> -
-
-
- -<%- include('_footer') %> \ No newline at end of file