Skip to content
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

Store volume level on window object #2307

Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
"prefer-rest-params": 0,
"prettier/prettier": "error",
"quote-props": 0,
"unicorn/filename-case": 0
"unicorn/filename-case": 0,
"jsx-a11y/media-has-caption": 0
}
}
31 changes: 27 additions & 4 deletions src/shared/components/post/post-listing.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -128,10 +128,10 @@ export class PostListing extends Component<PostListingProps, PostListingState> {

componentDidMount(): void {
if (UserService.Instance.myUserInfo) {
const { auto_expand, blur_nsfw } = UserService.Instance.myUserInfo.local_user_view.local_user;
const { auto_expand, blur_nsfw } =
ismailkarsli marked this conversation as resolved.
Show resolved Hide resolved
UserService.Instance.myUserInfo.local_user_view.local_user;
this.setState({
imageExpanded:
auto_expand && !(blur_nsfw && this.postView.post.nsfw),
imageExpanded: auto_expand && !(blur_nsfw && this.postView.post.nsfw),
});
}
}
Expand Down Expand Up @@ -214,7 +214,15 @@ export class PostListing extends Component<PostListingProps, PostListingState> {
if (url && isVideo(url)) {
return (
<div className="embed-responsive ratio ratio-16x9 mt-3">
<video muted controls className="embed-responsive-item col-12">
<video
onLoadStart={linkEvent(this, this.handleVideoLoadStart)}
onPlay={linkEvent(this, this.handleVideoLoadStart)}
onMouseOver={linkEvent(this, this.handleVideoLoadStart)}
onFocus={linkEvent(this, this.handleVideoLoadStart)}
onVolumeChange={linkEvent(this, this.handleVideoVolumeChange)}
ismailkarsli marked this conversation as resolved.
Show resolved Hide resolved
controls
className="embed-responsive-item col-12"
>
<source src={url} type="video/mp4" />
</video>
</div>
Expand Down Expand Up @@ -766,6 +774,21 @@ export class PostListing extends Component<PostListingProps, PostListingState> {
this.setState({ showEdit: false });
}

handleVideoLoadStart(e) {
const video = e.target as HTMLVideoElement;
const volume = localStorage.getItem("volume_level");
if (volume) video.volume = Number(volume);
else {
video.volume = 0;
localStorage.setItem("volume_level", "0");
}
}

handleVideoVolumeChange(e) {
const video = e.target as HTMLVideoElement;
localStorage.setItem("volume_level", video.volume.toString());
}

ismailkarsli marked this conversation as resolved.
Show resolved Hide resolved
// The actual editing is done in the receive for post
handleEditPost(form: EditPost) {
this.setState({ showEdit: false });
Expand Down