mirror of
https://github.com/discourse/discourse-user-card-directory.git
synced 2025-06-29 18:02:11 +00:00
UX: improve handling of hidden profiles (#54)
This commit is contained in:
parent
d6bb016b17
commit
eacda5d00e
@ -1,5 +1,6 @@
|
|||||||
import { action } from "@ember/object";
|
import { action } from "@ember/object";
|
||||||
import UserCardContents from "discourse/components/user-card-contents";
|
import UserCardContents from "discourse/components/user-card-contents";
|
||||||
|
import discourseComputed from "discourse/lib/decorators";
|
||||||
|
|
||||||
export default class UserCardStaticContents extends UserCardContents {
|
export default class UserCardStaticContents extends UserCardContents {
|
||||||
layoutName = "components/user-card-contents";
|
layoutName = "components/user-card-contents";
|
||||||
@ -13,6 +14,13 @@ export default class UserCardStaticContents extends UserCardContents {
|
|||||||
willDestroyElement() {}
|
willDestroyElement() {}
|
||||||
keyUp() {}
|
keyUp() {}
|
||||||
|
|
||||||
|
@discourseComputed("user.last_seen_at")
|
||||||
|
contentHidden(lastSeenAt) {
|
||||||
|
// we don't have the full user data available
|
||||||
|
// so if last_seen_at is missing, treat the profile as hidden
|
||||||
|
return !lastSeenAt;
|
||||||
|
}
|
||||||
|
|
||||||
// need to override this to work with the loading slider
|
// need to override this to work with the loading slider
|
||||||
@action
|
@action
|
||||||
handleShowUser() {
|
handleShowUser() {
|
||||||
|
@ -90,17 +90,27 @@ export default {
|
|||||||
// Each user card expects its own promise
|
// Each user card expects its own promise
|
||||||
// Rather than making a separate AJAX request for each
|
// Rather than making a separate AJAX request for each
|
||||||
// We re-use the `user-cards.json` promise, and manipulate the data
|
// We re-use the `user-cards.json` promise, and manipulate the data
|
||||||
const convertedPromise = promise.then((data) => {
|
promise.then((data) => {
|
||||||
// Find the correct user from users, and put it in the user attribute
|
// Find the correct user from users, and put it in the user attribute
|
||||||
|
const foundUser = data.users?.find(
|
||||||
|
(u) => u.id === uc.user.id
|
||||||
|
);
|
||||||
|
|
||||||
|
// cover disabled or inactive profiles
|
||||||
|
if (!foundUser) {
|
||||||
|
uc.set("loading", false);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// Use Object.assign to avoid contaminating the source object
|
// Use Object.assign to avoid contaminating the source object
|
||||||
return Object.assign({}, data, {
|
const convertedPromise = Promise.resolve(
|
||||||
user: data.users.find((u) => u.id === uc.user.id),
|
Object.assign({}, data, { user: foundUser })
|
||||||
});
|
);
|
||||||
});
|
uc.user
|
||||||
return uc.user
|
|
||||||
.findDetails({ existingRequest: convertedPromise })
|
.findDetails({ existingRequest: convertedPromise })
|
||||||
.finally(() => uc.set("loading", false));
|
.finally(() => uc.set("loading", false));
|
||||||
});
|
});
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
return userCardInfos;
|
return userCardInfos;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user