diff --git a/app/lib/express.js b/app/lib/express.js index 1847040..6d4e1d0 100644 --- a/app/lib/express.js +++ b/app/lib/express.js @@ -518,6 +518,48 @@ router.get( } ); +router.get( + "/communities/new", + { mobileVersion: "/mobile/communities/new" }, + async (_req, res) => { + res.render("desktop/communities/new"); + } +); + +router.post("/communities/new", async (req, res) => { + const name = req.body.name; + if (!name.match(/^[a-z0-9-]+$/)) { + res.send("Invalid community name"); + return; + } + + const title = req.body.title; + const post = req.body.post; + + await ssb.client().identities.publishAs({ + id: req.context.profile.id, + private: false, + content: { + type: "post", + title: title, + text: post, + channel: name, + }, + }); + + await ssb.client().identities.publishAs({ + id: req.context.profile.id, + private: false, + content: { + type: "channel", + channel: name, + subscribed: true, + }, + }); + + res.redirect(`/communities/${name}`); +}); + const communityData = (req) => { const name = req.params.name; return Promise.all([ diff --git a/app/lib/mobile-routes.js b/app/lib/mobile-routes.js index 4e5388a..119234d 100644 --- a/app/lib/mobile-routes.js +++ b/app/lib/mobile-routes.js @@ -100,6 +100,14 @@ module.exports.setupRoutes = (router) => { } ); + router.get( + "/mobile/communities/new", + { desktopVersion: "/communities/new" }, + async (_req, res) => { + res.render("mobile/communities/new", { layout: "mobile/_layout" }); + } + ); + router.get( "/mobile/communities/:name", { desktopVersion: "/communities/:name" }, diff --git a/app/views/desktop/communities/list.ejs b/app/views/desktop/communities/list.ejs index 4606f8d..c9321a0 100644 --- a/app/views/desktop/communities/list.ejs +++ b/app/views/desktop/communities/list.ejs @@ -1,6 +1,9 @@ <%- include('../_header') %> -

My communities

+
+

My communities

+ New Community +
<% if (participating.length == 0) { %>

You haven't joined any communities yet, explore some below to join

diff --git a/app/views/desktop/communities/new.ejs b/app/views/desktop/communities/new.ejs new file mode 100644 index 0000000..05959f8 --- /dev/null +++ b/app/views/desktop/communities/new.ejs @@ -0,0 +1,28 @@ +<%- include('../_header') %> + +

Create a new community

+ +
+ + +

First topic

+ + +
+ +
+
+ +<%- include('../_footer') %> \ No newline at end of file diff --git a/app/views/mobile/communities/list.ejs b/app/views/mobile/communities/list.ejs index c49e4ce..52c6609 100644 --- a/app/views/mobile/communities/list.ejs +++ b/app/views/mobile/communities/list.ejs @@ -17,4 +17,8 @@ #<%= community %> <% }) %> + + +
+
+
\ No newline at end of file diff --git a/app/views/mobile/communities/new.ejs b/app/views/mobile/communities/new.ejs new file mode 100644 index 0000000..731e326 --- /dev/null +++ b/app/views/mobile/communities/new.ejs @@ -0,0 +1,26 @@ +
+

New community

+ +
+ + +

First topic

+ + +
+ +
+
+
\ No newline at end of file diff --git a/app/views/mobile/search.ejs b/app/views/mobile/search.ejs index b8ca097..3078f58 100644 --- a/app/views/mobile/search.ejs +++ b/app/views/mobile/search.ejs @@ -1,11 +1,11 @@
🔎
- +
- <% if (query.length < 3) { %> + <% if (query.length > 0 && query.length < 3) { %>

You need to search for 3 or more characters

- <% } else { %> + <% } else if (query.length > 3) { %>

People

<% if (people.length == 0) { %>