Skip to content
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

Mark post as read when clicking "Expand here" on the preview image on the post listing page (#1600) #1978

Merged
merged 4 commits into from
Aug 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/shared/components/community/community.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ import {
LockPost,
MarkCommentReplyAsRead,
MarkPersonMentionAsRead,
MarkPostAsRead,
PostResponse,
PurgeComment,
PurgeCommunity,
Expand Down Expand Up @@ -195,6 +196,7 @@ export class Community extends Component<
this.handleSavePost = this.handleSavePost.bind(this);
this.handlePurgePost = this.handlePurgePost.bind(this);
this.handleFeaturePost = this.handleFeaturePost.bind(this);
this.handleMarkPostAsRead = this.handleMarkPostAsRead.bind(this);
this.mainContentRef = createRef();
// Only fetch the data if coming from another route
if (FirstLoadService.isFirstLoad) {
Expand Down Expand Up @@ -431,6 +433,7 @@ export class Community extends Component<
onAddAdmin={this.handleAddAdmin}
onTransferCommunity={this.handleTransferCommunity}
onFeaturePost={this.handleFeaturePost}
onMarkPostAsRead={this.handleMarkPostAsRead}
/>
);
}
Expand Down Expand Up @@ -801,6 +804,11 @@ export class Community extends Component<
await HttpService.client.markPersonMentionAsRead(form);
}

async handleMarkPostAsRead(form: MarkPostAsRead) {
const res = await HttpService.client.markPostAsRead(form);
this.findAndUpdatePost(res);
}

async handleBanFromCommunity(form: BanFromCommunity) {
const banRes = await HttpService.client.banFromCommunity(form);
this.updateBanFromCommunity(banRes);
Expand Down
8 changes: 8 additions & 0 deletions src/shared/components/home/home.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ import {
LockPost,
MarkCommentReplyAsRead,
MarkPersonMentionAsRead,
MarkPostAsRead,
PostResponse,
PurgeComment,
PurgeItemResponse,
Expand Down Expand Up @@ -268,6 +269,7 @@ export class Home extends Component<any, HomeState> {
this.handleSavePost = this.handleSavePost.bind(this);
this.handlePurgePost = this.handlePurgePost.bind(this);
this.handleFeaturePost = this.handleFeaturePost.bind(this);
this.handleMarkPostAsRead = this.handleMarkPostAsRead.bind(this);

// Only fetch the data if coming from another route
if (FirstLoadService.isFirstLoad) {
Expand Down Expand Up @@ -698,6 +700,7 @@ export class Home extends Component<any, HomeState> {
onAddAdmin={this.handleAddAdmin}
onTransferCommunity={this.handleTransferCommunity}
onFeaturePost={this.handleFeaturePost}
onMarkPostAsRead={this.handleMarkPostAsRead}
/>
);
}
Expand Down Expand Up @@ -1025,6 +1028,11 @@ export class Home extends Component<any, HomeState> {
this.updateBan(banRes);
}

async handleMarkPostAsRead(form: MarkPostAsRead) {
const res = await HttpService.client.markPostAsRead(form);
this.findAndUpdatePost(res);
}

updateBanFromCommunity(banRes: RequestState<BanFromCommunityResponse>) {
// Maybe not necessary
if (banRes.state === "success") {
Expand Down
4 changes: 4 additions & 0 deletions src/shared/components/person/person-details.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import {
LockPost,
MarkCommentReplyAsRead,
MarkPersonMentionAsRead,
MarkPostAsRead,
PersonView,
PostView,
PurgeComment,
Expand Down Expand Up @@ -84,6 +85,7 @@ interface PersonDetailsProps {
onSavePost(form: SavePost): void;
onFeaturePost(form: FeaturePost): void;
onPurgePost(form: PurgePost): void;
onMarkPostAsRead(form: MarkPostAsRead): void;
}

enum ItemEnum {
Expand Down Expand Up @@ -200,6 +202,7 @@ export class PersonDetails extends Component<PersonDetailsProps, any> {
onAddModToCommunity={this.props.onAddModToCommunity}
onAddAdmin={this.props.onAddAdmin}
onTransferCommunity={this.props.onTransferCommunity}
onMarkPostAsRead={this.props.onMarkPostAsRead}
/>
);
}
Expand Down Expand Up @@ -311,6 +314,7 @@ export class PersonDetails extends Component<PersonDetailsProps, any> {
onAddModToCommunity={this.props.onAddModToCommunity}
onAddAdmin={this.props.onAddAdmin}
onTransferCommunity={this.props.onTransferCommunity}
onMarkPostAsRead={this.props.onMarkPostAsRead}
/>
<hr className="my-3" />
</>
Expand Down
8 changes: 8 additions & 0 deletions src/shared/components/person/profile.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ import {
LockPost,
MarkCommentReplyAsRead,
MarkPersonMentionAsRead,
MarkPostAsRead,
PersonView,
PostResponse,
PurgeComment,
Expand Down Expand Up @@ -208,6 +209,7 @@ export class Profile extends Component<
this.handlePurgePost = this.handlePurgePost.bind(this);
this.handleFeaturePost = this.handleFeaturePost.bind(this);
this.handleModBanSubmit = this.handleModBanSubmit.bind(this);
this.handleMarkPostAsRead = this.handleMarkPostAsRead.bind(this);

// Only fetch the data if coming from another route
if (FirstLoadService.isFirstLoad) {
Expand Down Expand Up @@ -376,6 +378,7 @@ export class Profile extends Component<
onSavePost={this.handleSavePost}
onPurgePost={this.handlePurgePost}
onFeaturePost={this.handleFeaturePost}
onMarkPostAsRead={this.handleMarkPostAsRead}
/>
</div>

Expand Down Expand Up @@ -944,6 +947,11 @@ export class Profile extends Component<
await HttpService.client.markPersonMentionAsRead(form);
}

async handleMarkPostAsRead(form: MarkPostAsRead) {
const res = await HttpService.client.markPostAsRead(form);
this.findAndUpdatePost(res);
}

async handleBanFromCommunity(form: BanFromCommunity) {
const banRes = await HttpService.client.banFromCommunity(form);
this.updateBanFromCommunity(banRes);
Expand Down
2 changes: 2 additions & 0 deletions src/shared/components/post/post-form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -447,6 +447,7 @@ export class PostForm extends Component<PostFormProps, PostFormState> {
onAddModToCommunity={() => {}}
onAddAdmin={() => {}}
onTransferCommunity={() => {}}
onMarkPostAsRead={() => {}}
/>
</>
)}
Expand Down Expand Up @@ -641,6 +642,7 @@ export class PostForm extends Component<PostFormProps, PostFormState> {
onAddModToCommunity={() => {}}
onAddAdmin={() => {}}
onTransferCommunity={() => {}}
onMarkPostAsRead={() => {}}
/>
</>
)
Expand Down
13 changes: 12 additions & 1 deletion src/shared/components/post/post-listing.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { myAuthRequired } from "@utils/app";
import { myAuth, myAuthRequired } from "@utils/app";
import { canShare, share } from "@utils/browser";
import { getExternalHost, getHttpBase } from "@utils/env";
import {
Expand Down Expand Up @@ -34,6 +34,7 @@ import {
FeaturePost,
Language,
LockPost,
MarkPostAsRead,
PersonView,
PostView,
PurgePerson,
Expand Down Expand Up @@ -130,6 +131,7 @@ interface PostListingProps {
onAddModToCommunity(form: AddModToCommunity): void;
onAddAdmin(form: AddAdmin): void;
onTransferCommunity(form: TransferCommunity): void;
onMarkPostAsRead(form: MarkPostAsRead): void;
}

export class PostListing extends Component<PostListingProps, PostListingState> {
Expand Down Expand Up @@ -1723,6 +1725,15 @@ export class PostListing extends Component<PostListingProps, PostListingState> {
event.preventDefault();
i.setState({ imageExpanded: !i.state.imageExpanded });
setupTippy();

const auth = myAuth();
if (auth && !i.props.post_view.read) {
i.props.onMarkPostAsRead({
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice, thanks for catching this one.

post_id: i.props.post_view.post.id,
read: true,
auth: auth,
});
}
}

handleViewSource(i: PostListing) {
Expand Down
3 changes: 3 additions & 0 deletions src/shared/components/post/post-listings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
FeaturePost,
Language,
LockPost,
MarkPostAsRead,
PostView,
PurgePerson,
PurgePost,
Expand Down Expand Up @@ -49,6 +50,7 @@ interface PostListingsProps {
onAddModToCommunity(form: AddModToCommunity): void;
onAddAdmin(form: AddAdmin): void;
onTransferCommunity(form: TransferCommunity): void;
onMarkPostAsRead(form: MarkPostAsRead): void;
}

export class PostListings extends Component<PostListingsProps, any> {
Expand Down Expand Up @@ -95,6 +97,7 @@ export class PostListings extends Component<PostListingsProps, any> {
onAddModToCommunity={this.props.onAddModToCommunity}
onAddAdmin={this.props.onAddAdmin}
onTransferCommunity={this.props.onTransferCommunity}
onMarkPostAsRead={this.props.onMarkPostAsRead}
/>
{idx + 1 !== this.posts.length && <hr className="my-3" />}
</>
Expand Down
1 change: 1 addition & 0 deletions src/shared/components/post/post-report.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ export class PostReport extends Component<PostReportProps, PostReportState> {
onAddModToCommunity={() => {}}
onAddAdmin={() => {}}
onTransferCommunity={() => {}}
onMarkPostAsRead={() => {}}
/>
<div>
{I18NextService.i18n.t("reporter")}:{" "}
Expand Down
8 changes: 8 additions & 0 deletions src/shared/components/post/post.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ import {
LockPost,
MarkCommentReplyAsRead,
MarkPersonMentionAsRead,
MarkPostAsRead,
PostResponse,
PurgeComment,
PurgeCommunity,
Expand Down Expand Up @@ -171,6 +172,7 @@ export class Post extends Component<any, PostState> {
this.handleSavePost = this.handleSavePost.bind(this);
this.handlePurgePost = this.handlePurgePost.bind(this);
this.handleFeaturePost = this.handleFeaturePost.bind(this);
this.handleMarkPostAsRead = this.handleMarkPostAsRead.bind(this);

this.state = { ...this.state, commentSectionRef: createRef() };

Expand Down Expand Up @@ -384,6 +386,7 @@ export class Post extends Component<any, PostState> {
onAddAdmin={this.handleAddAdmin}
onTransferCommunity={this.handleTransferCommunity}
onFeaturePost={this.handleFeaturePost}
onMarkPostAsRead={this.handleMarkPostAsRead}
/>
<div ref={this.state.commentSectionRef} className="mb-2" />
<CommentForm
Expand Down Expand Up @@ -917,6 +920,11 @@ export class Post extends Component<any, PostState> {
await HttpService.client.markPersonMentionAsRead(form);
}

async handleMarkPostAsRead(form: MarkPostAsRead) {
const res = await HttpService.client.markPostAsRead(form);
this.updatePost(res);
}

async handleBanFromCommunity(form: BanFromCommunity) {
const banRes = await HttpService.client.banFromCommunity(form);
this.updateBan(banRes);
Expand Down
2 changes: 2 additions & 0 deletions src/shared/components/search.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -706,6 +706,7 @@ export class Search extends Component<any, SearchState> {
onAddModToCommunity={() => {}}
onAddAdmin={() => {}}
onTransferCommunity={() => {}}
onMarkPostAsRead={() => {}}
/>
)}
{i.type_ === "comments" && (
Expand Down Expand Up @@ -856,6 +857,7 @@ export class Search extends Component<any, SearchState> {
onAddModToCommunity={() => {}}
onAddAdmin={() => {}}
onTransferCommunity={() => {}}
onMarkPostAsRead={() => {}}
/>
</div>
</div>
Expand Down