update grpc
This commit is contained in:
@@ -1,4 +1,6 @@
|
||||
import { client, type PreferencesSettingsPreferencesRequest } from '@/api/client';
|
||||
import { client as rpcClient } from '@/api/rpcclient';
|
||||
import type { Preferences } from '@/server/gen/proto/app/v1/common';
|
||||
import type { UpdatePreferencesRequest } from '@/server/gen/proto/app/v1/account';
|
||||
import { useQuery } from '@pinia/colada';
|
||||
|
||||
export const SETTINGS_PREFERENCES_QUERY_KEY = ['settings', 'preferences'] as const;
|
||||
@@ -36,9 +38,7 @@ export type PlayerSettingsDraft = {
|
||||
};
|
||||
|
||||
type PreferencesResponse = {
|
||||
data?: {
|
||||
preferences?: PreferencesSettingsPreferencesRequest;
|
||||
};
|
||||
preferences?: Preferences;
|
||||
};
|
||||
|
||||
const DEFAULT_SETTINGS_PREFERENCES_SNAPSHOT: SettingsPreferencesSnapshot = {
|
||||
@@ -56,17 +56,17 @@ const DEFAULT_SETTINGS_PREFERENCES_SNAPSHOT: SettingsPreferencesSnapshot = {
|
||||
};
|
||||
|
||||
const normalizePreferencesSnapshot = (responseData: unknown): SettingsPreferencesSnapshot => {
|
||||
const preferences = (responseData as PreferencesResponse | undefined)?.data?.preferences;
|
||||
const preferences = (responseData as PreferencesResponse | undefined)?.preferences;
|
||||
|
||||
return {
|
||||
emailNotifications: preferences?.email_notifications ?? DEFAULT_SETTINGS_PREFERENCES_SNAPSHOT.emailNotifications,
|
||||
pushNotifications: preferences?.push_notifications ?? DEFAULT_SETTINGS_PREFERENCES_SNAPSHOT.pushNotifications,
|
||||
marketingNotifications: preferences?.marketing_notifications ?? DEFAULT_SETTINGS_PREFERENCES_SNAPSHOT.marketingNotifications,
|
||||
telegramNotifications: preferences?.telegram_notifications ?? DEFAULT_SETTINGS_PREFERENCES_SNAPSHOT.telegramNotifications,
|
||||
emailNotifications: preferences?.emailNotifications ?? DEFAULT_SETTINGS_PREFERENCES_SNAPSHOT.emailNotifications,
|
||||
pushNotifications: preferences?.pushNotifications ?? DEFAULT_SETTINGS_PREFERENCES_SNAPSHOT.pushNotifications,
|
||||
marketingNotifications: preferences?.marketingNotifications ?? DEFAULT_SETTINGS_PREFERENCES_SNAPSHOT.marketingNotifications,
|
||||
telegramNotifications: preferences?.telegramNotifications ?? DEFAULT_SETTINGS_PREFERENCES_SNAPSHOT.telegramNotifications,
|
||||
autoplay: preferences?.autoplay ?? DEFAULT_SETTINGS_PREFERENCES_SNAPSHOT.autoplay,
|
||||
loop: preferences?.loop ?? DEFAULT_SETTINGS_PREFERENCES_SNAPSHOT.loop,
|
||||
muted: preferences?.muted ?? DEFAULT_SETTINGS_PREFERENCES_SNAPSHOT.muted,
|
||||
showControls: preferences?.show_controls ?? DEFAULT_SETTINGS_PREFERENCES_SNAPSHOT.showControls,
|
||||
showControls: preferences?.showControls ?? DEFAULT_SETTINGS_PREFERENCES_SNAPSHOT.showControls,
|
||||
pip: preferences?.pip ?? DEFAULT_SETTINGS_PREFERENCES_SNAPSHOT.pip,
|
||||
airplay: preferences?.airplay ?? DEFAULT_SETTINGS_PREFERENCES_SNAPSHOT.airplay,
|
||||
chromecast: preferences?.chromecast ?? DEFAULT_SETTINGS_PREFERENCES_SNAPSHOT.chromecast,
|
||||
@@ -97,20 +97,20 @@ export const createPlayerSettingsDraft = (
|
||||
|
||||
export const toNotificationPreferencesPayload = (
|
||||
draft: NotificationSettingsDraft,
|
||||
): PreferencesSettingsPreferencesRequest => ({
|
||||
email_notifications: draft.email,
|
||||
push_notifications: draft.push,
|
||||
marketing_notifications: draft.marketing,
|
||||
telegram_notifications: draft.telegram,
|
||||
): UpdatePreferencesRequest => ({
|
||||
emailNotifications: draft.email,
|
||||
pushNotifications: draft.push,
|
||||
marketingNotifications: draft.marketing,
|
||||
telegramNotifications: draft.telegram,
|
||||
});
|
||||
|
||||
export const toPlayerPreferencesPayload = (
|
||||
draft: PlayerSettingsDraft,
|
||||
): PreferencesSettingsPreferencesRequest => ({
|
||||
): UpdatePreferencesRequest => ({
|
||||
autoplay: draft.autoplay,
|
||||
loop: draft.loop,
|
||||
muted: draft.muted,
|
||||
show_controls: draft.showControls,
|
||||
showControls: draft.showControls,
|
||||
pip: draft.pip,
|
||||
airplay: draft.airplay,
|
||||
chromecast: draft.chromecast,
|
||||
@@ -120,8 +120,8 @@ export function useSettingsPreferencesQuery() {
|
||||
return useQuery({
|
||||
key: () => SETTINGS_PREFERENCES_QUERY_KEY,
|
||||
query: async () => {
|
||||
const response = await client.settings.preferencesList({ baseUrl: '/r' });
|
||||
return normalizePreferencesSnapshot(response.data);
|
||||
const response = await rpcClient.getPreferences();
|
||||
return normalizePreferencesSnapshot(response);
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user