Refactor code duplication in Chat root
@@ -87,14 +87,7 @@ export class Root extends Component {
inviteConfig = configs[`~${window.ship}/i`];
}
- return (
- <BrowserRouter>
- <div>
- <Route exact path="/~chat"
- render={ (props) => {
- return (
- <Skeleton
- sidebar={
+ const renderChannelsSidebar = (props) => (
<Sidebar
circles={circles}
messagePreviews={messagePreviews}
@@ -104,7 +97,16 @@ export class Root extends Component {
inviteConfig={inviteConfig}
{...props}
/>
- }>
+ );
+
+ return (
+ <BrowserRouter>
+ <div>
+ <Route exact path="/~chat"
+ render={ (props) => {
+ return (
+ <Skeleton
+ sidebar={renderChannelsSidebar(props)}>
<div className="w-100 h-100 fr" style={{ flexGrow: 1 }}>
<div className="dt w-100 h-100">
<div className="dtc center v-mid w-100 h-100 bg-white">
@@ -119,17 +121,7 @@ export class Root extends Component {
return (
<Skeleton
spinner={this.state.spinner}
- sidebar={
- <Sidebar
- circles={circles}
- messagePreviews={messagePreviews}
- invites={invites}
- unreads={unreads}
- api={api}
- inviteConfig={inviteConfig}
- {...props}
- />
- }>
+ sidebar={renderChannelsSidebar(props)}>
<NewScreen
setSpinner={this.setSpinner}
api={api}
@@ -143,17 +135,7 @@ export class Root extends Component {
render={ (props) => {
return (
<Skeleton
- sidebar={
- <Sidebar
- circles={circles}
- messagePreviews={messagePreviews}
- invites={invites}
- unreads={unreads}
- api={api}
- inviteConfig={inviteConfig}
- {...props}
- />
- }>
+ sidebar={renderDefaultSidebar(props)}>
<LandingScreen
api={api}
configs={configs}
@@ -171,17 +153,7 @@ export class Root extends Component {
let messages = state.messages[station] || [];
return (
<Skeleton
- sidebar={
- <Sidebar
- circles={circles}
- messagePreviews={messagePreviews}
- invites={invites}
- unreads={unreads}
- api={api}
- inviteConfig={inviteConfig}
- {...props}
- />
- }>
+ sidebar={renderChannelsSidebar(props) }>
<ChatScreen
api={api}
configs={configs}
@@ -197,17 +169,7 @@ export class Root extends Component {
render={ (props) => {
return (
<Skeleton
- sidebar={
- <Sidebar
- circles={circles}
- messagePreviews={messagePreviews}
- invites={invites}
- unreads={unreads}
- api={api}
- inviteConfig={inviteConfig}
- {...props}
- />
- }>
+ sidebar={renderChannelsSidebar(props) }>
<MemberScreen
{...props}
api={api}
@@ -221,17 +183,7 @@ export class Root extends Component {
return (
<Skeleton
spinner={this.state.spinner}
- sidebar={
- <Sidebar
- circles={circles}
- messagePreviews={messagePreviews}
- invites={invites}
- unreads={unreads}
- api={api}
- inviteConfig={inviteConfig}
- {...props}
- />
- }>
+ sidebar={renderChannelsSidebar(props) }>
<SettingsScreen
{...props}
setSpinner={this.setSpinner}
