aboutsummaryrefslogtreecommitdiff
path: root/vnext
diff options
context:
space:
mode:
authorGravatar Vitaly Takmazov2018-06-16 22:13:40 +0300
committerGravatar Vitaly Takmazov2023-01-13 10:37:52 +0300
commit67afd8e9378c65bff11a2aac21d95577fa916dc5 (patch)
tree299ae99f74df6285687d978c74875fc583af98e3 /vnext
parent9177719daf40ca63b73f78602283902b3c615bae (diff)
Discussions
Diffstat (limited to 'vnext')
-rw-r--r--vnext/src/components/Feeds.js (renamed from vnext/src/components/Discover.js)32
-rw-r--r--vnext/src/index.js9
2 files changed, 27 insertions, 14 deletions
diff --git a/vnext/src/components/Discover.js b/vnext/src/components/Feeds.js
index a0e51160a..3c183f7fb 100644
--- a/vnext/src/components/Discover.js
+++ b/vnext/src/components/Feeds.js
@@ -6,7 +6,15 @@ import * as qs from 'query-string';
import Message from './Message';
import Spinner from './Spinner';
-export default class Discover extends React.Component {
+export function Discover(props) {
+ return (<Feed baseUrl="https://api.juick.com/messages" {...props} />)
+}
+
+export function Discussions(props) {
+ return (<Feed authRequired="true" baseUrl="https://api.juick.com/messages/discussions" {...props} />)
+}
+
+class Feed extends React.Component {
constructor(props) {
super(props);
this.state = {
@@ -15,24 +23,27 @@ export default class Discover extends React.Component {
this.loadMessages = this.loadMessages.bind(this);
}
componentDidMount() {
- this.loadMessages();
+ this.loadMessages(this.props.visitor.hash);
}
componentWillReceiveProps(nextProps) {
- if (this.props.location.search != nextProps.location.search
+ if (this.props.location.search != nextProps.location.search
|| this.props.visitor != nextProps.visitor) {
- this.loadMessages(nextProps.location.search)
+ this.loadMessages(nextProps.visitor.hash, nextProps.location.search)
}
}
- loadMessages(filter = '') {
+ loadMessages(hash = '', filter = '') {
this.setState({ msgs: [] })
let params = qs.parse(filter) || {}
- let url = 'https://api.juick.com/messages';
- if (this.props.visitor && this.props.visitor.hash) {
- params.hash = this.props.visitor.hash;
+ let url = this.props.baseUrl;
+ if (hash) {
+ params.hash = hash;
}
if (Object.keys(params).length > 0) {
url = `${url}?${qs.stringify(params)}`;
}
+ if (!params.hash && this.props.authRequired) {
+ return
+ }
fetch(url)
.then(response => {
return response.json()
@@ -54,6 +65,7 @@ export default class Discover extends React.Component {
}
}
-Discover.propTypes = {
- msgs: PropTypes.array
+Feed.propTypes = {
+ msgs: PropTypes.array,
+ baseUrl: PropTypes.string
};
diff --git a/vnext/src/index.js b/vnext/src/index.js
index 3a4fe494c..9317c8b6a 100644
--- a/vnext/src/index.js
+++ b/vnext/src/index.js
@@ -2,7 +2,7 @@ import React from 'react';
import ReactDOM from 'react-dom';
import { BrowserRouter as Router, Route, Link } from 'react-router-dom';
import Icon from './components/Icon';
-import Discover from './components/Discover';
+import { Discover, Discussions } from './components/Feeds';
import Post from './components/Post';
import Thread from './components/Thread';
import LoginButton from './components/LoginButton';
@@ -42,7 +42,7 @@ class App extends React.Component {
<nav id="global">
<ul>
{this.state.visitor.uid > 0 ?
- <li><Link to={{ pathname: '/' }}><Icon name="ei-comment" size="s" />Discuss</Link></li>
+ <li><Link to={{ pathname: '/discussions' }}><Icon name="ei-comment" size="s" />Discuss</Link></li>
:
<li><Link to='/?media=1' rel="nofollow"><Icon name="ei-camera" size="s" />Photos</Link></li>
}
@@ -59,8 +59,9 @@ class App extends React.Component {
</div>
</header>
<Route exact path="/" render={(props) => <Discover visitor={this.state.visitor} {...props} />} />
- <Route path="/:user/:mid" render={(props) => <Thread visitor={this.state.visitor} {...props} />} />
- <Route path="/post" render={(props) => <Post visitor={this.state.visitor} {...props} />} />
+ <Route exact path="/discussions" render={(props) => <Discussions visitor={this.state.visitor} {...props} />} />
+ <Route exact path="/:user/:mid" render={(props) => <Thread visitor={this.state.visitor} {...props} />} />
+ <Route exact path="/post" render={(props) => <Post visitor={this.state.visitor} {...props} />} />
</div>
</Router>
<Footer />