Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Condition warning message to log into twitter if script initializes #916

Merged
merged 1 commit into from
Mar 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions packages/libs/web-common/src/App/NewsSidebar/News.scss
Original file line number Diff line number Diff line change
Expand Up @@ -75,4 +75,11 @@ $news-border-width: 2px;
padding-top: 1.2rem;
padding-bottom: 0.2rem;
}

.TwitterTimelineContainer {
p {
margin: 0;
margin-top: 0.5em;
}
}
}
45 changes: 35 additions & 10 deletions packages/libs/web-common/src/components/TwitterTimeline.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ export default class TwitterTimeline extends React.Component {
constructor(props) {
super(props);
this.timelineRef = React.createRef();
this.state = {
isInitialized: false,
};
}

componentDidMount() {
Expand Down Expand Up @@ -34,6 +37,12 @@ export default class TwitterTimeline extends React.Component {
return t;
})(document, 'script', 'twitter-wjs'));

if (!this.state.isInitialized && 'init' in t) {
this.setState({
isInitialized: true,
});
}

t.ready(() => t.widgets.load(this.timelineRef.current));
}

Expand All @@ -46,17 +55,33 @@ export default class TwitterTimeline extends React.Component {
linkColor = null,
} = this.props;
return (
<a
ref={this.timelineRef}
data-height={height}
data-width={width}
data-theme={theme}
data-link-color={linkColor}
className="twitter-timeline"
href={`https://twitter.com/${profileId}`}
<div
className="TwitterTimelineContainer"
style={{
height,
width,
}}
>
Tweets by {profileId}
</a>
<a
ref={this.timelineRef}
data-height={height}
data-width={width}
data-theme={theme}
data-link-color={linkColor}
className="twitter-timeline"
href={`https://twitter.com/${profileId}`}
>
Tweets by {profileId}
</a>
{this.state.isInitialized && (
<p>
<em>
<strong>Warning</strong>: You must be logged into Twitter/X to
view our timeline.
</em>
</p>
)}
</div>
);
}
}
Loading