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

Add 'after' param to /discourse-post-event/events.json call and Only show events of current category #2

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
9 changes: 1 addition & 8 deletions javascripts/discourse/initializers/layouts-event-list.js.es6
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { ajax } from "discourse/lib/ajax";

export default {
name: "layouts-event-list",
Expand All @@ -20,12 +19,6 @@ export default {

if (layoutsError || !siteSettings.calendar_enabled) return;

ajax(`/discourse-post-event/events.json`).then((eventList) => {
const events = eventList.events;
const props = {
events,
};
layouts.addSidebarProps(props);
});
layouts.addSidebarProps({});
},
};
33 changes: 32 additions & 1 deletion javascripts/discourse/widgets/layouts-event-list.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { createWidget } from "discourse/widgets/widget";
import { h } from "virtual-dom";
const { iconNode } = require("discourse-common/lib/icon-library");
const { iconHTML } = require("discourse-common/lib/icon-library");
import { ajax } from "discourse/lib/ajax";

let layouts;

Expand Down Expand Up @@ -32,8 +33,38 @@ function htmlDecode(input) {
}

export default layouts.createLayoutsWidget("event-list", {

defaultState(attrs) {
return {
categoryId: false, // Is not set to make a turn by didRenderWidget
events : [],
};
},

didRenderWidget() {
var self = this;
const { attrs } = this;
const { category } = attrs;
const categoryId = category?.id || null;

if (
category === false
|| categoryId !== this.state.categoryId
) {
const now = new Date();
const categoryParam = category?.id ? `&category_id=${category.id}&include_subcategories=true` : '';
const eventQuery = `/discourse-post-event/events.json?after=${now.toISOString()}${categoryParam}`;

ajax(eventQuery).then((eventList) => {
self.state.events = eventList.events;
self.state.categoryId = category?.id || null;
self.scheduleRerender();
});
}
},

html(attrs) {
const { events } = attrs;
const { events } = this.state;

if (events == null || events == undefined) return;

Expand Down