From c5f549967be2b7e4564a60a13adeb472c48c4696 Mon Sep 17 00:00:00 2001
From: MerlinScheurer
Date: Sat, 15 Mar 2025 15:15:22 +0100
Subject: [PATCH] Refac use file_size_unit from user config in frontend #886
---
frontend/src/api/actions/updateUserConfig.ts | 6 +++
.../src/components/BiggestChannelsStats.tsx | 8 ++--
.../src/components/DownloadHistoryStats.tsx | 6 +--
frontend/src/components/OverviewStats.tsx | 10 ++---
frontend/src/components/VideoTypeStats.tsx | 10 ++---
frontend/src/pages/ChannelVideo.tsx | 4 +-
frontend/src/pages/SettingsDashboard.tsx | 28 ++++---------
frontend/src/pages/SettingsUser.tsx | 42 ++++++++++++++++++-
frontend/src/pages/Video.tsx | 8 +++-
frontend/src/stores/UserConfigStore.ts | 1 +
10 files changed, 83 insertions(+), 40 deletions(-)
diff --git a/frontend/src/api/actions/updateUserConfig.ts b/frontend/src/api/actions/updateUserConfig.ts
index 675d80d9..a4261034 100644
--- a/frontend/src/api/actions/updateUserConfig.ts
+++ b/frontend/src/api/actions/updateUserConfig.ts
@@ -3,6 +3,11 @@ import APIClient from '../../functions/APIClient';
export type ColourVariants = 'dark.css' | 'light.css' | 'matrix.css' | 'midnight.css';
+export const FileSizeUnits = {
+ Binary: 'binary',
+ Metric: 'metric',
+};
+
export type UserConfigType = {
stylesheet: ColourVariants;
page_size: number;
@@ -14,6 +19,7 @@ export type UserConfigType = {
view_style_playlist: ViewLayoutType;
grid_items: number;
hide_watched: boolean;
+ file_size_unit: 'binary' | 'metric';
show_ignored_only: boolean;
show_subed_only: boolean;
show_help_text: boolean;
diff --git a/frontend/src/components/BiggestChannelsStats.tsx b/frontend/src/components/BiggestChannelsStats.tsx
index 6358ede5..7ccf32f5 100644
--- a/frontend/src/components/BiggestChannelsStats.tsx
+++ b/frontend/src/components/BiggestChannelsStats.tsx
@@ -8,14 +8,14 @@ type BiggestChannelsStatsProps = {
biggestChannelsStatsByCount?: BiggestChannelsStatsType;
biggestChannelsStatsByDuration?: BiggestChannelsStatsType;
biggestChannelsStatsByMediaSize?: BiggestChannelsStatsType;
- useSI: boolean;
+ useSIUnits: boolean;
};
const BiggestChannelsStats = ({
biggestChannelsStatsByCount,
biggestChannelsStatsByDuration,
biggestChannelsStatsByMediaSize,
- useSI,
+ useSIUnits,
}: BiggestChannelsStatsProps) => {
if (
!biggestChannelsStatsByCount &&
@@ -94,7 +94,9 @@ const BiggestChannelsStats = ({
|
{name}
|
- {humanFileSize(media_size, useSI)} |
+
+ {humanFileSize(media_size, useSIUnits)}
+ |
);
})}
diff --git a/frontend/src/components/DownloadHistoryStats.tsx b/frontend/src/components/DownloadHistoryStats.tsx
index 935fa314..74d440df 100644
--- a/frontend/src/components/DownloadHistoryStats.tsx
+++ b/frontend/src/components/DownloadHistoryStats.tsx
@@ -5,10 +5,10 @@ import { DownloadHistoryStatsType } from '../pages/SettingsDashboard';
type DownloadHistoryStatsProps = {
downloadHistoryStats?: DownloadHistoryStatsType;
- useSI: boolean;
+ useSIUnits: boolean;
};
-const DownloadHistoryStats = ({ downloadHistoryStats, useSI }: DownloadHistoryStatsProps) => {
+const DownloadHistoryStats = ({ downloadHistoryStats, useSIUnits }: DownloadHistoryStatsProps) => {
if (!downloadHistoryStats) {
return Loading...
;
}
@@ -31,7 +31,7 @@ const DownloadHistoryStats = ({ downloadHistoryStats, useSI }: DownloadHistorySt
+{formatNumbers(count)} {videoText}
- {humanFileSize(media_size, useSI)}
+ {humanFileSize(media_size, useSIUnits)}
);
diff --git a/frontend/src/components/OverviewStats.tsx b/frontend/src/components/OverviewStats.tsx
index deced848..41b991ec 100644
--- a/frontend/src/components/OverviewStats.tsx
+++ b/frontend/src/components/OverviewStats.tsx
@@ -6,10 +6,10 @@ import { VideoStatsType } from '../pages/SettingsDashboard';
type OverviewStatsProps = {
videoStats?: VideoStatsType;
- useSI: boolean;
+ useSIUnits: boolean;
};
-const OverviewStats = ({ videoStats, useSI }: OverviewStatsProps) => {
+const OverviewStats = ({ videoStats, useSIUnits }: OverviewStatsProps) => {
if (!videoStats) {
return Loading...
;
}
@@ -19,7 +19,7 @@ const OverviewStats = ({ videoStats, useSI }: OverviewStatsProps) => {
title: 'All: ',
data: {
Videos: formatNumbers(videoStats?.doc_count || 0),
- ['Media Size']: humanFileSize(videoStats?.media_size || 0, useSI),
+ ['Media Size']: humanFileSize(videoStats?.media_size || 0, useSIUnits),
Duration: videoStats?.duration_str,
},
},
@@ -27,7 +27,7 @@ const OverviewStats = ({ videoStats, useSI }: OverviewStatsProps) => {
title: 'Active: ',
data: {
Videos: formatNumbers(videoStats?.active_true?.doc_count || 0),
- ['Media Size']: humanFileSize(videoStats?.active_true?.media_size || 0, useSI),
+ ['Media Size']: humanFileSize(videoStats?.active_true?.media_size || 0, useSIUnits),
Duration: videoStats?.active_true?.duration_str || 'NA',
},
},
@@ -35,7 +35,7 @@ const OverviewStats = ({ videoStats, useSI }: OverviewStatsProps) => {
title: 'Inactive: ',
data: {
Videos: formatNumbers(videoStats?.active_false?.doc_count || 0),
- ['Media Size']: humanFileSize(videoStats?.active_false?.media_size || 0, useSI),
+ ['Media Size']: humanFileSize(videoStats?.active_false?.media_size || 0, useSIUnits),
Duration: videoStats?.active_false?.duration_str || 'NA',
},
},
diff --git a/frontend/src/components/VideoTypeStats.tsx b/frontend/src/components/VideoTypeStats.tsx
index 1aacfecf..a63a1276 100644
--- a/frontend/src/components/VideoTypeStats.tsx
+++ b/frontend/src/components/VideoTypeStats.tsx
@@ -6,10 +6,10 @@ import { VideoStatsType } from '../pages/SettingsDashboard';
type VideoTypeStatsProps = {
videoStats?: VideoStatsType;
- useSI: boolean;
+ useSIUnits: boolean;
};
-const VideoTypeStats = ({ videoStats, useSI }: VideoTypeStatsProps) => {
+const VideoTypeStats = ({ videoStats, useSIUnits }: VideoTypeStatsProps) => {
if (!videoStats) {
return Loading...
;
}
@@ -19,7 +19,7 @@ const VideoTypeStats = ({ videoStats, useSI }: VideoTypeStatsProps) => {
title: 'Regular Videos: ',
data: {
Videos: formatNumbers(videoStats?.type_videos?.doc_count || 0),
- ['Media Size']: humanFileSize(videoStats?.type_videos?.media_size || 0, useSI),
+ ['Media Size']: humanFileSize(videoStats?.type_videos?.media_size || 0, useSIUnits),
Duration: videoStats?.type_videos?.duration_str || 'NA',
},
},
@@ -27,7 +27,7 @@ const VideoTypeStats = ({ videoStats, useSI }: VideoTypeStatsProps) => {
title: 'Shorts: ',
data: {
Videos: formatNumbers(videoStats?.type_shorts?.doc_count || 0),
- ['Media Size']: humanFileSize(videoStats?.type_shorts?.media_size || 0, useSI),
+ ['Media Size']: humanFileSize(videoStats?.type_shorts?.media_size || 0, useSIUnits),
Duration: videoStats?.type_shorts?.duration_str || 'NA',
},
},
@@ -35,7 +35,7 @@ const VideoTypeStats = ({ videoStats, useSI }: VideoTypeStatsProps) => {
title: 'Streams: ',
data: {
Videos: formatNumbers(videoStats?.type_streams?.doc_count || 0),
- ['Media Size']: humanFileSize(videoStats?.type_streams?.media_size || 0, useSI),
+ ['Media Size']: humanFileSize(videoStats?.type_streams?.media_size || 0, useSIUnits),
Duration: videoStats?.type_streams?.duration_str || 'NA',
},
},
diff --git a/frontend/src/pages/ChannelVideo.tsx b/frontend/src/pages/ChannelVideo.tsx
index 2533bebe..7a2cc5c4 100644
--- a/frontend/src/pages/ChannelVideo.tsx
+++ b/frontend/src/pages/ChannelVideo.tsx
@@ -20,6 +20,7 @@ import loadVideoListByFilter, {
import loadChannelAggs, { ChannelAggsType } from '../api/loader/loadChannelAggs';
import humanFileSize from '../functions/humanFileSize';
import { useUserConfigStore } from '../stores/UserConfigStore';
+import { FileSizeUnits } from '../api/actions/updateUserConfig';
type ChannelParams = {
channelId: string;
@@ -47,6 +48,7 @@ const ChannelVideo = ({ videoType }: ChannelVideoProps) => {
const pagination = videoResponse?.paginate;
const hasVideos = videoResponse?.data?.length !== 0;
+ const useSiUnits = userConfig.file_size_unit === FileSizeUnits.Metric;
const view = userConfig.view_style_home;
const isGridView = view === ViewStyles.grid;
@@ -114,7 +116,7 @@ const ChannelVideo = ({ videoType }: ChannelVideoProps) => {
|{' '}
{videoAggsResponse.total_duration.value_str} playback{' '}
| Total size{' '}
- {humanFileSize(videoAggsResponse.total_size.value, true)}
+ {humanFileSize(videoAggsResponse.total_size.value, useSiUnits)}
+
Archive view page size
@@ -113,18 +129,40 @@ const SettingsUser = () => {
+
+
+
+
+
+
+
+
{isAdmin && (
<>
diff --git a/frontend/src/pages/Video.tsx b/frontend/src/pages/Video.tsx
index 2d1d81fe..ba659e32 100644
--- a/frontend/src/pages/Video.tsx
+++ b/frontend/src/pages/Video.tsx
@@ -41,6 +41,8 @@ import ToggleConfig from '../components/ToggleConfig';
import { PlaylistType } from '../api/loader/loadPlaylistById';
import { useAppSettingsStore } from '../stores/AppSettingsStore';
import updateDownloadQueueStatusById from '../api/actions/updateDownloadQueueStatusById';
+import { FileSizeUnits } from '../api/actions/updateUserConfig';
+import { useUserConfigStore } from '../stores/UserConfigStore';
const isInPlaylist = (videoId: string, playlist: PlaylistType) => {
return playlist.playlist_entries.some(entry => {
@@ -112,6 +114,7 @@ const Video = () => {
const navigate = useNavigate();
const isAdmin = useIsAdmin();
const { appSettingsConfig } = useAppSettingsStore();
+ const { userConfig } = useUserConfigStore();
const [videoEnded, setVideoEnded] = useState(false);
const [playlistAutoplay, setPlaylistAutoplay] = useState(
@@ -199,6 +202,7 @@ const Video = () => {
const customPlaylists = customPlaylistsResponse?.data;
const starRating = convertStarRating(video?.stats?.average_rating);
const comments = commentsResponse;
+ const useSiUnits = userConfig.file_size_unit === FileSizeUnits.Metric;
console.log('playlistNav', playlistNav);
@@ -439,14 +443,14 @@ const Video = () => {
- {video.media_size &&
File size: {humanFileSize(video.media_size)}
}
+ {video.media_size &&
File size: {humanFileSize(video.media_size, useSiUnits)}
}
{video.streams &&
video.streams.map(stream => {
return (
{capitalizeFirstLetter(stream.type)}: {stream.codec}{' '}
- {humanFileSize(stream.bitrate)}/s
+ {humanFileSize(stream.bitrate, useSiUnits)}/s
{stream.width && (
<>
| {stream.width}x{stream.height}
diff --git a/frontend/src/stores/UserConfigStore.ts b/frontend/src/stores/UserConfigStore.ts
index 609f4b7b..20b2a417 100644
--- a/frontend/src/stores/UserConfigStore.ts
+++ b/frontend/src/stores/UserConfigStore.ts
@@ -18,6 +18,7 @@ export const useUserConfigStore = create(set => ({
view_style_playlist: 'grid',
grid_items: 3,
hide_watched: false,
+ file_size_unit: 'binary',
show_ignored_only: false,
show_subed_only: false,
show_help_text: true,