Skip to content

Commit

Permalink
feat: never show read setting (#1816)
Browse files Browse the repository at this point in the history
  • Loading branch information
aeharding authored Jan 20, 2025
1 parent b97d28b commit c2b9fe9
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 5 deletions.
18 changes: 13 additions & 5 deletions src/features/feed/PostCommentFeed.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,9 @@ export default function PostCommentFeed({
const markReadOnScroll = useAppSelector(
(state) => state.settings.general.posts.markReadOnScroll,
);
const neverShowReadPosts = useAppSelector(
(state) => state.settings.general.posts.neverShowReadPosts,
);
const autohidePostIfNeeded = useAutohidePostIfNeeded();

const itemsRef = useRef<PostCommentItem[]>();
Expand Down Expand Up @@ -179,18 +182,23 @@ export default function PostCommentFeed({
const filterOnRxFn = useCallback(
(item: PostCommentItem) => {
const postHidden = postHiddenById[item.post.id];
if (filterHiddenPosts && postHidden?.hidden) return false;
if (isPost(item)) {
if (filterHiddenPosts && postHidden?.hidden) return false;

// Filter removed from community/special feed pages for mods
if (filterHiddenPosts && item.post.removed) {
return false;
// Ignore neverShowReadPosts on hidden posts page (and profile, etc)
if (filterHiddenPosts && neverShowReadPosts && item.read) return false;

// Filter removed from community/special feed pages for mods
if (filterHiddenPosts && item.post.removed) {
return false;
}
}

if (_filterOnRxFn) return _filterOnRxFn(item);

return true;
},
[filterHiddenPosts, postHiddenById, _filterOnRxFn],
[filterHiddenPosts, postHiddenById, _filterOnRxFn, neverShowReadPosts],
);

const getIndex = useCallback(
Expand Down
2 changes: 2 additions & 0 deletions src/features/settings/general/hiding/HidingSettings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import AutoHideRead from "./autoHide/AutoHideRead";
import DisableInCommunities from "./autoHide/DisableInCommunities";
import DisableMarkingRead from "./DisableMarkingRead";
import MarkReadOnScroll from "./MarkReadOnScroll";
import NeverShowReadPosts from "./NeverShowReadPosts";
import ShowHiddenInCommunities from "./ShowHiddenInCommunities";
import ShowHideReadButton from "./ShowHideReadButton";

Expand All @@ -24,6 +25,7 @@ export default function HidingSettings() {
<MarkReadOnScroll />
<ShowHideReadButton />
<ShowHiddenInCommunities />
<NeverShowReadPosts />
</>
)}
</IonList>
Expand Down
23 changes: 23 additions & 0 deletions src/features/settings/general/hiding/NeverShowReadPosts.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { IonItem, IonToggle } from "@ionic/react";

import { useAppDispatch, useAppSelector } from "#/store";

import { setNeverShowReadPosts } from "../../settingsSlice";

export default function NeverShowReadPosts() {
const dispatch = useAppDispatch();
const neverShowReadPosts = useAppSelector(
(state) => state.settings.general.posts.neverShowReadPosts,
);

return (
<IonItem>
<IonToggle
checked={neverShowReadPosts}
onIonChange={(e) => dispatch(setNeverShowReadPosts(e.detail.checked))}
>
Never Show Previously Read
</IonToggle>
</IonItem>
);
}
9 changes: 9 additions & 0 deletions src/features/settings/settingsSlice.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ export interface SettingsState {
markReadOnScroll: boolean;
showHideReadButton: boolean;
showHiddenInCommunities: boolean;
neverShowReadPosts: boolean;
autoHideRead: boolean;
disableAutoHideInCommunities: boolean;
infiniteScrolling: boolean;
Expand Down Expand Up @@ -249,6 +250,7 @@ const baseState: SettingsState = {
disableMarkingRead: false,
infiniteScrolling: true,
markReadOnScroll: false,
neverShowReadPosts: false,
rememberCommunitySort: false,
showHiddenInCommunities: false,
showHideReadButton: false,
Expand Down Expand Up @@ -429,6 +431,11 @@ export const settingsSlice = createSlice({

db.setSetting("mark_read_on_scroll", action.payload);
},
setNeverShowReadPosts(state, action: PayloadAction<boolean>) {
state.general.posts.neverShowReadPosts = action.payload;

db.setSetting("never_show_read_posts", action.payload);
},
setNoSubscribedInFeed(state, action: PayloadAction<boolean>) {
state.general.noSubscribedInFeed = action.payload;
db.setSetting("no_subscribed_in_feed", action.payload);
Expand Down Expand Up @@ -792,6 +799,7 @@ export const {
setLargeShowVotingButtons,
setLinkHandler,
setMarkPostsReadOnScroll,
setNeverShowReadPosts,
setNoSubscribedInFeed,
setNsfwBlur,
setPostAppearance,
Expand Down Expand Up @@ -908,6 +916,7 @@ function hydrateStateWithGlobalSettings(
disableMarkingRead: settings.disable_marking_posts_read,
infiniteScrolling: settings.infinite_scrolling,
markReadOnScroll: settings.mark_read_on_scroll,
neverShowReadPosts: settings.never_show_read_posts,
rememberCommunitySort: settings.remember_community_post_sort,
showHiddenInCommunities: settings.show_hidden_in_communities,
showHideReadButton: settings.show_hide_read_button,
Expand Down
2 changes: 2 additions & 0 deletions src/services/db.ts
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,7 @@ export interface GlobalSettingValueTypes {
large_show_voting_buttons: boolean;
link_handler: LinkHandlerType;
mark_read_on_scroll: boolean;
never_show_read_posts: boolean;
no_subscribed_in_feed: boolean;
post_appearance_type: PostAppearanceType;
prefer_native_apps: boolean;
Expand Down Expand Up @@ -457,6 +458,7 @@ export const ALL_GLOBAL_SETTINGS = arrayOfAll<keyof GlobalSettingValueTypes>()([
"upvote_on_save",
"user_instance_url_display",
"vote_display_mode",
"never_show_read_posts",
"votes_theme",
"hide_alt_text",
"show_controls_on_open",
Expand Down

0 comments on commit c2b9fe9

Please sign in to comment.