* Mark post as read when clicking "Expand here" on the preview image on the post listing page (#1600)
* Simplified check for mark post as read
* Implemented mark post as read as a property callback instead of directly using HttpService
---------
Co-authored-by: SleeplessOne1917 <abias1122@gmail.com>
LockPost,
MarkCommentReplyAsRead,
MarkPersonMentionAsRead,
+ MarkPostAsRead,
PostResponse,
PurgeComment,
PurgeCommunity,
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) {
onAddAdmin={this.handleAddAdmin}
onTransferCommunity={this.handleTransferCommunity}
onFeaturePost={this.handleFeaturePost}
+ onMarkPostAsRead={this.handleMarkPostAsRead}
/>
);
}
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);
LockPost,
MarkCommentReplyAsRead,
MarkPersonMentionAsRead,
+ MarkPostAsRead,
PostResponse,
PurgeComment,
PurgeItemResponse,
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) {
onAddAdmin={this.handleAddAdmin}
onTransferCommunity={this.handleTransferCommunity}
onFeaturePost={this.handleFeaturePost}
+ onMarkPostAsRead={this.handleMarkPostAsRead}
/>
);
}
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") {
LockPost,
MarkCommentReplyAsRead,
MarkPersonMentionAsRead,
+ MarkPostAsRead,
PersonView,
PostView,
PurgeComment,
onSavePost(form: SavePost): void;
onFeaturePost(form: FeaturePost): void;
onPurgePost(form: PurgePost): void;
+ onMarkPostAsRead(form: MarkPostAsRead): void;
}
enum ItemEnum {
onAddModToCommunity={this.props.onAddModToCommunity}
onAddAdmin={this.props.onAddAdmin}
onTransferCommunity={this.props.onTransferCommunity}
+ onMarkPostAsRead={this.props.onMarkPostAsRead}
/>
);
}
onAddModToCommunity={this.props.onAddModToCommunity}
onAddAdmin={this.props.onAddAdmin}
onTransferCommunity={this.props.onTransferCommunity}
+ onMarkPostAsRead={this.props.onMarkPostAsRead}
/>
<hr className="my-3" />
</>
LockPost,
MarkCommentReplyAsRead,
MarkPersonMentionAsRead,
+ MarkPostAsRead,
PersonView,
PostResponse,
PurgeComment,
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) {
onSavePost={this.handleSavePost}
onPurgePost={this.handlePurgePost}
onFeaturePost={this.handleFeaturePost}
+ onMarkPostAsRead={this.handleMarkPostAsRead}
/>
</div>
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);
onAddModToCommunity={() => {}}
onAddAdmin={() => {}}
onTransferCommunity={() => {}}
+ onMarkPostAsRead={() => {}}
/>
</>
)}
onAddModToCommunity={() => {}}
onAddAdmin={() => {}}
onTransferCommunity={() => {}}
+ onMarkPostAsRead={() => {}}
/>
</>
)
-import { myAuthRequired } from "@utils/app";
+import { myAuth, myAuthRequired } from "@utils/app";
import { canShare, share } from "@utils/browser";
import { getExternalHost, getHttpBase } from "@utils/env";
import {
FeaturePost,
Language,
LockPost,
+ MarkPostAsRead,
PersonView,
PostView,
PurgePerson,
onAddModToCommunity(form: AddModToCommunity): void;
onAddAdmin(form: AddAdmin): void;
onTransferCommunity(form: TransferCommunity): void;
+ onMarkPostAsRead(form: MarkPostAsRead): void;
}
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({
+ post_id: i.props.post_view.post.id,
+ read: true,
+ auth: auth,
+ });
+ }
}
handleViewSource(i: PostListing) {
FeaturePost,
Language,
LockPost,
+ MarkPostAsRead,
PostView,
PurgePerson,
PurgePost,
onAddModToCommunity(form: AddModToCommunity): void;
onAddAdmin(form: AddAdmin): void;
onTransferCommunity(form: TransferCommunity): void;
+ onMarkPostAsRead(form: MarkPostAsRead): void;
}
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" />}
</>
onAddModToCommunity={() => {}}
onAddAdmin={() => {}}
onTransferCommunity={() => {}}
+ onMarkPostAsRead={() => {}}
/>
<div>
{I18NextService.i18n.t("reporter")}:{" "}
LockPost,
MarkCommentReplyAsRead,
MarkPersonMentionAsRead,
+ MarkPostAsRead,
PostResponse,
PurgeComment,
PurgeCommunity,
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() };
onAddAdmin={this.handleAddAdmin}
onTransferCommunity={this.handleTransferCommunity}
onFeaturePost={this.handleFeaturePost}
+ onMarkPostAsRead={this.handleMarkPostAsRead}
/>
<div ref={this.state.commentSectionRef} className="mb-2" />
<CommentForm
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);
onAddModToCommunity={() => {}}
onAddAdmin={() => {}}
onTransferCommunity={() => {}}
+ onMarkPostAsRead={() => {}}
/>
)}
{i.type_ === "comments" && (
onAddModToCommunity={() => {}}
onAddAdmin={() => {}}
onTransferCommunity={() => {}}
+ onMarkPostAsRead={() => {}}
/>
</div>
</div>