Skip to content

Commit

Permalink
Add toggle to show read posts in communities (#719)
Browse files Browse the repository at this point in the history
Co-authored-by: Sean Griffin <sgriffin6697@gmail.com>
  • Loading branch information
ktgd and sgriff96 authored Jul 20, 2023
1 parent a8c4d60 commit 8438773
Show file tree
Hide file tree
Showing 9 changed files with 84 additions and 44 deletions.
2 changes: 1 addition & 1 deletion Stack.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ function SettingsScreens(stack) {
name="ReadSettings"
component={ReadSettingsScreen}
options={{
title: t("Mark Post Read On"),
title: t("Hide Read Posts"),
}}
/>
<stack.Screen
Expand Down
37 changes: 2 additions & 35 deletions src/components/screens/Settings/Content/ContentScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,7 @@ function ContentScreen({
return (
<ScrollView backgroundColor={theme.colors.app.bg} flex={1}>
<TableView style={styles.table}>
<CSection
header={t("Posts")}
footer={t("settings.content.markRead.footer")}
>
<CSection header={t("Posts")}>
{/* <CCell */}
{/* title="Swipe Gestures" */}
{/* backgroundColor={theme.colors.app.fg} */}
Expand Down Expand Up @@ -101,43 +98,13 @@ function ContentScreen({
/>
</ListingTypeContextMenu>
<CCell
title={t("Mark Post Read On")}
title={t("Hide Read Posts")}
backgroundColor={theme.colors.app.fg}
titleTextColor={theme.colors.app.textPrimary}
rightDetailColor={theme.colors.app.textSecondary}
accessory="DisclosureIndicator"
onPress={() => navigation.push("ReadSettings")}
/>
<CCell
cellStyle="RightDetail"
title={t("Hide Read Posts on Feed")}
backgroundColor={theme.colors.app.fg}
titleTextColor={theme.colors.app.textPrimary}
rightDetailColor={theme.colors.app.textSecondary}
cellAccessoryView={
<Switch
value={settings.hideReadPostsOnFeed}
onValueChange={(v) => {
onChange("hideReadPostsOnFeed", v);
}}
/>
}
/>
<CCell
cellStyle="RightDetail"
title={t("Show Hide Read Button")}
backgroundColor={theme.colors.app.fg}
titleTextColor={theme.colors.app.textPrimary}
rightDetailColor={theme.colors.app.textSecondary}
cellAccessoryView={
<Switch
value={settings.showHideReadButton}
onValueChange={(v) => {
onChange("showHideReadButton", v);
}}
/>
}
/>
</CSection>

<CSection header={t("Comments")}>
Expand Down
46 changes: 46 additions & 0 deletions src/components/screens/Settings/Content/ReadSettingsScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,52 @@ function ReadSettingsScreen() {
return (
<VStack backgroundColor={theme.colors.app.bg}>
<CTable>
<CSection footer={t("settings.content.markRead.footer")}>
<CCell
cellStyle="RightDetail"
title={t("Hide Read Posts on Feed")}
backgroundColor={theme.colors.app.fg}
titleTextColor={theme.colors.app.textPrimary}
rightDetailColor={theme.colors.app.textSecondary}
cellAccessoryView={
<Switch
value={settings.hideReadPostsOnFeed}
onValueChange={(v) => {
onChange("hideReadPostsOnFeed", v);
}}
/>
}
/>
<CCell
cellStyle="RightDetail"
title={`${t("Hide Read Posts in Communities")}`}
backgroundColor={theme.colors.app.fg}
titleTextColor={theme.colors.app.textPrimary}
rightDetailColor={theme.colors.app.textSecondary}
cellAccessoryView={
<Switch
value={settings.hideReadPostsInCommunities}
onValueChange={(v) => onChange("hideReadPostsInCommunities", v)}
/>
}
/>
<CCell
cellStyle="RightDetail"
title={t("Show Hide Read Button")}
backgroundColor={theme.colors.app.fg}
titleTextColor={theme.colors.app.textPrimary}
rightDetailColor={theme.colors.app.textSecondary}
cellAccessoryView={
<Switch
value={settings.showHideReadButton}
onValueChange={(v) => {
onChange("showHideReadButton", v);
}}
/>
}
/>
</CSection>

<CSection header={t("settings.content.markRead.header")}>
<CCell
cellStyle="RightDetail"
Expand Down
2 changes: 1 addition & 1 deletion src/hooks/feeds/useCommunityFeed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ const useCommunityFeed = (communityFullName: string): UseCommunityFeed => {
const lastPost = useRef<number>(0);

// Hooks
const feed = useFeed(communityFullName);
const feed = useFeed(communityFullName, true);

// Other hooks
const { t } = useTranslation();
Expand Down
23 changes: 19 additions & 4 deletions src/hooks/feeds/useFeed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,18 @@ export interface UseFeed {
setLoaded: React.Dispatch<SetStateAction<any>>;
}

export const useFeed = (communityIdOrName?: number | string): UseFeed => {
export const useFeed = (
communityIdOrName?: number | string,
isCommunity = false
): UseFeed => {
// Global State
const { defaultSort, defaultListingType, hideNsfw, hideReadPostsOnFeed } =
useAppSelector(selectSettings);
const {
defaultSort,
defaultListingType,
hideNsfw,
hideReadPostsOnFeed,
hideReadPostsInCommunities,
} = useAppSelector(selectSettings);
const { updateVote, updateSaved } = useAppSelector(selectFeed);

// State
Expand Down Expand Up @@ -181,8 +189,15 @@ export const useFeed = (communityIdOrName?: number | string): UseFeed => {
return;
}

// Filter posts
let newPosts = hideNsfw ? removeNsfwPosts(res.posts) : res.posts;
newPosts = hideReadPostsOnFeed ? removeReadPosts(res.posts) : res.posts;

if (
(hideReadPostsOnFeed && !isCommunity) ||
(hideReadPostsInCommunities && isCommunity)
) {
newPosts = removeReadPosts(res.posts);
}

preloadImages(newPosts);

Expand Down
6 changes: 5 additions & 1 deletion src/plugins/i18n/locales/cz.json
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,8 @@
"header": "NASTAVENÍ OZNAČOVANÍ JAKO PŘEČTENO",
"onPostOpen": "Označit Příspěvky Jako Přečteny Při Otevření Příspěvku",
"onImageView": "Označit Příspěvky Jako Přečteny Při Otevření Obrázku.",
"onVote": "Označit Příspěvky Jako Přečteny Při Hlasování."
"onVote": "Označit Příspěvky Jako Přečteny Při Hlasování.",
"footer": "Hide Read Posts on Feed will automatically hide read posts anytime the feed is refreshed. If Hide Read Posts on Feed is enabled, Show Hide Read Button will show a floating action button to hide read posts without a feed refresh."
}
},
"appearance": {
Expand Down Expand Up @@ -287,6 +288,8 @@
"Add Account": "Přidat Účet",
"Create Account": "Vytvořit Účet",
"Mark Post Read On": "Označit Příspěvek jako přečtený...",
"Hide Read Posts": "Hide Read Posts",
"Show Hide Read Button": "Show Hide Read Button",
"View": "Zobrazit",
"Content": "Obsah",
"Appearance": "Vzhled",
Expand Down Expand Up @@ -317,6 +320,7 @@
"Default Sort": "Výchozí Řazení",
"Default Comment Sort": "Výchozí Řazení Komentářů",
"Hide Read Posts on Feed": "Schovat Přečtené Příspěvky na Feedu",
"Hide Read Posts in Communities": "Hide Read Posts in Communities",
"Show Comment Actions": "Zobrazit Akce ke Komentáři",
"NSFW": "NSFW",
"NSFW Content": "NSFW Obsah",
Expand Down
6 changes: 5 additions & 1 deletion src/plugins/i18n/locales/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,8 @@
"header": "Gelesen Markieren Einstellungen",
"onPostOpen": "Beim öffnen vom Post",
"onImageView": "Beim ansehen vom Bild",
"onVote": "Beim Abstimmen"
"onVote": "Beim Abstimmen",
"footer": "Hide Read Posts on Feed will automatically hide read posts anytime the feed is refreshed. If Hide Read Posts on Feed is enabled, Show Hide Read Button will show a floating action button to hide read posts without a feed refresh."
}
},
"appearance": {
Expand Down Expand Up @@ -274,6 +275,8 @@
"Add Account": "Account hinzufügen",
"Create Account": "Account erstellen",
"Mark Post Read On": "Post als gelesen markieren...",
"Hide Read Posts": "Hide Read Posts",
"Show Hide Read Button": "Show Hide Read Button",
"View": "Anzeigen",
"Content": "Inhalt",
"Appearance": "Darstellung",
Expand Down Expand Up @@ -305,6 +308,7 @@
"Default Comment Sort": "Standard Kommentar Sortierung",
"Default Listing Type": "Standard Listen Typ",
"Hide Read Posts on Feed": "Gelesene Posts im Feed ausblenden",
"Hide Read Posts in Communities": "Hide Read Posts in Communities",
"Show Comment Actions": "Kommentar anzeigen Aktionen",
"NSFW": "NSFW",
"NSFW Content": "NSFW Inhalt",
Expand Down
4 changes: 3 additions & 1 deletion src/plugins/i18n/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@
},
"markRead": {
"header": "MARK READ SETTINGS",
"onPostOpen": "Mark Read on Post open",
"onPostOpen": "Mark Read on Post Open",
"onImageView": "Mark Read on Image View",
"onVote": "Mark Read on Vote",
"footer": "Hide Read Posts on Feed will automatically hide read posts anytime the feed is refreshed. If Hide Read Posts on Feed is enabled, Show Hide Read Button will show a floating action button to hide read posts without a feed refresh."
Expand Down Expand Up @@ -288,6 +288,7 @@
"Add Account": "Add Account",
"Create Account": "Create Account",
"Mark Post Read On": "Mark Post Read...",
"Hide Read Posts": "Hide Read Posts",
"View": "View",
"Content": "Content",
"Appearance": "Appearance",
Expand Down Expand Up @@ -318,6 +319,7 @@
"Default Sort": "Default Sort",
"Default Comment Sort": "Default Comment Sort",
"Hide Read Posts on Feed": "Hide Read Posts on Feed",
"Hide Read Posts in Communities": "Hide Read Posts in Communities",
"Show Hide Read Button": "Show Hide Read Button",
"Show Comment Actions": "Show Comment Actions",
"NSFW": "NSFW",
Expand Down
2 changes: 2 additions & 0 deletions src/slices/settings/settingsSlice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ export interface SettingsState {
useReaderMode: boolean;
accentColor?: string;
hideReadPostsOnFeed: boolean;
hideReadPostsInCommunities: boolean;
showHideReadButton: boolean;
appIcon: string;
showCommentActions: boolean;
Expand Down Expand Up @@ -73,6 +74,7 @@ const initialState: SettingsState = {
displayTotalScore: true,
useReaderMode: false,
hideReadPostsOnFeed: false,
hideReadPostsInCommunities: false,
showHideReadButton: false,
appIcon: "purple",
showCommentActions: true,
Expand Down

0 comments on commit 8438773

Please sign in to comment.