From 9d5b1ce9c7a6128a1800eecd2092337636875b0e Mon Sep 17 00:00:00 2001 From: timqian Date: Wed, 24 Jul 2019 18:38:29 +0800 Subject: [PATCH] init topic extraction UI --- backend/index.js | 31 ++++++++++- index.html | 2 +- pages/chat.js | 140 +++++++++++++++++++++++++++++++++++++++++++---- pages/members.js | 2 - pages/topics.js | 8 +-- 5 files changed, 163 insertions(+), 20 deletions(-) diff --git a/backend/index.js b/backend/index.js index 7484872..3579183 100644 --- a/backend/index.js +++ b/backend/index.js @@ -162,8 +162,9 @@ nextApp.prepare().then(() => { let msgs = await Msg.getRange({ groupName, idOffset: topic.msgRange[0], - idLimit: topic.msgRange[1] - topic.msgRange[0], + idLimit: 50, }); + // potential bug: more than 100 member of a group const members = await GroupMember.getAllMemberNames({ groupName, @@ -239,6 +240,34 @@ nextApp.prepare().then(() => { res.json('ok'); }); + app.post('/api/topics/add', async (req, res) => { + const { + groupName, + from, + title, + date, + msgRange, + description, + type, + password, + } = req.body; + + if (password !== secret.topicPassword) { + res.status(400).json('Wrong password'); + } + + await Topics.add({ + groupName, + from, + title, + date, + msgRange, + description: description || undefined, + type, + }); + res.json('ok'); + }); + app.get('/api/slackThread/:threadTs', async (req, res) => { const { threadTs } = req.params; const msgs = await Msg.getByThreadTs({ ts: threadTs }); diff --git a/index.html b/index.html index a609353..4e019cf 100644 --- a/index.html +++ b/index.html @@ -21,7 +21,7 @@ gtag('config', 'UA-56506279-9'); - diff --git a/pages/chat.js b/pages/chat.js index 5745856..9b85f6c 100644 --- a/pages/chat.js +++ b/pages/chat.js @@ -1,4 +1,6 @@ +import { useState } from 'react'; import ReactPaginate from 'react-paginate'; +import axios from 'axios'; import Head from './components/Head'; import Nav from './components/Nav'; import Footer from './components/Footer'; @@ -14,22 +16,67 @@ const Index = (props) => { group, msgs, totalPageCount, currentPage, } = props; + + const [isModalVisible, setIsModalVisible] = useState(false); + const [topicTitle, setTopicTitle] = useState(''); + const [topicDesc, setTopicDesc] = useState(''); + const [password, setPassword] = useState(''); + const [topicMsg, setTopicMsg] = useState({}); + + const addTopic = async () => { + await axios.post('/api/topics/add', { + groupName: group.name, + from: topicMsg.from, + title: topicTitle, + date: topicMsg.date, + msgRange: [topicMsg.id], + description: topicDesc || undefined, + type: 'wechat', + password, + }); + + window.location.href = `/chat/${group.name}/topics`; + }; + + const Msgs = () => { if (group.type === 'wechat') { return (
{ msgs.map(msg => ( - +
+
+ + ... + + +
+ +
)) }
@@ -130,6 +177,79 @@ const Index = (props) => {