Skip to content

Commit

Permalink
Merge pull request #46 from kadirahq/show-comments-for-guest
Browse files Browse the repository at this point in the history
Show comments and login button for guests
  • Loading branch information
Muhammed Thanish authored Oct 20, 2016
2 parents 90eb928 + 0583b5c commit 2563d1a
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 32 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"testonly": "mocha --require .scripts/mocha_runner src/**/tests/**/*.js",
"test": "npm run lint && npm run testonly",
"test-watch": "npm run testonly -- --watch --watch-extensions js",
"storybook": "STORYBOOK_CLOUD_SERVER='http://localhost:3003/graphql' STORYBOOK_CLOUD_APPID='test-app' STORYBOOK_CLOUD_DATABASE='test-db' start-storybook -p 3006",
   "storybook": "start-storybook -p 3006",
"storybook-local": "STORYBOOK_CLOUD_SERVER='http://localhost:3003/graphql' start-storybook -p 9010",
"storybook-remote": "start-storybook -p 3006",
"publish-storybook": "bash .scripts/publish_storybook.sh"
Expand Down
21 changes: 21 additions & 0 deletions src/manager/components/CommentForm/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@ export default class CommentForm extends Component {
this.setState({ text: '' });
}

openLogin() {
const signInUrl = `https://hub.getstorybook.io/sign-in?redirectUrl=${encodeURIComponent(location.href)}`;
location.href = signInUrl;
}

handleKeyDown(e) {
if (e.key === 'Enter' && !e.shiftKey) {
e.preventDefault();
Expand All @@ -49,6 +54,22 @@ export default class CommentForm extends Component {
}

render() {
if (!this.props.user) {
return (
<div style={style.wrapper}>
<Textarea
style={style.input}
disabled={true}
/>
<button
style={style.submitButton}
onClick={() => this.openLogin()}
>Sign in with Storybook Hub
</button>
</div>
);
}

const { text } = this.state;
return (
<div style={style.wrapper}>
Expand Down
5 changes: 0 additions & 5 deletions src/manager/components/CommentForm/style.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,6 @@ export default {
alignItems: 'center',
borderTop: '1px solid rgb(234, 234, 234)',
},
loginButton: {
...button,
fontWeight: 'bold',
borderRight: '1px solid rgb(234, 234, 234)',
},
submitButton: {
...button,
cursor: 'pointer',
Expand Down
2 changes: 1 addition & 1 deletion src/manager/components/CommentList/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export default class CommentList extends Component {
<CommentItem
key={`comment_${idx}`}
comment={comment}
ownComment={comment.userId === this.props.user.id}
ownComment={comment.userId === this.props.user && this.props.user.id}
deleteComment={() => this.props.deleteComment(comment.id)}
/>
))}
Expand Down
11 changes: 0 additions & 11 deletions src/manager/components/CommentsPanel/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,6 @@ export default class CommentsPanel extends Component {
);
}

if (!this.props.user) {
const signInUrl = `https://hub.getstorybook.io/sign-in?redirectUrl=${encodeURIComponent(location.href)}`;
return (
<div style={style.wrapper}>
<div style={style.message}>
<a style={style.button} href={signInUrl}>SignIn with Storybook Hub</a>
</div>
</div>
);
}

if (this.props.appNotAvailable) {
const appsUrl = 'https://hub.getstorybook.io/apps';
return (
Expand Down
11 changes: 2 additions & 9 deletions src/manager/containers/CommentsPanel/dataStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ export default class DataStore {
this.currentStory = { sbKind, sbStory };

// We don't need to do anything if the there's no loggedIn user.
if (!this.user) return;
// if (!this.user) return;

this._reloadCurrentComments();
const item = this._getFromCache(this.currentStory);
Expand Down Expand Up @@ -88,13 +88,6 @@ export default class DataStore {

setCurrentUser(user) {
this.user = user;
// We don't load comments in the `setCurrentStory` if there's no loggedIn
// user.
// That's why we need to do this here.
if (user && this.currentStory) {
const { sbKind, sbStory } = this.currentStory;
this.setCurrentStory(sbKind, sbStory);
}
}

_loadUsers() {
Expand Down Expand Up @@ -123,7 +116,7 @@ export default class DataStore {
// add to cache
this._addToCache(currentStory, comments);

/* eslint no-param-reassign:0 */
/* eslint no-param-reassign:0 */
// set comments only if we are on the relavant story
if (deepEquals(currentStory, this.currentStory)) {
this._fireComments(comments);
Expand Down
9 changes: 4 additions & 5 deletions src/manager/containers/CommentsPanel/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,13 +63,12 @@ export default class Container extends Component {
db.persister._getUser()
.then(u => Promise.resolve(u), err => Promise.resolve(null))
.then((user) => {
if (!user) {
if (user) {
this.store.setCurrentUser(user);
this.setState({ user });
} else {
this.setState({ user: null });
return Promise.resolve(null);
}

this.store.setCurrentUser(user);
this.setState({ user });
return this._getAppInfo(db.persister);
})
.then((appInfo) => {
Expand Down

0 comments on commit 2563d1a

Please sign in to comment.