mirror of
https://github.com/discourse/discourse.git
synced 2024-11-22 22:21:55 +08:00
REFACTOR: Migrate screenTrack
to a service
This commit is contained in:
parent
86aa5d5e48
commit
f52927cd33
|
@ -4,6 +4,7 @@ import MountWidget from "discourse/components/mount-widget";
|
||||||
import { cloak, uncloak } from "discourse/widgets/post-stream";
|
import { cloak, uncloak } from "discourse/widgets/post-stream";
|
||||||
import { isWorkaroundActive } from "discourse/lib/safari-hacks";
|
import { isWorkaroundActive } from "discourse/lib/safari-hacks";
|
||||||
import offsetCalculator from "discourse/lib/offset-calculator";
|
import offsetCalculator from "discourse/lib/offset-calculator";
|
||||||
|
import { inject as service } from "@ember/service";
|
||||||
|
|
||||||
function findTopView($posts, viewportTop, postsWrapperTop, min, max) {
|
function findTopView($posts, viewportTop, postsWrapperTop, min, max) {
|
||||||
if (max < min) {
|
if (max < min) {
|
||||||
|
@ -26,6 +27,7 @@ function findTopView($posts, viewportTop, postsWrapperTop, min, max) {
|
||||||
}
|
}
|
||||||
|
|
||||||
export default MountWidget.extend({
|
export default MountWidget.extend({
|
||||||
|
screenTrack: service(),
|
||||||
widget: "post-stream",
|
widget: "post-stream",
|
||||||
_topVisible: null,
|
_topVisible: null,
|
||||||
_bottomVisible: null,
|
_bottomVisible: null,
|
||||||
|
|
|
@ -43,6 +43,9 @@ export function registerCustomPostMessageCallback(type, callback) {
|
||||||
export default Controller.extend(bufferedProperty("model"), {
|
export default Controller.extend(bufferedProperty("model"), {
|
||||||
composer: controller(),
|
composer: controller(),
|
||||||
application: controller(),
|
application: controller(),
|
||||||
|
documentTitle: service(),
|
||||||
|
screenTrack: service(),
|
||||||
|
|
||||||
multiSelect: false,
|
multiSelect: false,
|
||||||
selectedPostIds: null,
|
selectedPostIds: null,
|
||||||
editingTopic: false,
|
editingTopic: false,
|
||||||
|
@ -60,7 +63,6 @@ export default Controller.extend(bufferedProperty("model"), {
|
||||||
username_filters: null,
|
username_filters: null,
|
||||||
filter: null,
|
filter: null,
|
||||||
quoteState: null,
|
quoteState: null,
|
||||||
documentTitle: service(),
|
|
||||||
|
|
||||||
canRemoveTopicFeaturedLink: and(
|
canRemoveTopicFeaturedLink: and(
|
||||||
"canEditTopicFeaturedLink",
|
"canEditTopicFeaturedLink",
|
||||||
|
@ -454,9 +456,7 @@ export default Controller.extend(bufferedProperty("model"), {
|
||||||
},
|
},
|
||||||
|
|
||||||
deferTopic() {
|
deferTopic() {
|
||||||
const screenTrack = Discourse.__container__.lookup("screen-track:main");
|
const { screenTrack, currentUser, topic } = this;
|
||||||
const currentUser = this.currentUser;
|
|
||||||
const topic = this.model;
|
|
||||||
|
|
||||||
screenTrack.reset();
|
screenTrack.reset();
|
||||||
screenTrack.stop();
|
screenTrack.stop();
|
||||||
|
|
|
@ -9,7 +9,7 @@ export default {
|
||||||
name: "signup-cta",
|
name: "signup-cta",
|
||||||
|
|
||||||
initialize(container) {
|
initialize(container) {
|
||||||
const screenTrack = container.lookup("screen-track:main");
|
const screenTrack = container.lookup("service:screen-track");
|
||||||
const session = Session.current();
|
const session = Session.current();
|
||||||
const siteSettings = container.lookup("site-settings:main");
|
const siteSettings = container.lookup("site-settings:main");
|
||||||
const keyValueStore = container.lookup("key-value-store:main");
|
const keyValueStore = container.lookup("key-value-store:main");
|
||||||
|
|
|
@ -71,17 +71,14 @@ export default {
|
||||||
ALL_TARGETS.forEach(t => app.inject(t, "session", "session:main"));
|
ALL_TARGETS.forEach(t => app.inject(t, "session", "session:main"));
|
||||||
app.inject("service", "session", "session:main");
|
app.inject("service", "session", "session:main");
|
||||||
|
|
||||||
|
// TODO: Automatically register this service
|
||||||
const screenTrack = new ScreenTrack(
|
const screenTrack = new ScreenTrack(
|
||||||
topicTrackingState,
|
topicTrackingState,
|
||||||
siteSettings,
|
siteSettings,
|
||||||
session,
|
session,
|
||||||
currentUser
|
currentUser
|
||||||
);
|
);
|
||||||
|
app.register("service:screen-track", screenTrack, { instantiate: false });
|
||||||
app.register("screen-track:main", screenTrack, { instantiate: false });
|
|
||||||
["component", "route"].forEach(t =>
|
|
||||||
app.inject(t, "screenTrack", "screen-track:main")
|
|
||||||
);
|
|
||||||
|
|
||||||
if (currentUser) {
|
if (currentUser) {
|
||||||
["component", "route", "controller", "service"].forEach(t => {
|
["component", "route", "controller", "service"].forEach(t => {
|
||||||
|
|
|
@ -10,6 +10,7 @@ import { defaultHomepage } from "discourse/lib/utilities";
|
||||||
import Session from "discourse/models/session";
|
import Session from "discourse/models/session";
|
||||||
import { Promise } from "rsvp";
|
import { Promise } from "rsvp";
|
||||||
import Site from "discourse/models/site";
|
import Site from "discourse/models/site";
|
||||||
|
import { inject as service } from "@ember/service";
|
||||||
|
|
||||||
// A helper to build a topic route for a filter
|
// A helper to build a topic route for a filter
|
||||||
function filterQueryParams(params, defaultParams) {
|
function filterQueryParams(params, defaultParams) {
|
||||||
|
@ -87,6 +88,7 @@ export default function(filter, extras) {
|
||||||
extras = extras || {};
|
extras = extras || {};
|
||||||
return DiscourseRoute.extend(
|
return DiscourseRoute.extend(
|
||||||
{
|
{
|
||||||
|
screenTrack: service(),
|
||||||
queryParams,
|
queryParams,
|
||||||
|
|
||||||
beforeModel() {
|
beforeModel() {
|
||||||
|
|
|
@ -5,12 +5,15 @@ import DiscourseRoute from "discourse/routes/discourse";
|
||||||
import DiscourseURL from "discourse/lib/url";
|
import DiscourseURL from "discourse/lib/url";
|
||||||
import { ID_CONSTRAINT } from "discourse/models/topic";
|
import { ID_CONSTRAINT } from "discourse/models/topic";
|
||||||
import { setTopicId } from "discourse/lib/topic-list-tracker";
|
import { setTopicId } from "discourse/lib/topic-list-tracker";
|
||||||
|
import { inject as service } from "@ember/service";
|
||||||
|
|
||||||
const SCROLL_DELAY = 500;
|
const SCROLL_DELAY = 500;
|
||||||
|
|
||||||
import showModal from "discourse/lib/show-modal";
|
import showModal from "discourse/lib/show-modal";
|
||||||
|
|
||||||
const TopicRoute = DiscourseRoute.extend({
|
const TopicRoute = DiscourseRoute.extend({
|
||||||
|
screenTrack: service(),
|
||||||
|
|
||||||
init() {
|
init() {
|
||||||
this._super(...arguments);
|
this._super(...arguments);
|
||||||
|
|
||||||
|
|
|
@ -14,6 +14,7 @@ moduleFor("controller:topic", "controller:topic", {
|
||||||
"service:document-title"
|
"service:document-title"
|
||||||
],
|
],
|
||||||
beforeEach() {
|
beforeEach() {
|
||||||
|
this.registry.register("service:screen-track", {}, { instantiate: false });
|
||||||
this.registry.injection("controller", "appEvents", "service:app-events");
|
this.registry.injection("controller", "appEvents", "service:app-events");
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue
Block a user