mirror of
https://github.com/twisterarmy/twister-react.git
synced 2025-01-27 15:14:30 +00:00
upgrade to react-router 2.0 yay
This commit is contained in:
parent
41e16137a9
commit
b8badf0aa6
@ -103,7 +103,9 @@ App = React.createClass({displayName: "App",
|
|||||||
Twister.getAccount(acc.name).verifyKey(function(key){
|
Twister.getAccount(acc.name).verifyKey(function(key){
|
||||||
thisComponent.setState(function(oldstate,props){
|
thisComponent.setState(function(oldstate,props){
|
||||||
|
|
||||||
oldstate.accounts[acc.name].status = key.getStatus();
|
oldstate.accounts.find(function(a){
|
||||||
|
return a.name==acc.name;
|
||||||
|
}).status = key.getStatus();
|
||||||
|
|
||||||
return oldstate;
|
return oldstate;
|
||||||
|
|
||||||
@ -152,9 +154,13 @@ App = React.createClass({displayName: "App",
|
|||||||
|
|
||||||
render: function() {
|
render: function() {
|
||||||
|
|
||||||
//var firstroute = this.context.router.getCurrentRoutes()[1].name;
|
var route = this.props.location.pathname.split("/").filter(function(s){
|
||||||
|
return s!="";
|
||||||
|
});
|
||||||
|
|
||||||
|
var isOnHome = (route.length==0);
|
||||||
|
|
||||||
//console.log(firstroute);
|
var isOnOwnProfile = ( route[0]="profile" && route[1]==this.state.activeAccount );
|
||||||
|
|
||||||
var guestMode = true;
|
var guestMode = true;
|
||||||
|
|
||||||
@ -199,13 +205,13 @@ App = React.createClass({displayName: "App",
|
|||||||
React.createElement(Col, {xs: 12, sm: 10, smOffset: 1, md: 8, mdOffset: 2, lg: 6, lgOffset: 3},
|
React.createElement(Col, {xs: 12, sm: 10, smOffset: 1, md: 8, mdOffset: 2, lg: 6, lgOffset: 3},
|
||||||
React.createElement(ButtonGroup, {justified: true},
|
React.createElement(ButtonGroup, {justified: true},
|
||||||
React.createElement(Button, {
|
React.createElement(Button, {
|
||||||
href: "#",
|
href: "#/",
|
||||||
//bsStyle={firstroute=="home" ? 'primary' : 'default'}
|
bsStyle: isOnHome ? 'primary' : 'default',
|
||||||
disabled: guestMode
|
disabled: guestMode
|
||||||
}, React.createElement(Glyphicon, {glyph: "home"})),
|
}, React.createElement(Glyphicon, {glyph: "home"})),
|
||||||
React.createElement(Button, {
|
React.createElement(Button, {
|
||||||
href: "#/profile",
|
href: '#/profile/'+this.state.activeAccount,
|
||||||
//bsStyle={firstroute=="profile-active" ? 'primary' : 'default'}
|
bsStyle: isOnOwnProfile ? 'primary' : 'default',
|
||||||
disabled: guestMode
|
disabled: guestMode
|
||||||
}, React.createElement(Glyphicon, {glyph: "user"})),
|
}, React.createElement(Glyphicon, {glyph: "user"})),
|
||||||
React.createElement(Button, {href: "#/directmessages", disabled: true}, React.createElement(Glyphicon, {glyph: "transfer"})),
|
React.createElement(Button, {href: "#/directmessages", disabled: true}, React.createElement(Glyphicon, {glyph: "transfer"})),
|
||||||
@ -242,12 +248,6 @@ initializeApp = function () {
|
|||||||
React.createElement(Router, {history: hashHistory},
|
React.createElement(Router, {history: hashHistory},
|
||||||
React.createElement(Route, {component: App, path: "/"},
|
React.createElement(Route, {component: App, path: "/"},
|
||||||
React.createElement(IndexRoute, {component: Home}),
|
React.createElement(IndexRoute, {component: Home}),
|
||||||
React.createElement(Route, {path: "/profile", component: Profile},
|
|
||||||
React.createElement(IndexRoute, {component: Timeline}),
|
|
||||||
React.createElement(Route, {path: "timeline", component: Timeline}),
|
|
||||||
React.createElement(Route, {path: "followings", component: Followings}),
|
|
||||||
React.createElement(Route, {path: "mentions", component: Mentions})
|
|
||||||
),
|
|
||||||
React.createElement(Route, {path: "/profile/:username", component: Profile},
|
React.createElement(Route, {path: "/profile/:username", component: Profile},
|
||||||
React.createElement(IndexRoute, {component: Timeline}),
|
React.createElement(IndexRoute, {component: Timeline}),
|
||||||
React.createElement(Route, {path: "timeline", component: Timeline}),
|
React.createElement(Route, {path: "timeline", component: Timeline}),
|
||||||
@ -1462,12 +1462,12 @@ module.exports = ProfileMixin = {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
getInitialState: function() {
|
getInitialState: function() {
|
||||||
|
|
||||||
var username = this.props.username;
|
var username = this.props.username;
|
||||||
|
|
||||||
if (!username) {
|
if (!username) {
|
||||||
|
|
||||||
username = (this.context.router.getCurrentParams().username ? this.context.router.getCurrentParams().username : this.props.activeAccount);
|
username = (this.props.params.username ? this.props.params.username : this.props.activeAccount);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2534,9 +2534,6 @@ module.exports = Settings = React.createClass({displayName: "Settings",
|
|||||||
SafeStateChangeMixin,
|
SafeStateChangeMixin,
|
||||||
AppSettingsMixin
|
AppSettingsMixin
|
||||||
],
|
],
|
||||||
contextTypes: {
|
|
||||||
router: React.PropTypes.func
|
|
||||||
},
|
|
||||||
handeSettingsUpdate: function (e) {
|
handeSettingsUpdate: function (e) {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
|
|
||||||
@ -2880,12 +2877,9 @@ var ReactBootstrap = require('react-bootstrap')
|
|||||||
module.exports = Followings = React.createClass({displayName: "Followings",
|
module.exports = Followings = React.createClass({displayName: "Followings",
|
||||||
|
|
||||||
mixins: [AppSettingsMixin,SetIntervalMixin,SafeStateChangeMixin],
|
mixins: [AppSettingsMixin,SetIntervalMixin,SafeStateChangeMixin],
|
||||||
contextTypes: {
|
|
||||||
router: React.PropTypes.func
|
|
||||||
},
|
|
||||||
getInitialState: function() {
|
getInitialState: function() {
|
||||||
return {
|
return {
|
||||||
username: (this.context.router.getCurrentParams().username ? this.context.router.getCurrentParams().username : this.props.activeAccount),
|
username: (this.props.params.username ? this.props.params.username : this.props.activeAccount),
|
||||||
followings: [],
|
followings: [],
|
||||||
loading: true
|
loading: true
|
||||||
};
|
};
|
||||||
@ -2952,12 +2946,9 @@ var AppSettingsMixin = require('../common/AppSettingsMixin.js');
|
|||||||
module.exports = Mentions = React.createClass({displayName: "Mentions",
|
module.exports = Mentions = React.createClass({displayName: "Mentions",
|
||||||
|
|
||||||
mixins: [StreamMixin,AppSettingsMixin,SetIntervalMixin,SafeStateChangeMixin],
|
mixins: [StreamMixin,AppSettingsMixin,SetIntervalMixin,SafeStateChangeMixin],
|
||||||
contextTypes: {
|
|
||||||
router: React.PropTypes.func
|
|
||||||
},
|
|
||||||
getInitialState: function() {
|
getInitialState: function() {
|
||||||
return {
|
return {
|
||||||
username: (this.context.router.getCurrentParams().username ? this.context.router.getCurrentParams().username : this.props.activeAccount),
|
username: (this.props.params.username ? this.props.params.username : this.props.activeAccount),
|
||||||
data: [],
|
data: [],
|
||||||
postIdentifiers: {},
|
postIdentifiers: {},
|
||||||
loading: true
|
loading: true
|
||||||
@ -3020,7 +3011,7 @@ var FollowButton = require('../common/FollowButton.js');
|
|||||||
var EditProfileModalButton = require('../profile/EditProfileModalButton.js');
|
var EditProfileModalButton = require('../profile/EditProfileModalButton.js');
|
||||||
var EditAvatarModalButton = require('../profile/EditAvatarModalButton.js');
|
var EditAvatarModalButton = require('../profile/EditAvatarModalButton.js');
|
||||||
|
|
||||||
module.exports = Post = React.createClass({displayName: "Post",
|
module.exports = Profile = React.createClass({displayName: "Profile",
|
||||||
mixins: [
|
mixins: [
|
||||||
SetIntervalMixin,
|
SetIntervalMixin,
|
||||||
SafeStateChangeMixin,
|
SafeStateChangeMixin,
|
||||||
@ -3028,11 +3019,15 @@ module.exports = Post = React.createClass({displayName: "Post",
|
|||||||
],
|
],
|
||||||
render: function() {
|
render: function() {
|
||||||
|
|
||||||
var routeprefix = "#/profile/"+(this.context.router.getCurrentParams().username ? this.context.router.getCurrentParams().username+"/" : "")
|
var routeprefix = "#/profile/"+(this.props.params.username ? this.props.params.username+"/" : "")
|
||||||
|
|
||||||
var subroute = this.context.router.getCurrentRoutes()[2].name
|
var route = this.props.location.pathname.split("/").filter(function(s){
|
||||||
|
return s!="";
|
||||||
//console.log(this.context.router.getCurrentRoutes());
|
});
|
||||||
|
|
||||||
|
var isOnTimeline = !route[2] || route[2]=="timeline";
|
||||||
|
var isOnMentions = route[2]=="mentions";
|
||||||
|
var isOnFollowings = route[2]=="followings";
|
||||||
|
|
||||||
return (
|
return (
|
||||||
React.createElement(ListGroup, {fill: true},
|
React.createElement(ListGroup, {fill: true},
|
||||||
@ -3067,13 +3062,13 @@ module.exports = Post = React.createClass({displayName: "Post",
|
|||||||
),
|
),
|
||||||
React.createElement(ListGroupItem, {className: "fullytight_all"},
|
React.createElement(ListGroupItem, {className: "fullytight_all"},
|
||||||
React.createElement(ButtonGroup, {justified: true},
|
React.createElement(ButtonGroup, {justified: true},
|
||||||
React.createElement(Button, {href: routeprefix+"timeline", bsStyle: subroute.indexOf("timeline")>-1 ? "primary" : "default"}, React.createElement(Glyphicon, {glyph: "list"})),
|
React.createElement(Button, {href: routeprefix+"timeline", bsStyle: isOnTimeline ? 'primary' : 'default'}, React.createElement(Glyphicon, {glyph: "list"})),
|
||||||
React.createElement(Button, {href: routeprefix+"followings", bsStyle: subroute.indexOf("followings")>-1 ? "primary" : "default"}, React.createElement(Glyphicon, {glyph: "eye-open"})),
|
React.createElement(Button, {href: routeprefix+"followings", bsStyle: isOnFollowings ? 'primary' : 'default'}, React.createElement(Glyphicon, {glyph: "eye-open"})),
|
||||||
React.createElement(Button, {href: routeprefix+"mentions", bsStyle: subroute.indexOf("mentions")>-1 ? "primary" : "default"}, React.createElement(Glyphicon, {glyph: "comment"}))
|
React.createElement(Button, {href: routeprefix+"mentions", bsStyle: isOnMentions ? 'primary' : 'default'}, React.createElement(Glyphicon, {glyph: "comment"}))
|
||||||
)
|
)
|
||||||
),
|
),
|
||||||
this.props.children && React.cloneElement(this.props.children, {
|
this.props.children && React.cloneElement(this.props.children, {
|
||||||
activeAccount:this.state.activeAccount
|
activeAccount:this.props.activeAccount
|
||||||
})
|
})
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
@ -3108,12 +3103,9 @@ module.exports = Timeline = React.createClass({displayName: "Timeline",
|
|||||||
EventListenerMixin('scrolledtobottom'),
|
EventListenerMixin('scrolledtobottom'),
|
||||||
EventListenerMixin('newpostbyuser')
|
EventListenerMixin('newpostbyuser')
|
||||||
],
|
],
|
||||||
contextTypes: {
|
|
||||||
router: React.PropTypes.func
|
|
||||||
},
|
|
||||||
getInitialState: function() {
|
getInitialState: function() {
|
||||||
return {
|
return {
|
||||||
username: (this.context.router.getCurrentParams().username ? this.context.router.getCurrentParams().username : this.props.activeAccount),
|
username: (this.props.params.username ? this.props.params.username : this.props.activeAccount),
|
||||||
data: [],
|
data: [],
|
||||||
postIdentifiers: {},
|
postIdentifiers: {},
|
||||||
postCount: 30,
|
postCount: 30,
|
||||||
|
26
jsx/App.js
26
jsx/App.js
@ -102,7 +102,9 @@ App = React.createClass({
|
|||||||
Twister.getAccount(acc.name).verifyKey(function(key){
|
Twister.getAccount(acc.name).verifyKey(function(key){
|
||||||
thisComponent.setState(function(oldstate,props){
|
thisComponent.setState(function(oldstate,props){
|
||||||
|
|
||||||
oldstate.accounts[acc.name].status = key.getStatus();
|
oldstate.accounts.find(function(a){
|
||||||
|
return a.name==acc.name;
|
||||||
|
}).status = key.getStatus();
|
||||||
|
|
||||||
return oldstate;
|
return oldstate;
|
||||||
|
|
||||||
@ -151,9 +153,13 @@ App = React.createClass({
|
|||||||
|
|
||||||
render: function() {
|
render: function() {
|
||||||
|
|
||||||
//var firstroute = this.context.router.getCurrentRoutes()[1].name;
|
var route = this.props.location.pathname.split("/").filter(function(s){
|
||||||
|
return s!="";
|
||||||
|
});
|
||||||
|
|
||||||
|
var isOnHome = (route.length==0);
|
||||||
|
|
||||||
//console.log(firstroute);
|
var isOnOwnProfile = ( route[0]="profile" && route[1]==this.state.activeAccount );
|
||||||
|
|
||||||
var guestMode = true;
|
var guestMode = true;
|
||||||
|
|
||||||
@ -198,13 +204,13 @@ App = React.createClass({
|
|||||||
<Col xs={12} sm={10} smOffset={1} md={8} mdOffset={2} lg={6} lgOffset={3}>
|
<Col xs={12} sm={10} smOffset={1} md={8} mdOffset={2} lg={6} lgOffset={3}>
|
||||||
<ButtonGroup justified>
|
<ButtonGroup justified>
|
||||||
<Button
|
<Button
|
||||||
href='#'
|
href='#/'
|
||||||
//bsStyle={firstroute=="home" ? 'primary' : 'default'}
|
bsStyle={isOnHome ? 'primary' : 'default'}
|
||||||
disabled = {guestMode}
|
disabled = {guestMode}
|
||||||
><Glyphicon glyph="home"/></Button>
|
><Glyphicon glyph="home"/></Button>
|
||||||
<Button
|
<Button
|
||||||
href='#/profile'
|
href={'#/profile/'+this.state.activeAccount}
|
||||||
//bsStyle={firstroute=="profile-active" ? 'primary' : 'default'}
|
bsStyle={isOnOwnProfile ? 'primary' : 'default'}
|
||||||
disabled = {guestMode}
|
disabled = {guestMode}
|
||||||
><Glyphicon glyph="user"/></Button>
|
><Glyphicon glyph="user"/></Button>
|
||||||
<Button href='#/directmessages' disabled><Glyphicon glyph="transfer"/></Button>
|
<Button href='#/directmessages' disabled><Glyphicon glyph="transfer"/></Button>
|
||||||
@ -241,12 +247,6 @@ initializeApp = function () {
|
|||||||
<Router history={hashHistory}>
|
<Router history={hashHistory}>
|
||||||
<Route component={App} path="/">
|
<Route component={App} path="/">
|
||||||
<IndexRoute component={Home} />
|
<IndexRoute component={Home} />
|
||||||
<Route path="/profile" component={Profile}>
|
|
||||||
<IndexRoute component={Timeline} />
|
|
||||||
<Route path="timeline" component={Timeline} />
|
|
||||||
<Route path="followings" component={Followings} />
|
|
||||||
<Route path="mentions" component={Mentions} />
|
|
||||||
</Route>
|
|
||||||
<Route path="/profile/:username" component={Profile}>
|
<Route path="/profile/:username" component={Profile}>
|
||||||
<IndexRoute component={Timeline} />
|
<IndexRoute component={Timeline} />
|
||||||
<Route path="timeline" component={Timeline} />
|
<Route path="timeline" component={Timeline} />
|
||||||
|
@ -32,12 +32,12 @@ module.exports = ProfileMixin = {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
getInitialState: function() {
|
getInitialState: function() {
|
||||||
|
|
||||||
var username = this.props.username;
|
var username = this.props.username;
|
||||||
|
|
||||||
if (!username) {
|
if (!username) {
|
||||||
|
|
||||||
username = (this.context.router.getCurrentParams().username ? this.context.router.getCurrentParams().username : this.props.activeAccount);
|
username = (this.props.params.username ? this.props.params.username : this.props.activeAccount);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -23,9 +23,6 @@ module.exports = Settings = React.createClass({
|
|||||||
SafeStateChangeMixin,
|
SafeStateChangeMixin,
|
||||||
AppSettingsMixin
|
AppSettingsMixin
|
||||||
],
|
],
|
||||||
contextTypes: {
|
|
||||||
router: React.PropTypes.func
|
|
||||||
},
|
|
||||||
handeSettingsUpdate: function (e) {
|
handeSettingsUpdate: function (e) {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
|
|
||||||
|
@ -24,12 +24,9 @@ var ReactBootstrap = require('react-bootstrap')
|
|||||||
module.exports = Followings = React.createClass({
|
module.exports = Followings = React.createClass({
|
||||||
|
|
||||||
mixins: [AppSettingsMixin,SetIntervalMixin,SafeStateChangeMixin],
|
mixins: [AppSettingsMixin,SetIntervalMixin,SafeStateChangeMixin],
|
||||||
contextTypes: {
|
|
||||||
router: React.PropTypes.func
|
|
||||||
},
|
|
||||||
getInitialState: function() {
|
getInitialState: function() {
|
||||||
return {
|
return {
|
||||||
username: (this.context.router.getCurrentParams().username ? this.context.router.getCurrentParams().username : this.props.activeAccount),
|
username: (this.props.params.username ? this.props.params.username : this.props.activeAccount),
|
||||||
followings: [],
|
followings: [],
|
||||||
loading: true
|
loading: true
|
||||||
};
|
};
|
||||||
|
@ -11,12 +11,9 @@ var AppSettingsMixin = require('../common/AppSettingsMixin.js');
|
|||||||
module.exports = Mentions = React.createClass({
|
module.exports = Mentions = React.createClass({
|
||||||
|
|
||||||
mixins: [StreamMixin,AppSettingsMixin,SetIntervalMixin,SafeStateChangeMixin],
|
mixins: [StreamMixin,AppSettingsMixin,SetIntervalMixin,SafeStateChangeMixin],
|
||||||
contextTypes: {
|
|
||||||
router: React.PropTypes.func
|
|
||||||
},
|
|
||||||
getInitialState: function() {
|
getInitialState: function() {
|
||||||
return {
|
return {
|
||||||
username: (this.context.router.getCurrentParams().username ? this.context.router.getCurrentParams().username : this.props.activeAccount),
|
username: (this.props.params.username ? this.props.params.username : this.props.activeAccount),
|
||||||
data: [],
|
data: [],
|
||||||
postIdentifiers: {},
|
postIdentifiers: {},
|
||||||
loading: true
|
loading: true
|
||||||
|
@ -23,7 +23,7 @@ var FollowButton = require('../common/FollowButton.js');
|
|||||||
var EditProfileModalButton = require('../profile/EditProfileModalButton.js');
|
var EditProfileModalButton = require('../profile/EditProfileModalButton.js');
|
||||||
var EditAvatarModalButton = require('../profile/EditAvatarModalButton.js');
|
var EditAvatarModalButton = require('../profile/EditAvatarModalButton.js');
|
||||||
|
|
||||||
module.exports = Post = React.createClass({
|
module.exports = Profile = React.createClass({
|
||||||
mixins: [
|
mixins: [
|
||||||
SetIntervalMixin,
|
SetIntervalMixin,
|
||||||
SafeStateChangeMixin,
|
SafeStateChangeMixin,
|
||||||
@ -33,9 +33,13 @@ module.exports = Post = React.createClass({
|
|||||||
|
|
||||||
var routeprefix = "#/profile/"+(this.props.params.username ? this.props.params.username+"/" : "")
|
var routeprefix = "#/profile/"+(this.props.params.username ? this.props.params.username+"/" : "")
|
||||||
|
|
||||||
//var subroute = this.context.router.getCurrentRoutes()[2].name
|
var route = this.props.location.pathname.split("/").filter(function(s){
|
||||||
|
return s!="";
|
||||||
//console.log(this.context.router.getCurrentRoutes());
|
});
|
||||||
|
|
||||||
|
var isOnTimeline = !route[2] || route[2]=="timeline";
|
||||||
|
var isOnMentions = route[2]=="mentions";
|
||||||
|
var isOnFollowings = route[2]=="followings";
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<ListGroup fill>
|
<ListGroup fill>
|
||||||
@ -70,13 +74,13 @@ module.exports = Post = React.createClass({
|
|||||||
</ListGroupItem>
|
</ListGroupItem>
|
||||||
<ListGroupItem className="fullytight_all">
|
<ListGroupItem className="fullytight_all">
|
||||||
<ButtonGroup justified>
|
<ButtonGroup justified>
|
||||||
<Button href={routeprefix+"timeline"} ><Glyphicon glyph="list"/></Button>
|
<Button href={routeprefix+"timeline"} bsStyle={isOnTimeline ? 'primary' : 'default'}><Glyphicon glyph="list"/></Button>
|
||||||
<Button href={routeprefix+"followings"} ><Glyphicon glyph="eye-open"/></Button>
|
<Button href={routeprefix+"followings"} bsStyle={isOnFollowings ? 'primary' : 'default'}><Glyphicon glyph="eye-open"/></Button>
|
||||||
<Button href={routeprefix+"mentions"} ><Glyphicon glyph="comment"/></Button>
|
<Button href={routeprefix+"mentions"} bsStyle={isOnMentions ? 'primary' : 'default'}><Glyphicon glyph="comment"/></Button>
|
||||||
</ButtonGroup>
|
</ButtonGroup>
|
||||||
</ListGroupItem>
|
</ListGroupItem>
|
||||||
{this.props.children && React.cloneElement(this.props.children, {
|
{this.props.children && React.cloneElement(this.props.children, {
|
||||||
activeAccount:this.state.activeAccount
|
activeAccount:this.props.activeAccount
|
||||||
})}
|
})}
|
||||||
</ListGroup>
|
</ListGroup>
|
||||||
);
|
);
|
||||||
|
@ -26,12 +26,9 @@ module.exports = Timeline = React.createClass({
|
|||||||
EventListenerMixin('scrolledtobottom'),
|
EventListenerMixin('scrolledtobottom'),
|
||||||
EventListenerMixin('newpostbyuser')
|
EventListenerMixin('newpostbyuser')
|
||||||
],
|
],
|
||||||
contextTypes: {
|
|
||||||
router: React.PropTypes.func
|
|
||||||
},
|
|
||||||
getInitialState: function() {
|
getInitialState: function() {
|
||||||
return {
|
return {
|
||||||
username: (this.context.router.getCurrentParams().username ? this.context.router.getCurrentParams().username : this.props.activeAccount),
|
username: (this.props.params.username ? this.props.params.username : this.props.activeAccount),
|
||||||
data: [],
|
data: [],
|
||||||
postIdentifiers: {},
|
postIdentifiers: {},
|
||||||
postCount: 30,
|
postCount: 30,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user