Skip to content

Commit

Permalink
feat: setting to hide accessible captions (#1792)
Browse files Browse the repository at this point in the history
  • Loading branch information
aeharding authored Dec 23, 2024
1 parent 7b3c388 commit c5a1df6
Show file tree
Hide file tree
Showing 7 changed files with 72 additions and 3 deletions.
6 changes: 5 additions & 1 deletion src/features/media/gallery/actions/AltText.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { useState } from "react";

import { cx } from "#/helpers/css";
import { useAppSelector } from "#/store";

import styles from "./AltText.module.css";

Expand All @@ -9,9 +10,12 @@ interface AltTextProps {
}

export default function AltText({ alt }: AltTextProps) {
const hideAltText = useAppSelector(
(state) => state.settings.general.media.hideAltText,
);
const [shouldClampAltText, setShouldClampAltText] = useState(true);

if (!alt) return;
if (!alt || hideAltText) return;

return (
<div className={cx("alt-text", styles.container)}>
Expand Down
9 changes: 7 additions & 2 deletions src/features/media/gallery/actions/ImageMoreActions.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { isNative } from "#/helpers/device";
import { useAppSelector } from "#/store";

import AltText from "./AltText";
import GalleryActions from "./GalleryActions";
Expand All @@ -15,17 +16,21 @@ export default function ImageMoreActions({
imgSrc,
alt,
}: ImageMoreActionsProps) {
const hideAltText = useAppSelector(
(state) => state.settings.general.media.hideAltText,
);

return (
<>
{isNative() && (
<div className={styles.topContainer}>
<GalleryActions imgSrc={imgSrc} />
</div>
)}
{alt && (
{alt && !hideAltText && (
<BottomContainer>
<AltText alt={alt} />
<BottomContainerActions withBg={!!alt} />
<BottomContainerActions withBg />
</BottomContainer>
)}
</>
Expand Down
2 changes: 2 additions & 0 deletions src/features/settings/general/GeneralSettings.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import Comments from "./comments/Comments";
import Media from "./media/Media";
import Other from "./other/Other";
import Posts from "./posts/Posts";
import Safari from "./safari/Safari";
Expand All @@ -9,6 +10,7 @@ export default function GeneralSettings() {
<Posts />
<Comments />
<Safari />
<Media />
<Other />
</>
);
Expand Down
23 changes: 23 additions & 0 deletions src/features/settings/general/media/HideAltText.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 { setHideAltText } from "../../settingsSlice";

export default function HideAltText() {
const dispatch = useAppDispatch();
const hideAltText = useAppSelector(
(state) => state.settings.general.media.hideAltText,
);

return (
<IonItem>
<IonToggle
checked={hideAltText}
onIonChange={(e) => dispatch(setHideAltText(e.detail.checked))}
>
Hide Accessible Captions
</IonToggle>
</IonItem>
);
}
19 changes: 19 additions & 0 deletions src/features/settings/general/media/Media.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { IonLabel } from "@ionic/react";
import { IonList } from "@ionic/react";

import { ListHeader } from "#/features/settings/shared/formatting";

import HideAltText from "./HideAltText";

export default function Media() {
return (
<>
<ListHeader>
<IonLabel>Media</IonLabel>
</ListHeader>
<IonList inset>
<HideAltText />
</IonList>
</>
);
}
14 changes: 14 additions & 0 deletions src/features/settings/settingsSlice.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,9 @@ export interface SettingsState {
safari: {
alwaysUseReaderMode: boolean;
};
media: {
hideAltText: boolean;
};
enableHapticFeedback: boolean;
linkHandler: LinkHandlerType;
preferNativeApps: boolean;
Expand Down Expand Up @@ -233,6 +236,9 @@ const baseState: SettingsState = {
defaultFeed: undefined,
enableHapticFeedback: true,
linkHandler: OLinkHandlerType.InApp,
media: {
hideAltText: false,
},
noSubscribedInFeed: false,
posts: {
autoHideRead: false,
Expand Down Expand Up @@ -387,6 +393,10 @@ export const settingsSlice = createSlice({
state.appearance.font.fontSizeMultiplier = action.payload;
set(LOCALSTORAGE_KEYS.FONT.FONT_SIZE_MULTIPLIER, action.payload);
},
setHideAltText(state, action: PayloadAction<boolean>) {
state.general.media.hideAltText = action.payload;
db.setSetting("hide_alt_text", action.payload);
},
setHighlightNewAccount(state, action: PayloadAction<boolean>) {
state.general.comments.highlightNewAccount = action.payload;
db.setSetting("highlight_new_account", action.payload);
Expand Down Expand Up @@ -769,6 +779,7 @@ export const {
setFilteredKeywords,
setFilteredWebsites,
setFontSizeMultiplier,
setHideAltText,
setHighlightNewAccount,
setInfiniteScrolling,
setJumpButtonPosition,
Expand Down Expand Up @@ -878,6 +889,9 @@ function hydrateStateWithGlobalSettings(
},
enableHapticFeedback: settings.enable_haptic_feedback,
linkHandler: settings.link_handler,
media: {
hideAltText: settings.hide_alt_text,
},
noSubscribedInFeed: settings.no_subscribed_in_feed,
posts: {
autoHideRead: settings.auto_hide_read,
Expand Down
2 changes: 2 additions & 0 deletions src/services/db.ts
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,7 @@ export interface GlobalSettingValueTypes {
enable_haptic_feedback: boolean;
filtered_keywords: string[];
filtered_websites: string[];
hide_alt_text: boolean;
highlight_new_account: boolean;
infinite_scrolling: boolean;
jump_button_position: JumpButtonPositionType;
Expand Down Expand Up @@ -456,6 +457,7 @@ export const ALL_GLOBAL_SETTINGS = arrayOfAll<keyof GlobalSettingValueTypes>()([
"user_instance_url_display",
"vote_display_mode",
"votes_theme",
"hide_alt_text",
]);

export interface ISettingItem<T extends keyof SettingValueTypes> {
Expand Down

0 comments on commit c5a1df6

Please sign in to comment.