fix: rename credentials and save credentials type
This commit is contained in:
@@ -38,7 +38,7 @@ const Logo = styled.Image`
|
|||||||
|
|
||||||
function Onboarding() {
|
function Onboarding() {
|
||||||
// Get account from Redux and dispatcher
|
// Get account from Redux and dispatcher
|
||||||
const account = useTypedSelector(state => state.settings.jellyfin);
|
const account = useTypedSelector(state => state.settings.credentials);
|
||||||
const dispatch = useAppDispatch();
|
const dispatch = useAppDispatch();
|
||||||
|
|
||||||
// Also retrieve the navigation handler so that we can open the modal in
|
// Also retrieve the navigation handler so that we can open the modal in
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ import { InputContainer, Input } from '../components/Input';
|
|||||||
|
|
||||||
export default function LibrarySettings() {
|
export default function LibrarySettings() {
|
||||||
const defaultStyles = useDefaultStyles();
|
const defaultStyles = useDefaultStyles();
|
||||||
const { jellyfin } = useTypedSelector(state => state.settings);
|
const { credentials } = useTypedSelector(state => state.settings);
|
||||||
const navigation = useNavigation<NavigationProp>();
|
const navigation = useNavigation<NavigationProp>();
|
||||||
const handleSetLibrary = useCallback(() => navigation.navigate('SetJellyfinServer'), [navigation]);
|
const handleSetLibrary = useCallback(() => navigation.navigate('SetJellyfinServer'), [navigation]);
|
||||||
|
|
||||||
@@ -19,15 +19,15 @@ export default function LibrarySettings() {
|
|||||||
<Container>
|
<Container>
|
||||||
<InputContainer>
|
<InputContainer>
|
||||||
<Paragraph style={defaultStyles.text}>{t('jellyfin-server-url')}</Paragraph>
|
<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>
|
||||||
<InputContainer>
|
<InputContainer>
|
||||||
<Paragraph style={defaultStyles.text}>{t('jellyfin-access-token')}</Paragraph>
|
<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>
|
||||||
<InputContainer>
|
<InputContainer>
|
||||||
<Paragraph style={defaultStyles.text}>{t('jellyfin-user-id')}</Paragraph>
|
<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>
|
</InputContainer>
|
||||||
<Button title={t('set-jellyfin-server')} onPress={handleSetLibrary} />
|
<Button title={t('set-jellyfin-server')} onPress={handleSetLibrary} />
|
||||||
</Container>
|
</Container>
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ import { AppState } from '@/store';
|
|||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
serverUrl: string;
|
serverUrl: string;
|
||||||
onCredentialsRetrieved: (credentials: AppState['settings']['jellyfin']) => void;
|
onCredentialsRetrieved: (credentials: AppState['settings']['credentials']) => void;
|
||||||
}
|
}
|
||||||
|
|
||||||
type CredentialEventData = {
|
type CredentialEventData = {
|
||||||
@@ -148,6 +148,7 @@ class CredentialGenerator extends Component<Props> {
|
|||||||
user_id: userId,
|
user_id: userId,
|
||||||
access_token: accessToken,
|
access_token: accessToken,
|
||||||
device_id: deviceId,
|
device_id: deviceId,
|
||||||
|
type: data.type,
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ export default function SetJellyfinServer() {
|
|||||||
const navigation = useNavigation();
|
const navigation = useNavigation();
|
||||||
|
|
||||||
// Save creedentials to store and close the modal
|
// Save creedentials to store and close the modal
|
||||||
const saveCredentials = useCallback((credentials: AppState['settings']['jellyfin']) => {
|
const saveCredentials = useCallback((credentials: AppState['settings']['credentials']) => {
|
||||||
if (credentials) {
|
if (credentials) {
|
||||||
dispatch(setJellyfinCredentials(credentials));
|
dispatch(setJellyfinCredentials(credentials));
|
||||||
navigation.dispatch(StackActions.popToTop());
|
navigation.dispatch(StackActions.popToTop());
|
||||||
|
|||||||
@@ -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,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
}
|
||||||
})
|
})
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import { createAction } from '@reduxjs/toolkit';
|
import { createAction } from '@reduxjs/toolkit';
|
||||||
import { ColorScheme } from './types';
|
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 setBitrate = createAction<number>('SET_BITRATE');
|
||||||
export const setOnboardingStatus = createAction<boolean>('SET_ONBOARDING_STATUS');
|
export const setOnboardingStatus = createAction<boolean>('SET_ONBOARDING_STATUS');
|
||||||
export const setReceivedErrorReportingAlert = createAction<void>('SET_RECEIVED_ERROR_REPORTING_ALERT');
|
export const setReceivedErrorReportingAlert = createAction<void>('SET_RECEIVED_ERROR_REPORTING_ALERT');
|
||||||
|
|||||||
@@ -3,11 +3,12 @@ import { setReceivedErrorReportingAlert, setBitrate, setJellyfinCredentials, set
|
|||||||
import { ColorScheme } from './types';
|
import { ColorScheme } from './types';
|
||||||
|
|
||||||
interface State {
|
interface State {
|
||||||
jellyfin?: {
|
credentials?: {
|
||||||
uri: string;
|
uri: string;
|
||||||
user_id: string;
|
user_id: string;
|
||||||
access_token: string;
|
access_token: string;
|
||||||
device_id: string;
|
device_id: string;
|
||||||
|
type: 'jellyfin' | 'emby';
|
||||||
}
|
}
|
||||||
bitrate: number;
|
bitrate: number;
|
||||||
isOnboardingComplete: boolean;
|
isOnboardingComplete: boolean;
|
||||||
@@ -27,7 +28,7 @@ const initialState: State = {
|
|||||||
const settings = createReducer(initialState, builder => {
|
const settings = createReducer(initialState, builder => {
|
||||||
builder.addCase(setJellyfinCredentials, (state, action) => ({
|
builder.addCase(setJellyfinCredentials, (state, action) => ({
|
||||||
...state,
|
...state,
|
||||||
jellyfin: action.payload,
|
credentials: action.payload,
|
||||||
}));
|
}));
|
||||||
builder.addCase(setBitrate, (state, action) => ({
|
builder.addCase(setBitrate, (state, action) => ({
|
||||||
...state,
|
...state,
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ import type { AppState, Store } from '@/store';
|
|||||||
import { Platform } from 'react-native';
|
import { Platform } from 'react-native';
|
||||||
import { version } from '../../../package.json';
|
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
|
* This is a convenience function that converts a set of Jellyfin credentials
|
||||||
@@ -38,7 +38,7 @@ export async function fetchApi<T>(
|
|||||||
parseResponse = true
|
parseResponse = true
|
||||||
) {
|
) {
|
||||||
// Retrieve the latest credentials from the Redux store
|
// 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
|
// GUARD: Check that the credentials are present
|
||||||
if (!credentials) {
|
if (!credentials) {
|
||||||
@@ -97,7 +97,7 @@ export async function fetchApi<T>(
|
|||||||
* Retrieve an image URL for a given ItemId
|
* Retrieve an image URL for a given ItemId
|
||||||
*/
|
*/
|
||||||
export function getImage(ItemId: string): string {
|
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`);
|
const uri = encodeURI(`${credentials?.uri}/Items/${ItemId}/Images/Primary?format=jpeg`);
|
||||||
return uri;
|
return uri;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -48,6 +48,7 @@ export async function sendPlaybackEvent(
|
|||||||
ItemId: activeTrack.backendId,
|
ItemId: activeTrack.backendId,
|
||||||
CanSeek: true,
|
CanSeek: true,
|
||||||
PlaybackStartTimeTicks: null,
|
PlaybackStartTimeTicks: null,
|
||||||
|
PlaySessionId: activeTrack?.backendId || 'fintunes',
|
||||||
};
|
};
|
||||||
|
|
||||||
// Generate a config from the credentials and dispatch the request
|
// Generate a config from the credentials and dispatch the request
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ export async function retrieveAllPlaylists() {
|
|||||||
* Retrieve all albums that are available on the Jellyfin server
|
* Retrieve all albums that are available on the Jellyfin server
|
||||||
*/
|
*/
|
||||||
export async function retrievePlaylistTracks(ItemId: string) {
|
export async function retrievePlaylistTracks(ItemId: string) {
|
||||||
const credentials = asyncFetchStore().getState().settings.jellyfin;
|
const credentials = asyncFetchStore().getState().settings.credentials;
|
||||||
const singlePlaylistOptions = {
|
const singlePlaylistOptions = {
|
||||||
SortBy: 'IndexNumber,SortName',
|
SortBy: 'IndexNumber,SortName',
|
||||||
UserId: credentials?.user_id || '',
|
UserId: credentials?.user_id || '',
|
||||||
|
|||||||
@@ -30,7 +30,7 @@ const baseTrackOptions: Record<string, string> = {
|
|||||||
* Generate the track streaming url from the trackId
|
* Generate the track streaming url from the trackId
|
||||||
*/
|
*/
|
||||||
export function generateTrackUrl(trackId: string) {
|
export function generateTrackUrl(trackId: string) {
|
||||||
const credentials = store.getState().settings.jellyfin;
|
const credentials = store.getState().settings.credentials;
|
||||||
const trackOptions = {
|
const trackOptions = {
|
||||||
...baseTrackOptions,
|
...baseTrackOptions,
|
||||||
UserId: credentials?.user_id || '',
|
UserId: credentials?.user_id || '',
|
||||||
|
|||||||
Reference in New Issue
Block a user