Skip to content

Commit

Permalink
sonar suggestion
Browse files Browse the repository at this point in the history
  • Loading branch information
grafixeyehero committed Mar 8, 2023
1 parent 3e0129e commit 78e973f
Show file tree
Hide file tree
Showing 14 changed files with 1,721 additions and 490 deletions.
1,358 changes: 1,195 additions & 163 deletions package-lock.json

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions src/components/dashboard/users/UserLibraryAccessForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,14 @@ const UserLibraryAccessForm: FC<UserLibraryAccessFormProps> = ({
setClientUser,
onFormSubmit
}) => {
const { userId } = useParams();
const { id } = useParams();

const { data: mediaFolders } = useMediaFolders({ isHidden: false });
const { data: channels } = useChannels({
userId: userId
userId: id
});
const { data: devices } = useDevices({
userId: userId
userId: id
});

const onEnabledFoldersChange = useCallback(
Expand Down
266 changes: 186 additions & 80 deletions src/components/dashboard/users/UserPasswordForm.tsx

Large diffs are not rendered by default.

10 changes: 5 additions & 5 deletions src/components/dashboard/users/UserProfileForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -58,14 +58,14 @@ const UserProfileForm: FC<UserProfileFormProps> = ({
setClientUser,
onFormSubmit
}) => {
const { userId } = useParams();
const { id } = useParams();
const navigate = useNavigate();

const { data: authProviders } = useAuthProviders(userId);
const { data: passwordResetProviders } = usePasswordResetProviders(userId);
const { data: authProviders } = useAuthProviders(id);
const { data: passwordResetProviders } = usePasswordResetProviders(id);
const { data: mediaFolders } = useMediaFolders({ isHidden: false });
const { data: channels } = useChannels({
userId: userId,
userId: id,
supportsMediaDeletion: true
});
/*const { data: config } = useNamedConfiguration({
Expand Down Expand Up @@ -512,7 +512,7 @@ const UserProfileForm: FC<UserProfileFormProps> = ({
{getSyncPlayAccessOptions().map((option) => (
<MenuItem
key={option.value}
value={option.value as string}
value={option.value}
>
{option.label}
</MenuItem>
Expand Down
72 changes: 33 additions & 39 deletions src/hooks/useFetchItems.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query';
import { JellyfinApiContext, useApi } from './useApi';
import { ParametersOptions, Sections } from '../types/interface';

type ParentId = string | null | undefined;

const fetchItem = async (
currentApi: JellyfinApiContext,
itemId?: string | null
Expand Down Expand Up @@ -90,7 +92,7 @@ export const useItems = (parametersOptions: ItemsApiGetItemsRequest) => {
const fetchItemsByViewType = async (
currentApi: JellyfinApiContext,
viewType: string,
parentId: string | null | undefined,
parentId: ParentId,
parametersOptions: ParametersOptions
) => {
const { api, user } = currentApi;
Expand Down Expand Up @@ -146,7 +148,7 @@ const fetchItemsByViewType = async (

export const useViewItemsByType = (
viewType: string,
parentId: string | null | undefined,
parentId: ParentId,
parametersOptions: ParametersOptions
) => {
const currentApi = useApi();
Expand Down Expand Up @@ -188,7 +190,7 @@ export const useViewItemsByType = (

const fetchQueryFiltersLegacy = async (
currentApi: JellyfinApiContext,
parentId: string | null | undefined,
parentId: ParentId,
itemType: BaseItemKind[]
) => {
const { api, user } = currentApi;
Expand All @@ -203,7 +205,7 @@ const fetchQueryFiltersLegacy = async (
};

export const useQueryFiltersLegacy = (
parentId: string | null | undefined,
parentId: ParentId,
itemType: BaseItemKind[]
) => {
const currentApi = useApi();
Expand All @@ -216,7 +218,7 @@ export const useQueryFiltersLegacy = (

const fetchQueryFilters = async (
currentApi: JellyfinApiContext,
parentId: string | null | undefined
parentId: ParentId
) => {
const { api, user } = currentApi;
if (api && user?.Id) {
Expand All @@ -228,7 +230,7 @@ const fetchQueryFilters = async (
}
};

export const useQueryFilters = (parentId: string | null | undefined) => {
export const useQueryFilters = (parentId: ParentId) => {
const currentApi = useApi();
return useQuery({
queryKey: ['QueryFilters', parentId],
Expand All @@ -239,7 +241,7 @@ export const useQueryFilters = (parentId: string | null | undefined) => {

const fetchGenres = async (
currentApi: JellyfinApiContext,
parentId: string | null | undefined,
parentId: ParentId,
itemType: BaseItemKind[]
) => {
const { api, user } = currentApi;
Expand All @@ -257,7 +259,7 @@ const fetchGenres = async (
};

export const useGenres = (
parentId: string | null | undefined,
parentId: ParentId,
itemType: BaseItemKind[]
) => {
const currentApi = useApi();
Expand All @@ -270,7 +272,7 @@ export const useGenres = (

const fetchStudios = async (
currentApi: JellyfinApiContext,
parentId: string | null | undefined,
parentId: ParentId,
itemType: BaseItemKind[]
) => {
const { api, user } = currentApi;
Expand All @@ -291,7 +293,7 @@ const fetchStudios = async (
};

export const useStudios = (
parentId: string | null | undefined,
parentId: ParentId,
itemType: BaseItemKind[]
) => {
const currentApi = useApi();
Expand All @@ -304,7 +306,7 @@ export const useStudios = (

const fetchMovieRecommendations = async (
currentApi: JellyfinApiContext,
parentId: string | null | undefined
parentId: ParentId
) => {
const { api, user } = currentApi;
if (api && user?.Id) {
Expand All @@ -324,7 +326,7 @@ const fetchMovieRecommendations = async (
};

export const useMovieRecommendations = (
parentId: string | null | undefined
parentId: ParentId
) => {
const currentApi = useApi();
return useQuery({
Expand All @@ -336,7 +338,7 @@ export const useMovieRecommendations = (

const fetchUpcomingEpisodes = async (
currentApi: JellyfinApiContext,
parentId: string | null | undefined
parentId: ParentId
) => {
const { api, user } = currentApi;
if (api && user?.Id) {
Expand All @@ -356,7 +358,7 @@ const fetchUpcomingEpisodes = async (
}
};

export const useUpcomingEpisodes = (parentId: string | null | undefined) => {
export const useUpcomingEpisodes = (parentId: ParentId) => {
const currentApi = useApi();
return useQuery({
queryKey: ['UpcomingEpisodes', parentId],
Expand All @@ -368,7 +370,7 @@ export const useUpcomingEpisodes = (parentId: string | null | undefined) => {
const fetchItemsBySuggestionsType = async (
currentApi: JellyfinApiContext,
viewType: string | undefined,
parentId: string | null | undefined,
parentId: ParentId,
parametersOptions: ParametersOptions | undefined
) => {
const { api, user } = currentApi;
Expand Down Expand Up @@ -461,7 +463,7 @@ const fetchItemsBySuggestionsType = async (

export const useItemsBySectionType = (
sections: Sections,
parentId: string | null | undefined
parentId: ParentId
) => {
const currentApi = useApi();
return useQuery({
Expand All @@ -480,7 +482,7 @@ export const useItemsBySectionType = (
const fetchItemsByFavoriteType = async (
currentApi: JellyfinApiContext,
viewType: string | undefined,
parentId: string | null | undefined,
parentId: ParentId,
parametersOptions: ParametersOptions | undefined
) => {
const { api, user } = currentApi;
Expand Down Expand Up @@ -555,7 +557,7 @@ const fetchItemsByFavoriteType = async (

export const useItemsByFavoriteType = (
sections: Sections,
parentId: string | null | undefined
parentId: ParentId
) => {
const currentApi = useApi();
return useQuery({
Expand Down Expand Up @@ -594,30 +596,28 @@ export const useUsers = (parametersOptions?: UserApiGetUsersRequest) => {

const fetchUserById = async (
currentApi: JellyfinApiContext,
userId?: string | null
id?: string | null
) => {
const { api } = currentApi;
if (api && userId) {
if (api && id) {
const response = await getUserApi(api).getUserById({
userId: userId
userId: id
});
return response.data;
}
};

export const useUserById = (userId?: string | null) => {
export const useUserById = (id?: string | null) => {
const currentApi = useApi();
return useQuery({
queryKey: ['UserById', userId],
queryFn: () => fetchUserById(currentApi, userId),
enabled: Boolean(userId)
queryKey: ['UserById', id],
queryFn: () => fetchUserById(currentApi, id),
enabled: Boolean(id)
});
};

const fetchAuthProviders = async (
currentApi: JellyfinApiContext
//options: AxiosRequestConfig
//userId?: string | null
) => {
const { api } = currentApi;
if (api) {
Expand All @@ -626,19 +626,17 @@ const fetchAuthProviders = async (
}
};

export const useAuthProviders = (userId?: string | null) => {
export const useAuthProviders = (id?: string | null) => {
const currentApi = useApi();
return useQuery({
queryKey: ['AuthProviders', userId],
queryKey: ['AuthProviders', id],
queryFn: () => fetchAuthProviders(currentApi),
enabled: !!userId
enabled: !!id
});
};

const fetchPasswordResetProviders = async (
currentApi: JellyfinApiContext
//options: AxiosRequestConfig
//userId?: string | null
) => {
const { api } = currentApi;
if (api) {
Expand All @@ -647,19 +645,18 @@ const fetchPasswordResetProviders = async (
}
};

export const usePasswordResetProviders = (userId?: string | null) => {
export const usePasswordResetProviders = (id?: string | null) => {
const currentApi = useApi();
return useQuery({
queryKey: ['PasswordResetProviders', userId],
queryKey: ['PasswordResetProviders', id],
queryFn: () => fetchPasswordResetProviders(currentApi),
enabled: !!userId
enabled: !!id
});
};

const fetchMediaFolders = async (
currentApi: JellyfinApiContext,
parametersOptions: LibraryApiGetMediaFoldersRequest
//userId?: string | null
) => {
const { api } = currentApi;
if (api) {
Expand All @@ -677,14 +674,12 @@ export const useMediaFolders = (
return useQuery({
queryKey: ['MediaFolders', parametersOptions.isHidden],
queryFn: () => fetchMediaFolders(currentApi, parametersOptions)
//enabled: !!userId
});
};

const fetchChannels = async (
currentApi: JellyfinApiContext,
parametersOptions: ChannelsApiGetChannelsRequest
//userId?: string | null
) => {
const { api } = currentApi;
if (api) {
Expand All @@ -709,7 +704,6 @@ export const useChannels = (
const fetchDevices = async (
currentApi: JellyfinApiContext,
parametersOptions: DevicesApiGetDevicesRequest
//userId?: string | null
) => {
const { api } = currentApi;
if (api) {
Expand Down
2 changes: 1 addition & 1 deletion src/routes/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ const AppRoutes = () => (

<Route path='usernew.html' element={<UserNew />} />
<Route path='userprofiles.html' element={<UserProfiles />} />
<Route path='userprofile/:userId' element={<UserProfile />} >
<Route path='userprofile/:id' element={<UserProfile />} >
<Route path='libraryaccess' element={<UserLibraryAccess />} />
<Route path='parentalcontrol' element={<UserParentalControl />} />
<Route path='password' element={<UserPassword />} />
Expand Down
1 change: 1 addition & 0 deletions src/routes/movies/SuggestionsView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ const SuggestionsView: FC<LibraryViewProps> = ({ topParentId }) => {
movieRecommendationsItems.map((recommendation, index) => {
return (
<RecommendationContainer
// Todo add a uniqe key id here
// eslint-disable-next-line react/no-array-index-key
key={index}
recommendation={recommendation}
Expand Down
2 changes: 1 addition & 1 deletion src/routes/user/myprofile.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ const MyProfile: FC = () => {
</div>
</div>
<UserPasswordForm
userId={userId}
id={userId}
/>
</div>
</Page>
Expand Down
12 changes: 6 additions & 6 deletions src/routes/user/useredit.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ import UserProfileForm from '../../components/dashboard/users/UserProfileForm';
import { Link } from '@mui/material';

const UserEdit: FC = () => {
const { userId } = useParams();
const { isLoading, data: serverUser } = useUserById(userId);
const { id } = useParams();
const { isLoading, data: serverUser } = useUserById(id);
const updateUser = useUpdateUser();
const updateUserPolicy = useUpdateUserPolicy();

Expand All @@ -34,7 +34,7 @@ const UserEdit: FC = () => {

updateUser.mutate(
{
userId: userId || '',
userId: id || '',
userDto: {
...clientUser,
Name: clientUser?.Name
Expand All @@ -44,7 +44,7 @@ const UserEdit: FC = () => {
onSuccess: async () => {
updateUserPolicy.mutate(
{
userId: userId || '',
userId: id || '',
userPolicy: {
...clientUser?.Policy,
RemoteClientBitrateLimit: Math.floor(1e6 * (clientUser?.Policy?.RemoteClientBitrateLimit || 0)),
Expand All @@ -64,7 +64,7 @@ const UserEdit: FC = () => {
}
);
},
[clientUser, updateUser, updateUserPolicy, userId]
[clientUser, updateUser, updateUserPolicy, id]
);

useEffect(() => {
Expand All @@ -82,7 +82,7 @@ const UserEdit: FC = () => {
>
<Link
className='lnkEditUserPreferences button-link'
href={`#/mypreferencesmenu.html?userId=${userId}`}
href={`#/mypreferencesmenu.html?userId=${id}`}
underline='hover'
>
{globalize.translate('ButtonEditOtherUserPreferences')}
Expand Down
Loading

0 comments on commit 78e973f

Please sign in to comment.