This repository has been archived on 2023-03-18. You can view files and clone it, but cannot push or open issues or pull requests.
osr-discourse-src/app/assets/javascripts/discourse/app/controllers/auth-token.js
2022-10-13 16:16:22 -04:00

49 lines
1.2 KiB
JavaScript

import Controller from "@ember/controller";
import ModalFunctionality from "discourse/mixins/modal-functionality";
import { ajax } from "discourse/lib/ajax";
import { action } from "@ember/object";
import { next } from "@ember/runloop";
import { userPath } from "discourse/lib/url";
export default Controller.extend(ModalFunctionality, {
expanded: false,
onShow() {
ajax(
userPath(`${this.get("currentUser.username_lower")}/activity.json`)
).then((posts) => {
if (posts.length > 0) {
this.set("latest_post", posts[0]);
// slightly hacky, but default d-modal focus gets reset
document.querySelector(".d-modal .modal-close")?.focus();
}
});
},
@action
toggleExpanded(event) {
event?.preventDefault();
this.set("expanded", !this.expanded);
},
actions: {
highlightSecure() {
this.send("closeModal");
next(() => {
const $prefPasswordDiv = $(".pref-password");
$prefPasswordDiv.addClass("highlighted");
$prefPasswordDiv.on("animationend", () =>
$prefPasswordDiv.removeClass("highlighted")
);
window.scrollTo({
top: $prefPasswordDiv.offset().top,
behavior: "smooth",
});
});
},
},
});