|
@@ -51,15 +51,19 @@ export default class PageContainer extends Container {
|
|
|
revisionCreatedAt: +mainContent.getAttribute('data-page-revision-created'),
|
|
revisionCreatedAt: +mainContent.getAttribute('data-page-revision-created'),
|
|
|
path,
|
|
path,
|
|
|
tocHtml: '',
|
|
tocHtml: '',
|
|
|
- isLiked: false,
|
|
|
|
|
|
|
+
|
|
|
isBookmarked: false,
|
|
isBookmarked: false,
|
|
|
|
|
+ sumOfBookmarks: 0,
|
|
|
|
|
+
|
|
|
seenUsers: [],
|
|
seenUsers: [],
|
|
|
- seenUserIds: mainContent.getAttribute('data-page-ids-of-seen-users'),
|
|
|
|
|
- countOfSeenUsers: mainContent.getAttribute('data-page-count-of-seen-users'),
|
|
|
|
|
|
|
+ seenUserIds: [],
|
|
|
|
|
+ sumOfSeenUsers: [],
|
|
|
|
|
|
|
|
- likerUsers: [],
|
|
|
|
|
|
|
+ isLiked: false,
|
|
|
|
|
+ likers: [],
|
|
|
|
|
+ likerIds: [],
|
|
|
sumOfLikers: 0,
|
|
sumOfLikers: 0,
|
|
|
- sumOfBookmarks: 0,
|
|
|
|
|
|
|
+
|
|
|
createdAt: mainContent.getAttribute('data-page-created-at'),
|
|
createdAt: mainContent.getAttribute('data-page-created-at'),
|
|
|
updatedAt: mainContent.getAttribute('data-page-updated-at'),
|
|
updatedAt: mainContent.getAttribute('data-page-updated-at'),
|
|
|
deletedAt: mainContent.getAttribute('data-page-deleted-at') || null,
|
|
deletedAt: mainContent.getAttribute('data-page-deleted-at') || null,
|
|
@@ -109,7 +113,7 @@ export default class PageContainer extends Container {
|
|
|
interceptorManager.addInterceptor(new RestoreCodeBlockInterceptor(appContainer), 900); // process as late as possible
|
|
interceptorManager.addInterceptor(new RestoreCodeBlockInterceptor(appContainer), 900); // process as late as possible
|
|
|
|
|
|
|
|
this.initStateMarkdown();
|
|
this.initStateMarkdown();
|
|
|
- this.checkAndUpdateImageUrlCached(this.state.likerUsers);
|
|
|
|
|
|
|
+ this.checkAndUpdateImageUrlCached(this.state.likers);
|
|
|
|
|
|
|
|
const { isSharedUser } = this.appContainer;
|
|
const { isSharedUser } = this.appContainer;
|
|
|
|
|
|
|
@@ -117,8 +121,10 @@ export default class PageContainer extends Container {
|
|
|
const isAbleToGetAttachedInformationAboutPages = this.state.isPageExist && !isSharedUser;
|
|
const isAbleToGetAttachedInformationAboutPages = this.state.isPageExist && !isSharedUser;
|
|
|
|
|
|
|
|
if (isAbleToGetAttachedInformationAboutPages) {
|
|
if (isAbleToGetAttachedInformationAboutPages) {
|
|
|
- this.retrieveSeenUsers();
|
|
|
|
|
- this.retrieveLikeInfo();
|
|
|
|
|
|
|
+ // We don't retrieve bookmarks in the initial page load
|
|
|
|
|
+ // as it is stored in a separate collection to like and seen user
|
|
|
|
|
+ // data so it has a separate api endpoint.
|
|
|
|
|
+ this.initialPageLoad();
|
|
|
this.retrieveBookmarkInfo();
|
|
this.retrieveBookmarkInfo();
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -219,7 +225,7 @@ export default class PageContainer extends Container {
|
|
|
* whether to like button
|
|
* whether to like button
|
|
|
* not displayed on user page
|
|
* not displayed on user page
|
|
|
*/
|
|
*/
|
|
|
- get isAbleToShowLikeButton() {
|
|
|
|
|
|
|
+ get isAbleToShowLikeButtons() {
|
|
|
const { isUserPage } = this.state;
|
|
const { isUserPage } = this.state;
|
|
|
const { isSharedUser } = this.appContainer;
|
|
const { isSharedUser } = this.appContainer;
|
|
|
|
|
|
|
@@ -264,29 +270,54 @@ export default class PageContainer extends Container {
|
|
|
this.state.markdown = markdown;
|
|
this.state.markdown = markdown;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- async retrieveSeenUsers() {
|
|
|
|
|
- const { users } = await this.appContainer.apiGet('/users.list', { user_ids: this.state.seenUserIds });
|
|
|
|
|
|
|
|
|
|
- this.setState({ seenUsers: users });
|
|
|
|
|
- this.checkAndUpdateImageUrlCached(users);
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ async initialPageLoad() {
|
|
|
|
|
+ {
|
|
|
|
|
+ const {
|
|
|
|
|
+ data: {
|
|
|
|
|
+ likerIds, sumOfLikers, isLiked, seenUserIds, sumOfSeenUsers, isSeen,
|
|
|
|
|
+ },
|
|
|
|
|
+ } = await this.appContainer.apiv3Get('/page/info', { _id: this.state.pageId });
|
|
|
|
|
|
|
|
- async retrieveLikeInfo() {
|
|
|
|
|
- const res = await this.appContainer.apiv3Get('/page/like-info', { _id: this.state.pageId });
|
|
|
|
|
- const { sumOfLikers, isLiked } = res.data;
|
|
|
|
|
|
|
+ await this.setState({
|
|
|
|
|
+ sumOfLikers,
|
|
|
|
|
+ isLiked,
|
|
|
|
|
+ likerIds,
|
|
|
|
|
+ seenUserIds,
|
|
|
|
|
+ sumOfSeenUsers,
|
|
|
|
|
+ isSeen,
|
|
|
|
|
+ });
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
- this.setState({
|
|
|
|
|
- sumOfLikers,
|
|
|
|
|
- isLiked,
|
|
|
|
|
- });
|
|
|
|
|
|
|
+ await this.retrieveLikersAndSeenUsers();
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
async toggleLike() {
|
|
async toggleLike() {
|
|
|
- const bool = !this.state.isLiked;
|
|
|
|
|
- await this.appContainer.apiv3Put('/page/likes', { pageId: this.state.pageId, bool });
|
|
|
|
|
- this.setState({ isLiked: bool });
|
|
|
|
|
|
|
+ {
|
|
|
|
|
+ const toggledIsLiked = !this.state.isLiked;
|
|
|
|
|
+ await this.appContainer.apiv3Put('/page/likes', { pageId: this.state.pageId, bool: toggledIsLiked });
|
|
|
|
|
+
|
|
|
|
|
+ await this.setState(state => ({
|
|
|
|
|
+ isLiked: toggledIsLiked,
|
|
|
|
|
+ sumOfLikers: toggledIsLiked ? state.sumOfLikers + 1 : state.sumOfLikers - 1,
|
|
|
|
|
+ likerIds: toggledIsLiked
|
|
|
|
|
+ ? [...this.state.likerIds, this.appContainer.currentUserId]
|
|
|
|
|
+ : state.likerIds.filter(id => id !== this.appContainer.currentUserId),
|
|
|
|
|
+ }));
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ await this.retrieveLikersAndSeenUsers();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ async retrieveLikersAndSeenUsers() {
|
|
|
|
|
+ const { users } = await this.appContainer.apiGet('/users.list', { user_ids: [...this.state.likerIds, ...this.state.seenUserIds].join(',') });
|
|
|
|
|
|
|
|
- return this.retrieveLikeInfo();
|
|
|
|
|
|
|
+ await this.setState({
|
|
|
|
|
+ likers: users.filter(({ id }) => this.state.likerIds.includes(id)).slice(0, 15),
|
|
|
|
|
+ seenUsers: users.filter(({ id }) => this.state.seenUserIds.includes(id)).slice(0, 15),
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
|
|
+ this.checkAndUpdateImageUrlCached(users);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
async retrieveBookmarkInfo() {
|
|
async retrieveBookmarkInfo() {
|