-
Notifications
You must be signed in to change notification settings - Fork 52
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
DEV: migrate post event to glimmer #615
base: main
Are you sure you want to change the base?
Conversation
0299275
to
d1e7930
Compare
@@ -11,7 +11,7 @@ def index | |||
event_invitees = event.invitees | |||
event_invitees = event_invitees.with_status(params[:type].to_sym) if params[:type] | |||
|
|||
possible_invitees = [] | |||
suggested_users = [] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is recent code sam added, I just changed the name as we actually return users and not invitees
not_going: not_going, | ||
invited: going + interested + not_going + unanswered, | ||
} | ||
EventStatsSerializer.new(object, root: false).as_json |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I now use this serializer at two places so I extracted it
@@ -0,0 +1,36 @@ | |||
# frozen_string_literal: true |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The extracted serialize; no new code
@@ -12,21 +12,21 @@ def invitees | |||
|
|||
def meta | |||
{ | |||
possible_invitees: | |||
suggested_users: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
still name change of recent sam change
@@ -15,5 +15,14 @@ def include_id? | |||
def user | |||
BasicUserSerializer.new(object.user, embed: :objects, root: false) | |||
end | |||
|
|||
def meta |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Im returning these info in meta so I can properly update the model without any other remote calls when changing attendance
@@ -0,0 +1,29 @@ | |||
import Component from "@glimmer/component"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
1:1 migration from widget
@@ -0,0 +1,84 @@ | |||
import Component from "@glimmer/component"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This one is a little bit tricky as most of it was computed in the initializer before
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are two cases:
- local dates is enabled
- local dates is disabled
@@ -0,0 +1,198 @@ | |||
import Component from "@glimmer/component"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
1:1 migration, most notable change is that message bus is not setup in this component instead of the initializer
return this.currentUser && this.args.event.can_act_on_discourse_post_event; | ||
} | ||
|
||
get containerHeight() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This part was also done in the initializer before
@@ -0,0 +1,65 @@ | |||
import Component from "@glimmer/component"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
1:1 migration from widget
@@ -0,0 +1,70 @@ | |||
import Component from "@glimmer/component"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
1/1 migration from widget
@@ -0,0 +1,367 @@ | |||
import Component from "@glimmer/component"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was using the widget dropdown and now is using DMenu
@@ -0,0 +1,110 @@ | |||
import Component from "@glimmer/component"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
1:1 migration from widgets with PluginOutlets to support customizations we have
@@ -0,0 +1,25 @@ | |||
import Component from "@glimmer/component"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
1:1 migration from widget
@@ -2,15 +2,15 @@ | |||
@title={{i18n | |||
(concat | |||
"discourse_calendar.discourse_post_event.builder_modal." | |||
(if @model.event.isNew "create_event_title" "update_event_title") | |||
(if @model.event.id "update_event_title" "create_event_title") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I removed isNew, technically it's persisted once we have an id
) | ||
}} | ||
class="post-event-builder-modal" | ||
@closeModal={{@closeModal}} | ||
@flash={{this.flash}} | ||
> | ||
<:body> | ||
<ConditionalLoadingSection @isLoading={{@model.event.isSaving}}> | ||
<ConditionalLoadingSection @isLoading={{this.isSaving}}> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I moved isSaving out of the model
@action={{this.createEvent}} | ||
/> | ||
{{else}} | ||
{{#if @model.event.id}} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just inverted the logic here
@@ -12,29 +12,29 @@ import concatClass from "discourse/helpers/concat-class"; | |||
import i18n from "discourse-common/helpers/i18n"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I created a new "Invitees" model which can also old the suggested users. Not sure yet about this design but this is ok for now
@@ -0,0 +1,30 @@ | |||
import Component from "@glimmer/component"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is replacing the renderInvitee helper. We are actually rendering a User here.
@@ -75,12 +75,10 @@ export default Component.extend({ | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mostly casing changes
starts_at: moment(), | ||
timezone: moment.tz.guess(), | ||
}); | ||
|
||
modal.show(PostEventBuilder, { | ||
model: { | ||
event: eventModel, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
these functions are mostly not needed anymore
status: "public", | ||
custom_fields: EmberObject.create({}), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is now a default, could probably use something else than EmberObject but didn't want to refactor everything
@@ -245,34 +138,6 @@ function initializeDiscoursePostEventDecorator(api) { | |||
"notification.discourse_post_event.notifications.ongoing_event_reminder", | |||
"calendar-day" | |||
); | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
move into the component
if (eventModel && eventContainer) { | ||
eventContainer.innerHTML = ""; | ||
|
||
const datesHeight = 50; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
moved into the component
eventContainer.style.height = `${widgetHeight}px`; | ||
|
||
const glueContainer = document.createElement("div"); | ||
glueContainer.innerHTML = '<div class="spinner medium"></div>'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I haven't reimplemented the spinner logic yet, I should maybe do it
}, | ||
}, | ||
}; | ||
import { tracked } from "@glimmer/tracking"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
tracked properties for events
@@ -0,0 +1,19 @@ | |||
import { tracked } from "@glimmer/tracking"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A tracked stats model
this.__type = "discourse-post-event-invitee"; | ||
}, | ||
}); | ||
import { tracked } from "@glimmer/tracking"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
tracked invitee model
@@ -0,0 +1,52 @@ | |||
import { TrackedArray } from "@ember-compat/tracked-built-ins"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the invitees model; also holding suggested users
@@ -1,18 +1,23 @@ | |||
import { on } from "@ember/object/evented"; | |||
import Route from "@ember/routing/route"; | |||
import { action } from "@ember/object"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
modernizing the route
@@ -0,0 +1,126 @@ | |||
import Service from "@ember/service"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tried to have all the reactivity done in this file, so it's easier to know what's going on after a remote call
put "/discourse-post-event/events/:event_id/invitees/:invitee_id" => "invitees#update" | ||
post "/discourse-post-event/events/:event_id/invitees" => "invitees#create" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I probably should have avoided doing it without refactoring all of them, but I did it... No excuse.
<template> | ||
<span class="event-creator"> | ||
<a class="topic-invitee-avatar" data-user-card={{@user.username}}> | ||
{{this.avatarImage}} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd recommend using the avatar
helper:
{{this.avatarImage}} | |
{{avatar this.user imageSize="tiny"}} |
assets/javascripts/discourse/components/modal/post-event-invitees/user.gjs
Outdated
Show resolved
Hide resolved
assets/javascripts/discourse/components/modal/post-event-invitees/user.gjs
Outdated
Show resolved
Hide resolved
assets/javascripts/discourse/components/discourse-post-event/index.gjs
Outdated
Show resolved
Hide resolved
assets/javascripts/discourse/components/discourse-post-event/invitee.gjs
Outdated
Show resolved
Hide resolved
assets/javascripts/discourse/components/discourse-post-event/url.gjs
Outdated
Show resolved
Hide resolved
} | ||
|
||
@action | ||
async inviteUserOrGroup(event) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think all these 7 methods don't need to have an event arg and could use this.args.event directly
assets/javascripts/discourse/components/discourse-post-event/more-menu.gjs
Outdated
Show resolved
Hide resolved
import { cook } from "discourse/lib/text"; | ||
import i18n from "discourse-common/helpers/i18n"; | ||
import { getAbsoluteURL } from "discourse-common/lib/get-url"; | ||
import I18n from "I18n"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the i18n helper should be enough here
assets/javascripts/discourse/components/discourse-post-event/status.gjs
Outdated
Show resolved
Hide resolved
assets/javascripts/discourse/components/discourse-post-event/invitee.gjs
Outdated
Show resolved
Hide resolved
assets/javascripts/discourse/components/discourse-post-event/invitee.gjs
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great stuff! 🚀
assets/javascripts/discourse/components/discourse-post-event/index.gjs
Outdated
Show resolved
Hide resolved
…ndex.gjs Co-authored-by: Jarek Radosz <[email protected]>
This commit is making two major changes: