Skip to content

Commit

Permalink
update meetup widgets to API v3 - fixes #263
Browse files Browse the repository at this point in the history
  • Loading branch information
xMartin committed Sep 12, 2019
1 parent c42f7ac commit 34ddee3
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 22 deletions.
1 change: 1 addition & 0 deletions _includes/_scripts.html
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
{%comment%} city|jsonify does not work with collections. :( {%endcomment%}
"{{meetup}}": {
page: {{key | jsonify}},
isActive: !{{city.is_inactive | jsonify}}
}{% unless forloop.last %},{% endunless %}
{% endfor %}
}
Expand Down
4 changes: 2 additions & 2 deletions _layouts/city.html
Original file line number Diff line number Diff line change
Expand Up @@ -127,11 +127,11 @@ <h3>You?</h3>
<script src="/scripts/widgets.js" type="text/javascript" charset="utf-8"></script>
<script type="text/javascript" charset="utf-8">
$(function() {
React.renderComponent(OTS.Widgets.UpcomingEventsPreview({teams: OTS.config.chapters, path:"events", page: 5, hideTeams: true, params: {group_urlname: '{{meetup}}'}}), document.getElementById('upcomingEvents'));
React.renderComponent(OTS.Widgets.UpcomingEventsPreview({teams: OTS.config.chapters, chapterNames: ['{{meetup}}'], page: 5, hideTeams: true}), document.getElementById('upcomingEvents'));

React.renderComponent(OTS.Widgets.ChapterConversations({teams: OTS.config.chapters, path:"/category/chapters/{{key}}.json"}), document.getElementById('chapterConversations'));

React.renderComponent(OTS.Widgets.MembersCounter({path:"groups", params: {group_urlname: '{{meetup}}'}}), document.getElementById('membersCount'));
React.renderComponent(OTS.Widgets.MembersCounter({chapterName: '{{meetup}}'}), document.getElementById('membersCount'));


{% if page.discourse_group %}
Expand Down
12 changes: 8 additions & 4 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -120,13 +120,17 @@ <h4>and</h4>
<script src="/scripts/widgets.js" type="text/javascript" charset="utf-8"></script>
<script type="text/javascript" charset="utf-8">
$(function() {
var eventChapterNames = [];
for (var name in OTS.config.chapters) {
if (OTS.config.chapters[name].isActive) {
eventChapterNames.push(name);
}
}
React.renderComponent(
OTS.Widgets.UpcomingEventsPreview({
teams: OTS.config.chapters,
page: 5,
params: {
text: 'opentechschool'
}
chapterNames: eventChapterNames,
page: 5
}),
document.getElementById('upcomingEvents')
);
Expand Down
46 changes: 30 additions & 16 deletions scripts/widgets.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
]),
React.DOM.div({className: "details"}, [
React.DOM.h3({className: "title"},
React.DOM.a({href: cal_event.event_url}, cal_event.name)
React.DOM.a({href: cal_event.link}, cal_event.name)
),
React.DOM.span({className: "venue"}, cal_event.venue ? cal_event.venue.name : "TBA"),
this.props.hideTeams ? React.DOM.span() : React.DOM.span({className: "team", onClick: this.teamClicked}, cal_event.group.name.replace("OpenTechSchool", ""))
Expand Down Expand Up @@ -208,22 +208,35 @@

var MeetupMixin = {
componentWillMount: function() {
var params = $.extend({}, { key: meetupcom_key, sign: true, page: 200}, this.props.params ),
var params = $.extend({key: meetupcom_key, sign: true, page: 200}, this.props.params),
path = this.props.path || 'open_events';
$.getJSON('https://api.meetup.com/2/' + path + '?callback=?', params).
then(function(data){
this.resultsReceived(data);
}.bind(this)
);
$.getJSON('https://api.meetup.com/2/' + path + '?callback=?', params)
.then(function(data){
this.resultsReceived(data);
}.bind(this));
}
};


OTS.Widgets.UpcomingEventsPreview = React.createClass({
mixins: [MeetupMixin],

resultsReceived: function(data){
this.setState({events: this.props.page ? data.results.splice(0, this.props.page) : data.results});
componentWillMount: function() {
var requests = this.props.chapterNames.map(function (chapterName) {
return $.getJSON('https://api.meetup.com/' + chapterName + '/events?callback=?', {page: this.props.page});
}.bind(this));
Promise.all(requests)
.then(function(results) {
var events = [];
for (var i = 0; i < results.length; ++i) {
events = events.concat(results[i].data);
}
events.sort(function(a, b) {
return a.time < b.time ? -1 : 1;
});
if (this.props.page) {
events = events.splice(0, this.props.page);
}
this.setState({events: events});
}.bind(this));
},

getInitialState: function() {
Expand Down Expand Up @@ -402,11 +415,12 @@


OTS.Widgets.MembersCounter = React.createClass({
mixins: [MeetupMixin],

resultsReceived: function(data){
var group = data.results[0];
this.setState({members: group.members, who: group.who});
componentWillMount: function() {
$.getJSON('https://api.meetup.com/' + this.props.chapterName + '?callback=?')
.then(function(data) {
var group = data.data;
this.setState({members: group.members, who: group.who});
}.bind(this));
},

getInitialState: function() {
Expand Down

0 comments on commit 34ddee3

Please sign in to comment.