Types, add max height to reactions modal

Signed-off-by: marcin mikołajczak <git@mkljczk.pl>
This commit is contained in:
marcin mikołajczak
2024-08-23 18:46:14 +02:00
parent c22898cebc
commit 95d131ca3e
6 changed files with 32 additions and 82 deletions

View File

@ -5,6 +5,7 @@ import { decode as decodeBase64 } from 'soapbox/utils/base64';
import { setBrowserSupport, setSubscription, clearSubscription } from './setter';
import type { WebPushSubscription } from 'pl-api';
import type { AppDispatch, RootState } from 'soapbox/store';
import type { Me } from 'soapbox/types/soapbox';
@ -54,7 +55,7 @@ const sendSubscriptionToBackend = (subscription: PushSubscription, me: Me) =>
}
}
return dispatch(createPushSubscription(params) as any);
return dispatch(createPushSubscription(params));
};
// Last one checks for payload support: https://web-push-book.gauntface.com/chapter-06/01-non-standards-browsers/#no-payload
@ -81,10 +82,7 @@ const register = () =>
getRegistration()
.then(getPushSubscription)
// @ts-ignore
.then(({ registration, subscription }: {
registration: ServiceWorkerRegistration;
subscription: PushSubscription | null;
}) => {
.then(({ registration, subscription }) => {
if (subscription !== null) {
// We have a subscription, check if it is still valid
const currentServerKey = (new Uint8Array(subscription.options.applicationServerKey!)).toString();
@ -97,22 +95,25 @@ const register = () =>
return { subscription };
} else {
// Something went wrong, try to subscribe again
return unsubscribe({ registration, subscription }).then((registration: ServiceWorkerRegistration) => {
return unsubscribe({ registration, subscription }).then((registration) => {
return subscribe(registration, getState);
}).then(
(subscription: PushSubscription) => dispatch(sendSubscriptionToBackend(subscription, me) as any));
(subscription) => dispatch(sendSubscriptionToBackend(subscription, me)));
}
}
// No subscription, try to subscribe
return subscribe(registration, getState)
.then(subscription => dispatch(sendSubscriptionToBackend(subscription, me) as any));
.then(async (pushSubscription) => {
const subscription = await dispatch(sendSubscriptionToBackend(pushSubscription, me));
return { subscription };
});
})
.then(({ subscription }: { subscription: PushSubscription | Record<string, any> }) => {
.then(({ subscription }: { subscription: WebPushSubscription | PushSubscription | null }) => {
// If we got a PushSubscription (and not a subscription object from the backend)
// it means that the backend subscription is valid (and was set during hydration)
if (!(subscription instanceof PushSubscription)) {
dispatch(setSubscription(subscription as PushSubscription));
if (subscription !== null && !(subscription instanceof PushSubscription)) {
dispatch(setSubscription(subscription));
if (me) {
pushNotificationsSetting.set(me, { alerts: subscription.alerts });
}
@ -142,7 +143,7 @@ const register = () =>
const saveSettings = () =>
(dispatch: AppDispatch, getState: () => RootState) => {
const state = getState().push_notifications;
const alerts = state.alerts;
const alerts = state.alerts.toJS();
const data = { alerts };
const me = getState().me;

View File

@ -1,3 +1,5 @@
import type { WebPushSubscription } from 'pl-api';
const SET_BROWSER_SUPPORT = 'PUSH_NOTIFICATIONS_SET_BROWSER_SUPPORT' as const;
const SET_SUBSCRIPTION = 'PUSH_NOTIFICATIONS_SET_SUBSCRIPTION' as const;
const CLEAR_SUBSCRIPTION = 'PUSH_NOTIFICATIONS_CLEAR_SUBSCRIPTION' as const;
@ -8,7 +10,7 @@ const setBrowserSupport = (value: boolean) => ({
value,
});
const setSubscription = (subscription: PushSubscription) => ({
const setSubscription = (subscription: WebPushSubscription) => ({
type: SET_SUBSCRIPTION,
subscription,
});

View File

@ -1,78 +1,25 @@
import { getClient } from '../api';
import type { CreatePushNotificationsSubscriptionParams } from 'pl-api';
import type { CreatePushNotificationsSubscriptionParams, UpdatePushNotificationsSubscriptionParams } from 'pl-api';
import type { AppDispatch, RootState } from 'soapbox/store';
const PUSH_SUBSCRIPTION_CREATE_REQUEST = 'PUSH_SUBSCRIPTION_CREATE_REQUEST' as const;
const PUSH_SUBSCRIPTION_CREATE_SUCCESS = 'PUSH_SUBSCRIPTION_CREATE_SUCCESS' as const;
const PUSH_SUBSCRIPTION_CREATE_FAIL = 'PUSH_SUBSCRIPTION_CREATE_FAIL' as const;
const PUSH_SUBSCRIPTION_FETCH_REQUEST = 'PUSH_SUBSCRIPTION_FETCH_REQUEST' as const;
const PUSH_SUBSCRIPTION_FETCH_SUCCESS = 'PUSH_SUBSCRIPTION_FETCH_SUCCESS' as const;
const PUSH_SUBSCRIPTION_FETCH_FAIL = 'PUSH_SUBSCRIPTION_FETCH_FAIL' as const;
const PUSH_SUBSCRIPTION_UPDATE_REQUEST = 'PUSH_SUBSCRIPTION_UPDATE_REQUEST' as const;
const PUSH_SUBSCRIPTION_UPDATE_SUCCESS = 'PUSH_SUBSCRIPTION_UPDATE_SUCCESS' as const;
const PUSH_SUBSCRIPTION_UPDATE_FAIL = 'PUSH_SUBSCRIPTION_UPDATE_FAIL' as const;
const PUSH_SUBSCRIPTION_DELETE_REQUEST = 'PUSH_SUBSCRIPTION_DELETE_REQUEST' as const;
const PUSH_SUBSCRIPTION_DELETE_SUCCESS = 'PUSH_SUBSCRIPTION_DELETE_SUCCESS' as const;
const PUSH_SUBSCRIPTION_DELETE_FAIL = 'PUSH_SUBSCRIPTION_DELETE_FAIL' as const;
const createPushSubscription = (params: CreatePushNotificationsSubscriptionParams) =>
(dispatch: AppDispatch, getState: () => RootState) => {
dispatch({ type: PUSH_SUBSCRIPTION_CREATE_REQUEST, params });
return getClient(getState).pushNotifications.createSubscription(params)
.then((subscription) =>
dispatch({ type: PUSH_SUBSCRIPTION_CREATE_SUCCESS, params, subscription }),
).catch(error =>
dispatch({ type: PUSH_SUBSCRIPTION_CREATE_FAIL, params, error }),
);
};
(dispatch: AppDispatch, getState: () => RootState) =>
getClient(getState).pushNotifications.createSubscription(params);
const fetchPushSubscription = () =>
(dispatch: AppDispatch, getState: () => RootState) => {
dispatch({ type: PUSH_SUBSCRIPTION_FETCH_REQUEST });
return getClient(getState).pushNotifications.getSubscription().then((subscription) =>
dispatch({ type: PUSH_SUBSCRIPTION_FETCH_SUCCESS, subscription }),
).catch(error =>
dispatch({ type: PUSH_SUBSCRIPTION_FETCH_FAIL, error }),
);
};
(dispatch: AppDispatch, getState: () => RootState) =>
getClient(getState).pushNotifications.getSubscription();
const updatePushSubscription = (params: Record<string, any>) =>
(dispatch: AppDispatch, getState: () => RootState) => {
dispatch({ type: PUSH_SUBSCRIPTION_UPDATE_REQUEST, params });
return getClient(getState).pushNotifications.updateSubscription(params).then((subscription) =>
dispatch({ type: PUSH_SUBSCRIPTION_UPDATE_SUCCESS, params, subscription }),
).catch(error =>
dispatch({ type: PUSH_SUBSCRIPTION_UPDATE_FAIL, params, error }),
);
};
const updatePushSubscription = (params: UpdatePushNotificationsSubscriptionParams) =>
(dispatch: AppDispatch, getState: () => RootState) =>
getClient(getState).pushNotifications.updateSubscription(params);
const deletePushSubscription = () =>
(dispatch: AppDispatch, getState: () => RootState) => {
dispatch({ type: PUSH_SUBSCRIPTION_DELETE_REQUEST });
return getClient(getState).pushNotifications.deleteSubscription().then(() =>
dispatch({ type: PUSH_SUBSCRIPTION_DELETE_SUCCESS }),
).catch(error =>
dispatch({ type: PUSH_SUBSCRIPTION_DELETE_FAIL, error }),
);
};
(dispatch: AppDispatch, getState: () => RootState) =>
getClient(getState).pushNotifications.deleteSubscription();
export {
PUSH_SUBSCRIPTION_CREATE_REQUEST,
PUSH_SUBSCRIPTION_CREATE_SUCCESS,
PUSH_SUBSCRIPTION_CREATE_FAIL,
PUSH_SUBSCRIPTION_FETCH_REQUEST,
PUSH_SUBSCRIPTION_FETCH_SUCCESS,
PUSH_SUBSCRIPTION_FETCH_FAIL,
PUSH_SUBSCRIPTION_UPDATE_REQUEST,
PUSH_SUBSCRIPTION_UPDATE_SUCCESS,
PUSH_SUBSCRIPTION_UPDATE_FAIL,
PUSH_SUBSCRIPTION_DELETE_REQUEST,
PUSH_SUBSCRIPTION_DELETE_SUCCESS,
PUSH_SUBSCRIPTION_DELETE_FAIL,
createPushSubscription,
fetchPushSubscription,
updatePushSubscription,

View File

@ -5,7 +5,7 @@ import { SET_BROWSER_SUPPORT, SET_SUBSCRIPTION, CLEAR_SUBSCRIPTION, SET_ALERTS }
import type { SetterAction } from 'soapbox/actions/push-notifications/setter';
const SubscriptionRecord = ImmutableRecord({
id: '',
id: 0,
endpoint: '',
});