Skip to content

Add ability to hide images after clicking "show image" #29467

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

Merged
merged 25 commits into from
Mar 18, 2025

Conversation

Half-Shot
Copy link
Member

@Half-Shot Half-Shot commented Mar 11, 2025

This adds a simple button to rehide images that may have accidentally been unhidden. This applies regardless of your preview settings, so can be used to hide images that would show by default too.

This comes with a few changes to make this possible, notably:

  • The preference to preview a given eventId is moved from a localStorage to SettingsStore to allow us to watch / read / write to the value from another component.
  • Migrates the above to the new setting.
  • There is now a Hide action in the message action bar.

This PR still needs product review and tests.

image
image

Checklist

  • Tests written for new code (and old code if feasible).
  • New or updated public/exported symbols have accurate TSDoc documentation.
  • Linter and other CI checks pass.
  • I have licensed the changes to Element by completing the Contributor License Agreement (CLA)

@Half-Shot Half-Shot marked this pull request as ready for review March 11, 2025 15:15
@Half-Shot Half-Shot requested a review from a team as a code owner March 11, 2025 15:15
@florianduros
Copy link
Member

florianduros commented Mar 12, 2025

Shouldn't we wait for product approval before doing the review?

@Half-Shot Half-Shot mentioned this pull request Mar 14, 2025
4 tasks
@@ -105,11 +105,6 @@ export default class MFileBody extends React.Component<IProps, IState> {
declare public context: React.ContextType<typeof RoomContext>;

public state: IState = {};

public static defaultProps = {
Copy link
Member Author

@Half-Shot Half-Shot Mar 17, 2025

Choose a reason for hiding this comment

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

Default props would expect showGenericPlaceholder?: boolean would cause the signature of MFIleBody to expect a parameter for showGenericPlaceholder, oddly. This breaks 60eeb8a, and rather than leave a bunch of type assertions all over the place, I'll just remove defaultProps.

Since this is a single case, it was easier to just default it in the render function.

@@ -686,3 +685,10 @@ export class HiddenImagePlaceholder extends React.PureComponent<PlaceholderIProp
);
}
}

const MImageBody: React.FC<IBodyProps> = (props) => {
Copy link
Member Author

@Half-Shot Half-Shot Mar 17, 2025

Choose a reason for hiding this comment

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

This needs a wrapper to use the hook. I decided to defer on rewriting MImageBody in this PR, as it's already kinda huge.

return <MImageBodyInner mediaVisible={mediaVisible} setMediaVisible={setVisible} {...props} />;
};

export default MImageBody;
Copy link
Member Author

Choose a reason for hiding this comment

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

Keeping the same export pattern as the previous class.

@@ -45,8 +45,8 @@ import { type GetRelationsForEvent, type IEventTileOps } from "../rooms/EventTil
// onMessageAllowed is handled internally
interface IProps extends Omit<IBodyProps, "onMessageAllowed" | "mediaEventHelper"> {
/* overrides for the msgtype-specific components, used by ReplyTile to override file rendering */
overrideBodyTypes?: Record<string, typeof React.Component>;
overrideEventTypes?: Record<string, typeof React.Component>;
overrideBodyTypes?: Record<string, React.ComponentType<IBodyProps>>;
Copy link
Member Author

Choose a reason for hiding this comment

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

ComponentType allows for both functional and class components.

@Half-Shot Half-Shot added this pull request to the merge queue Mar 18, 2025
Merged via the queue into develop with commit e662c19 Mar 18, 2025
34 checks passed
@Half-Shot Half-Shot deleted the hs/add-hide-image-button branch March 18, 2025 15:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants