WIP TypeScript convertions
Signed-off-by: marcin mikołajczak <git@mkljczk.pl>
This commit is contained in:
@@ -4,7 +4,8 @@ import type { RootState } from 'soapbox/store';
|
||||
|
||||
export const validId = (id: any) => typeof id === 'string' && id !== 'null' && id !== 'undefined';
|
||||
|
||||
export const isURL = (url: string) => {
|
||||
export const isURL = (url?: string | null) => {
|
||||
if (typeof url !== 'string') return false;
|
||||
try {
|
||||
new URL(url);
|
||||
return true;
|
||||
@@ -30,11 +31,11 @@ export const isLoggedIn = (getState: () => RootState) => {
|
||||
return validId(getState().me);
|
||||
};
|
||||
|
||||
export const getAppToken = (state: RootState) => state.auth.getIn(['app', 'access_token']) as string;
|
||||
export const getAppToken = (state: RootState) => state.auth.app.access_token as string;
|
||||
|
||||
export const getUserToken = (state: RootState, accountId?: string | false | null) => {
|
||||
const accountUrl = state.accounts.getIn([accountId, 'url']);
|
||||
return state.auth.getIn(['users', accountUrl, 'access_token']) as string;
|
||||
const accountUrl = state.accounts.getIn([accountId, 'url']) as string;
|
||||
return state.auth.users.get(accountUrl)?.access_token as string;
|
||||
};
|
||||
|
||||
export const getAccessToken = (state: RootState) => {
|
||||
@@ -43,24 +44,23 @@ export const getAccessToken = (state: RootState) => {
|
||||
};
|
||||
|
||||
export const getAuthUserId = (state: RootState) => {
|
||||
const me = state.auth.get('me');
|
||||
const me = state.auth.me;
|
||||
|
||||
return ImmutableList([
|
||||
state.auth.getIn(['users', me, 'id']),
|
||||
state.auth.users.get(me!)?.id,
|
||||
me,
|
||||
]).find(validId);
|
||||
};
|
||||
|
||||
export const getAuthUserUrl = (state: RootState) => {
|
||||
const me = state.auth.get('me');
|
||||
const me = state.auth.me;
|
||||
|
||||
return ImmutableList([
|
||||
state.auth.getIn(['users', me, 'url']),
|
||||
state.auth.users.get(me!)?.url,
|
||||
me,
|
||||
]).find(isURL);
|
||||
].filter(url => url)).find(isURL);
|
||||
};
|
||||
|
||||
/** Get the VAPID public key. */
|
||||
export const getVapidKey = (state: RootState) => {
|
||||
return state.auth.getIn(['app', 'vapid_key']) || state.instance.getIn(['pleroma', 'vapid_public_key']);
|
||||
};
|
||||
export const getVapidKey = (state: RootState) =>
|
||||
(state.auth.app.vapid_key || state.instance.pleroma.get('vapid_public_key')) as string;
|
||||
|
||||
Reference in New Issue
Block a user