diff --git a/app/javascript/src/__tests__/__snapshots__/Onboarding.test.jsx.snap b/app/javascript/src/__tests__/__snapshots__/Onboarding.test.jsx.snap
index e0d8aa833..bbde3463f 100644
--- a/app/javascript/src/__tests__/__snapshots__/Onboarding.test.jsx.snap
+++ b/app/javascript/src/__tests__/__snapshots__/Onboarding.test.jsx.snap
@@ -247,7 +247,7 @@ preact-render-spy (1 nodes)
>
@@ -255,7 +255,7 @@ preact-render-spy (1 nodes)
@@ -278,7 +278,7 @@ preact-render-spy (1 nodes)
@@ -301,7 +301,7 @@ preact-render-spy (1 nodes)
@@ -891,7 +891,7 @@ preact-render-spy (1 nodes)
@@ -914,7 +914,7 @@ preact-render-spy (1 nodes)
@@ -937,7 +937,7 @@ preact-render-spy (1 nodes)
@@ -1152,7 +1152,7 @@ preact-render-spy (1 nodes)
@@ -1175,7 +1175,7 @@ preact-render-spy (1 nodes)
@@ -1198,7 +1198,7 @@ preact-render-spy (1 nodes)
- #
- {this.props.tag.name}
+ #{tag.name}
- {this.props.tag.following ? '✓' : '+'}
+ {tag.following ? '✓' : '+'}
);
}
}
-OnboardingSingleTag.propTypes = {
- onTagClick: PropTypes.func.isRequired,
- tag: PropTypes.object.isRequired,
-};
-
export default OnboardingSingleTag;
diff --git a/app/javascript/src/components/OnboardingTags.jsx b/app/javascript/src/components/OnboardingTags.jsx
index e3e4d7d0b..3ad197254 100644
--- a/app/javascript/src/components/OnboardingTags.jsx
+++ b/app/javascript/src/components/OnboardingTags.jsx
@@ -1,30 +1,30 @@
-import { h, render, Component } from 'preact';
+import { h } from 'preact';
+import PropTypes from 'prop-types';
import OnboardingSingleTag from './OnboardingSingleTag';
// page 2
-class OnboardingTags extends Component {
- constructor(props) {
- super(props);
- }
-
- render() {
- const tags = this.props.allTags.map(tag => {
- return (
-
- );
- });
-
+function OnboardingTags({ allTags, handleFollowTag }) {
+ const tags = allTags.map(tag => {
return (
-
-
Personalize your home feed
-
{tags}
-
+
);
- }
+ });
+
+ return (
+
+
Personalize your home feed
+
{tags}
+
+ );
}
+OnboardingTags.propTypes = {
+ handleFollowTag: PropTypes.func.isRequired,
+ allTags: PropTypes.objectOf().isRequired,
+};
+
export default OnboardingTags;
diff --git a/app/javascript/src/components/__tests__/__snapshots__/OnboardingFollowTags.test.jsx.snap b/app/javascript/src/components/__tests__/__snapshots__/OnboardingFollowTags.test.jsx.snap
index 4b0720c4d..8215a6665 100644
--- a/app/javascript/src/components/__tests__/__snapshots__/OnboardingFollowTags.test.jsx.snap
+++ b/app/javascript/src/components/__tests__/__snapshots__/OnboardingFollowTags.test.jsx.snap
@@ -19,7 +19,7 @@ exports[` renders properly when given a tag 1`] = `
>
@@ -27,7 +27,7 @@ exports[` renders properly when given a tag 1`] = `
renders properly when given a tag 1`] = `
>
@@ -50,7 +50,7 @@ exports[` renders properly when given a tag 1`] = `
renders properly when given a tag 1`] = `
>
@@ -73,7 +73,7 @@ exports[` renders properly when given a tag 1`] = `
when given a following tag renders correctly 1`
>
@@ -16,7 +16,7 @@ exports[` when given a following tag renders correctly 1`
when given a non-following tag renders correctl
>
@@ -42,7 +42,7 @@ exports[` when given a non-following tag renders correctl
{
// Hack, should probably be its own component in future
document.getElementById('connect-number').classList.remove('showing');
component.setState({ visible: false });
@@ -26,47 +38,49 @@ class UnopenedChannelNotice extends Component {
}
receiveNewMessage = e => {
- if (location.pathname.startsWith('/connect')) {
+ if (window.location.pathname.startsWith('/connect')) {
return;
}
- const channels = this.state.unopenedChannels;
+ const { unopenedChannels } = this.state;
const newObj = { adjusted_slug: e.chat_channel_adjusted_slug };
if (
- channels.filter(obj => obj.adjusted_slug === newObj.adjusted_slug)
+ unopenedChannels.filter(obj => obj.adjusted_slug === newObj.adjusted_slug)
.length === 0 &&
- newObj.adjusted_slug != `@${window.currentUser.username}`
+ newObj.adjusted_slug !== `@${window.currentUser.username}`
) {
- channels.push(newObj);
+ unopenedChannels.push(newObj);
}
this.setState({
- visible: channels.length > 0 && e.user_id != window.currentUser.id,
- unopenedChannels: channels,
+ visible:
+ unopenedChannels.length > 0 && e.user_id !== window.currentUser.id,
+ unopenedChannels,
});
const number = document.getElementById('connect-number');
number.classList.add('showing');
- number.innerHTML = channels.length;
+ number.innerHTML = unopenedChannels.length;
const component = this;
- if (channels.length === 0) {
+ if (unopenedChannels.length === 0) {
number.classList.remove('showing');
} else {
document.getElementById('connect-link').href = `/connect/${
- channels[0].adjusted_slug
+ unopenedChannels[0].adjusted_slug
}`;
}
- setTimeout(function() {
+ setTimeout(() => {
component.setState({ visible: false });
}, 7500);
};
- handleClick = e => {
+ handleClick = () => {
document.getElementById('connect-number').classList.remove('showing');
this.setState({ visible: false });
};
render() {
- if (this.state.visible) {
- const channels = this.state.unopenedChannels.map(channel => {
+ const { visible, unopenedChannels } = this.state;
+ if (visible) {
+ const channels = unopenedChannels.map(channel => {
return (
- New Message from
- {' '}
- {channels}
+ New Message from {channels}
);
}
+
+ return '';
}
}
-export default function getUnopenedChannels(user, successCb) {
+function manageChannel(json) {
+ const number = document.getElementById('connect-number');
+ if (json.length > 0) {
+ number.classList.add('showing');
+ number.innerHTML = json.length;
+ document.getElementById('connect-link').href = `/connect/${
+ json[0].adjusted_slug
+ }`; // Jump the user directly to the channel where appropriate
+ } else {
+ number.classList.remove('showing');
+ }
+}
+
+export default function getUnopenedChannels() {
render(
,
document.getElementById('message-notice'),
);
- if (location.pathname.startsWith('/connect')) {
- return;
- }
+ if (window.location.pathname.startsWith('/connect')) return;
fetch('/chat_channels?state=unopened', {
- method: 'GET',
credentials: 'same-origin',
})
.then(response => response.json())
.then(json => {
- const number = document.getElementById('connect-number');
- if (json.length > 0) {
- number.classList.add('showing');
- number.innerHTML = json.length;
- document.getElementById('connect-link').href = `/connect/${
- json[0].adjusted_slug
- }`; // Jump the user directly to the channel where appropriate
- } else {
- number.classList.remove('showing');
- }
- })
- .catch(error => {
- console.log(error);
+ manageChannel(json);
});
}