fix: rename credentials and save credentials type

This commit is contained in:
Lei Nelissen
2024-07-25 23:16:20 +02:00
parent 98c64e30eb
commit 0bf8b7a6e0
11 changed files with 34 additions and 15 deletions

View File

@@ -38,7 +38,7 @@ const Logo = styled.Image`
function Onboarding() {
// Get account from Redux and dispatcher
const account = useTypedSelector(state => state.settings.jellyfin);
const account = useTypedSelector(state => state.settings.credentials);
const dispatch = useAppDispatch();
// Also retrieve the navigation handler so that we can open the modal in

View File

@@ -11,7 +11,7 @@ import { InputContainer, Input } from '../components/Input';
export default function LibrarySettings() {
const defaultStyles = useDefaultStyles();
const { jellyfin } = useTypedSelector(state => state.settings);
const { credentials } = useTypedSelector(state => state.settings);
const navigation = useNavigation<NavigationProp>();
const handleSetLibrary = useCallback(() => navigation.navigate('SetJellyfinServer'), [navigation]);
@@ -19,15 +19,15 @@ export default function LibrarySettings() {
<Container>
<InputContainer>
<Paragraph style={defaultStyles.text}>{t('jellyfin-server-url')}</Paragraph>
<Input placeholder="https://jellyfin.yourserver.com/" value={jellyfin?.uri} editable={false} style={defaultStyles.input} />
<Input placeholder="https://jellyfin.yourserver.com/" value={credentials?.uri} editable={false} style={defaultStyles.input} />
</InputContainer>
<InputContainer>
<Paragraph style={defaultStyles.text}>{t('jellyfin-access-token')}</Paragraph>
<Input placeholder="deadbeefdeadbeefdeadbeef" value={jellyfin?.access_token} editable={false} style={defaultStyles.input} />
<Input placeholder="deadbeefdeadbeefdeadbeef" value={credentials?.access_token} editable={false} style={defaultStyles.input} />
</InputContainer>
<InputContainer>
<Paragraph style={defaultStyles.text}>{t('jellyfin-user-id')}</Paragraph>
<Input placeholder="deadbeefdeadbeefdeadbeef" value={jellyfin?.user_id} editable={false} style={defaultStyles.input} />
<Input placeholder="deadbeefdeadbeefdeadbeef" value={credentials?.user_id} editable={false} style={defaultStyles.input} />
</InputContainer>
<Button title={t('set-jellyfin-server')} onPress={handleSetLibrary} />
</Container>

View File

@@ -5,7 +5,7 @@ import { AppState } from '@/store';
interface Props {
serverUrl: string;
onCredentialsRetrieved: (credentials: AppState['settings']['jellyfin']) => void;
onCredentialsRetrieved: (credentials: AppState['settings']['credentials']) => void;
}
type CredentialEventData = {
@@ -148,6 +148,7 @@ class CredentialGenerator extends Component<Props> {
user_id: userId,
access_token: accessToken,
device_id: deviceId,
type: data.type,
});
};

View File

@@ -22,7 +22,7 @@ export default function SetJellyfinServer() {
const navigation = useNavigation();
// Save creedentials to store and close the modal
const saveCredentials = useCallback((credentials: AppState['settings']['jellyfin']) => {
const saveCredentials = useCallback((credentials: AppState['settings']['credentials']) => {
if (credentials) {
dispatch(setJellyfinCredentials(credentials));
navigation.dispatch(StackActions.popToTop());

View File

@@ -64,6 +64,22 @@ const persistConfig: PersistConfig<Omit<AppState, '_persist'>> = {
}
};
},
// @ts-expect-error migrations are poorly typed
5: (state: AppState) => {
// @ts-expect-error
const credentials = state.settings.jellyfin && {
// @ts-expect-error
...(state.settings.jellyfin as AppState['settings']['credentials']),
type: 'jellyfin',
};
return {
...state,
settings: {
credentials,
},
};
}
})
};

View File

@@ -1,7 +1,7 @@
import { createAction } from '@reduxjs/toolkit';
import { ColorScheme } from './types';
export const setJellyfinCredentials = createAction<{ access_token: string, user_id: string, uri: string, device_id: string; }>('SET_JELLYFIN_CREDENTIALS');
export const setJellyfinCredentials = createAction<{ access_token: string, user_id: string, uri: string, device_id: string; type: 'jellyfin' | 'emby' }>('SET_JELLYFIN_CREDENTIALS');
export const setBitrate = createAction<number>('SET_BITRATE');
export const setOnboardingStatus = createAction<boolean>('SET_ONBOARDING_STATUS');
export const setReceivedErrorReportingAlert = createAction<void>('SET_RECEIVED_ERROR_REPORTING_ALERT');

View File

@@ -3,11 +3,12 @@ import { setReceivedErrorReportingAlert, setBitrate, setJellyfinCredentials, set
import { ColorScheme } from './types';
interface State {
jellyfin?: {
credentials?: {
uri: string;
user_id: string;
access_token: string;
device_id: string;
type: 'jellyfin' | 'emby';
}
bitrate: number;
isOnboardingComplete: boolean;
@@ -27,7 +28,7 @@ const initialState: State = {
const settings = createReducer(initialState, builder => {
builder.addCase(setJellyfinCredentials, (state, action) => ({
...state,
jellyfin: action.payload,
credentials: action.payload,
}));
builder.addCase(setBitrate, (state, action) => ({
...state,

View File

@@ -2,7 +2,7 @@ import type { AppState, Store } from '@/store';
import { Platform } from 'react-native';
import { version } from '../../../package.json';
type Credentials = AppState['settings']['jellyfin'];
type Credentials = AppState['settings']['credentials'];
/**
* This is a convenience function that converts a set of Jellyfin credentials
@@ -38,7 +38,7 @@ export async function fetchApi<T>(
parseResponse = true
) {
// Retrieve the latest credentials from the Redux store
const credentials = asyncFetchStore().getState().settings.jellyfin;
const credentials = asyncFetchStore().getState().settings.credentials;
// GUARD: Check that the credentials are present
if (!credentials) {
@@ -97,7 +97,7 @@ export async function fetchApi<T>(
* Retrieve an image URL for a given ItemId
*/
export function getImage(ItemId: string): string {
const credentials = asyncFetchStore().getState().settings.jellyfin;
const credentials = asyncFetchStore().getState().settings.credentials;
const uri = encodeURI(`${credentials?.uri}/Items/${ItemId}/Images/Primary?format=jpeg`);
return uri;
}

View File

@@ -48,6 +48,7 @@ export async function sendPlaybackEvent(
ItemId: activeTrack.backendId,
CanSeek: true,
PlaybackStartTimeTicks: null,
PlaySessionId: activeTrack?.backendId || 'fintunes',
};
// Generate a config from the credentials and dispatch the request

View File

@@ -27,7 +27,7 @@ export async function retrieveAllPlaylists() {
* Retrieve all albums that are available on the Jellyfin server
*/
export async function retrievePlaylistTracks(ItemId: string) {
const credentials = asyncFetchStore().getState().settings.jellyfin;
const credentials = asyncFetchStore().getState().settings.credentials;
const singlePlaylistOptions = {
SortBy: 'IndexNumber,SortName',
UserId: credentials?.user_id || '',

View File

@@ -30,7 +30,7 @@ const baseTrackOptions: Record<string, string> = {
* Generate the track streaming url from the trackId
*/
export function generateTrackUrl(trackId: string) {
const credentials = store.getState().settings.jellyfin;
const credentials = store.getState().settings.credentials;
const trackOptions = {
...baseTrackOptions,
UserId: credentials?.user_id || '',