perf(startup): instant splash, cached home and non-blocking auth
Continuous Integration / build_web (push) Failing after 0s
Continuous Integration / build (macos-latest) (push) Skipped
Continuous Integration / build (ubuntu-22.04) (push) Skipped
Continuous Integration / build (windows-11-arm) (push) Skipped
Continuous Integration / build (windows-latest) (push) Skipped
Continuous Integration / nightly_release (push) Skipped
Continuous Integration / build_web (push) Failing after 0s
Continuous Integration / build (macos-latest) (push) Skipped
Continuous Integration / build (ubuntu-22.04) (push) Skipped
Continuous Integration / build (windows-11-arm) (push) Skipped
Continuous Integration / build (windows-latest) (push) Skipped
Continuous Integration / nightly_release (push) Skipped
Renders a static branded splash immediately, restores the last user/API session from disk, hydrates home/library queries from localStorage, shows a home skeleton while the first request runs, drops blocking auth network checks, and redirects a streamless /player to home.
This commit is contained in:
1 parent
b1d9b40def
commit
205b655d00
12 files changed
+424
-158
No files matched your search
+24
-16
@@ -46,22 +46,30 @@ export const jellyfin = new Jellyfin({
|
||||
},
|
||||
});
|
||||
|
||||
export const initializeApi = async () => {
|
||||
const currentServerId = await getDefaultServer();
|
||||
if (currentServerId) {
|
||||
const currentServer = await getServer(currentServerId);
|
||||
if (currentServer?.address) {
|
||||
const userOnDisk = await getUser();
|
||||
if (userOnDisk) {
|
||||
return jellyfin.createApi(
|
||||
currentServer.address,
|
||||
userOnDisk.AccessToken,
|
||||
);
|
||||
}
|
||||
return jellyfin.createApi(currentServer.address);
|
||||
}
|
||||
}
|
||||
return undefined;
|
||||
export type InitialSession = {
|
||||
api?: Api;
|
||||
user?: { Name: string; AccessToken: string; Id: string } | null;
|
||||
};
|
||||
|
||||
/**
|
||||
* Restore the API and a minimal user snapshot from local storage in one pass.
|
||||
* The full UserDto is fetched in the background, so the UI can render without
|
||||
* waiting for the server.
|
||||
*/
|
||||
export const initializeApi = async (): Promise<InitialSession> => {
|
||||
const [currentServerId, userOnDisk] = await Promise.all([
|
||||
getDefaultServer(),
|
||||
getUser(),
|
||||
]);
|
||||
if (!currentServerId) return { user: userOnDisk };
|
||||
|
||||
const currentServer = await getServer(currentServerId);
|
||||
if (!currentServer?.address) return { user: userOnDisk };
|
||||
|
||||
return {
|
||||
api: jellyfin.createApi(currentServer.address, userOnDisk?.AccessToken),
|
||||
user: userOnDisk,
|
||||
};
|
||||
};
|
||||
|
||||
export const ApiContext = createContext<StoreApi<ApiStore>>(undefined!);
|
||||
|
||||
@@ -51,7 +51,13 @@ export const setAppReady = () => {
|
||||
|
||||
const CentralContext = createContext<StoreApi<CentralStore>>(null!);
|
||||
|
||||
export const CentralProvider = ({ children }: { children: ReactNode }) => {
|
||||
export const CentralProvider = ({
|
||||
children,
|
||||
initialUser,
|
||||
}: {
|
||||
children: ReactNode;
|
||||
initialUser?: UserDto | null;
|
||||
}) => {
|
||||
const [store] = useState(() =>
|
||||
createStore<CentralStore>()((set) => ({
|
||||
defaultServerOnDisk: async () => (await getDefaultServer()) ?? null,
|
||||
@@ -63,7 +69,7 @@ export const CentralProvider = ({ children }: { children: ReactNode }) => {
|
||||
allServersOnDisk: async () => await getAllServers(),
|
||||
userOnDisk: async () => (await getUser()) ?? null,
|
||||
clientVersion: version,
|
||||
currentUser: null,
|
||||
currentUser: initialUser ?? null,
|
||||
fetchCurrentUser: async (api) => {
|
||||
if (api?.accessToken) {
|
||||
const user = (await getUserApi(api).getCurrentUser()).data;
|
||||
|
||||
Reference in new issue
Block a user