nicolium: oxlint and oxfmt migration, remove eslint
Signed-off-by: nicole mikołajczyk <git@mkljczk.pl>
This commit is contained in:
@@ -3,18 +3,22 @@ import memoize from 'lodash/memoize';
|
||||
|
||||
import type { PlApiClient } from 'pl-api';
|
||||
|
||||
const relationships = memoize((client: PlApiClient) => create({
|
||||
fetcher: (ids: string[]) => client.accounts.getRelationships(ids),
|
||||
resolver: keyResolver('id'),
|
||||
scheduler: bufferScheduler(200),
|
||||
}));
|
||||
const relationships = memoize((client: PlApiClient) =>
|
||||
create({
|
||||
fetcher: (ids: string[]) => client.accounts.getRelationships(ids),
|
||||
resolver: keyResolver('id'),
|
||||
scheduler: bufferScheduler(200),
|
||||
}),
|
||||
);
|
||||
|
||||
// TODO: proper multi-client support
|
||||
const translations = memoize((lang: string, client: PlApiClient) => create({
|
||||
fetcher: (ids: string[]) => client.statuses.translateStatuses(ids, lang),
|
||||
resolver: keyResolver('id'),
|
||||
scheduler: bufferScheduler(100),
|
||||
}));
|
||||
const translations = memoize((lang: string, client: PlApiClient) =>
|
||||
create({
|
||||
fetcher: (ids: string[]) => client.statuses.translateStatuses(ids, lang),
|
||||
resolver: keyResolver('id'),
|
||||
scheduler: bufferScheduler(100),
|
||||
}),
|
||||
);
|
||||
|
||||
const batcher = {
|
||||
relationships,
|
||||
|
||||
@@ -26,15 +26,17 @@ const useAccountLookup = (acct: string | undefined, opts: UseAccountLookupOpts =
|
||||
{ enabled: !!acct },
|
||||
);
|
||||
|
||||
const {
|
||||
data: relationship,
|
||||
isLoading: isRelationshipLoading,
|
||||
} = useRelationshipQuery(withRelationship ? entity?.id : undefined);
|
||||
const { data: relationship, isLoading: isRelationshipLoading } = useRelationshipQuery(
|
||||
withRelationship ? entity?.id : undefined,
|
||||
);
|
||||
|
||||
const isBlocked = entity?.relationship?.blocked_by === true;
|
||||
const isUnavailable = (me === entity?.id) ? false : (isBlocked && !features.blockersVisible);
|
||||
const isUnavailable = me === entity?.id ? false : isBlocked && !features.blockersVisible;
|
||||
|
||||
const account = useMemo(() => entity ? { ...entity, relationship } : undefined, [entity, relationship]);
|
||||
const account = useMemo(
|
||||
() => (entity ? { ...entity, relationship } : undefined),
|
||||
[entity, relationship],
|
||||
);
|
||||
|
||||
return {
|
||||
...result,
|
||||
|
||||
@@ -26,24 +26,26 @@ const useAccount = (accountId?: string, opts: UseAccountOpts = {}) => {
|
||||
{ enabled: !!accountId },
|
||||
);
|
||||
|
||||
const meta = useAppSelector((state) => accountId ? state.accounts_meta[accountId] : undefined);
|
||||
const meta = useAppSelector((state) => (accountId ? state.accounts_meta[accountId] : undefined));
|
||||
|
||||
const {
|
||||
data: relationship,
|
||||
isLoading: isRelationshipLoading,
|
||||
} = useRelationshipQuery(withRelationship ? entity?.id : undefined);
|
||||
const { data: relationship, isLoading: isRelationshipLoading } = useRelationshipQuery(
|
||||
withRelationship ? entity?.id : undefined,
|
||||
);
|
||||
|
||||
const isBlocked = entity?.relationship?.blocked_by === true;
|
||||
const isUnavailable = (me === entity?.id) ? false : (isBlocked && !features.blockersVisible);
|
||||
const isUnavailable = me === entity?.id ? false : isBlocked && !features.blockersVisible;
|
||||
|
||||
const account = useMemo(
|
||||
() => entity ? {
|
||||
...entity,
|
||||
relationship,
|
||||
__meta: { meta, ...entity.__meta },
|
||||
// @ts-ignore
|
||||
is_admin: meta?.role ? (meta.role.permissions & 0x1) === 0x1 : entity.is_admin,
|
||||
} : undefined,
|
||||
() =>
|
||||
entity
|
||||
? {
|
||||
...entity,
|
||||
relationship,
|
||||
__meta: { meta, ...entity.__meta },
|
||||
// @ts-ignore
|
||||
is_admin: meta?.role ? (meta.role.permissions & 0x1) === 0x1 : entity.is_admin,
|
||||
}
|
||||
: undefined,
|
||||
[entity, relationship],
|
||||
);
|
||||
|
||||
|
||||
@@ -22,7 +22,7 @@ const useVerify = () => {
|
||||
};
|
||||
|
||||
transaction({
|
||||
Accounts: ({ [accountId]: updater }),
|
||||
Accounts: { [accountId]: updater },
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
@@ -5,9 +5,8 @@ import { useClient } from '@/hooks/use-client';
|
||||
const useDeleteGroup = () => {
|
||||
const client = useClient();
|
||||
|
||||
const { deleteEntity, isSubmitting } = useDeleteEntity(
|
||||
Entities.GROUPS,
|
||||
(groupId: string) => client.experimental.groups.deleteGroup(groupId),
|
||||
const { deleteEntity, isSubmitting } = useDeleteEntity(Entities.GROUPS, (groupId: string) =>
|
||||
client.experimental.groups.deleteGroup(groupId),
|
||||
);
|
||||
|
||||
return {
|
||||
|
||||
@@ -11,8 +11,14 @@ const useDemoteGroupMember = (group: Pick<Group, 'id'>, groupMember: Pick<GroupM
|
||||
|
||||
const { createEntity } = useCreateEntity(
|
||||
[Entities.GROUP_MEMBERSHIPS, groupMember.id],
|
||||
({ account_ids, role }: { account_ids: string[]; role: GroupRole }) => client.experimental.groups.demoteGroupUsers(group.id, account_ids, role),
|
||||
{ schema: v.pipe(v.any(), v.transform(arr => arr[0])) },
|
||||
({ account_ids, role }: { account_ids: string[]; role: GroupRole }) =>
|
||||
client.experimental.groups.demoteGroupUsers(group.id, account_ids, role),
|
||||
{
|
||||
schema: v.pipe(
|
||||
v.any(),
|
||||
v.transform((arr) => arr[0]),
|
||||
),
|
||||
},
|
||||
);
|
||||
|
||||
return createEntity;
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { GroupRoles } from 'pl-api';
|
||||
|
||||
import { Entities } from '@/entity-store/entities';
|
||||
import { useDismissEntity } from '@/entity-store/hooks/use-dismiss-entity';
|
||||
import { useDismissEntity } from '@/entity-store/hooks/use-dismiss-entity';
|
||||
import { useEntities } from '@/entity-store/hooks/use-entities';
|
||||
import { useClient } from '@/hooks/use-client';
|
||||
|
||||
@@ -25,13 +25,19 @@ const useGroupMembershipRequests = (groupId: string) => {
|
||||
);
|
||||
|
||||
const { dismissEntity: authorize } = useDismissEntity(path, async (accountId: string) => {
|
||||
const response = await client.experimental.groups.acceptGroupMembershipRequest(groupId, accountId);
|
||||
const response = await client.experimental.groups.acceptGroupMembershipRequest(
|
||||
groupId,
|
||||
accountId,
|
||||
);
|
||||
invalidate();
|
||||
return response;
|
||||
});
|
||||
|
||||
const { dismissEntity: reject } = useDismissEntity(path, async (accountId: string) => {
|
||||
const response = await client.experimental.groups.rejectGroupMembershipRequest(groupId, accountId);
|
||||
const response = await client.experimental.groups.rejectGroupMembershipRequest(
|
||||
groupId,
|
||||
accountId,
|
||||
);
|
||||
invalidate();
|
||||
return response;
|
||||
});
|
||||
|
||||
@@ -14,7 +14,10 @@ const useGroupRelationship = (groupId: string | undefined) => {
|
||||
() => client.experimental.groups.getGroupRelationships([groupId!]),
|
||||
{
|
||||
enabled: !!groupId,
|
||||
schema: v.pipe(v.any(), v.transform(arr => arr[0])),
|
||||
schema: v.pipe(
|
||||
v.any(),
|
||||
v.transform((arr) => arr[0]),
|
||||
),
|
||||
},
|
||||
);
|
||||
|
||||
|
||||
@@ -14,7 +14,11 @@ const useGroup = (groupId: string, refetch = true) => {
|
||||
const location = useLocation();
|
||||
const navigate = useNavigate();
|
||||
|
||||
const { entity: group, isUnauthorized, ...result } = useEntity<Group, Group>(
|
||||
const {
|
||||
entity: group,
|
||||
isUnauthorized,
|
||||
...result
|
||||
} = useEntity<Group, Group>(
|
||||
[Entities.GROUPS, groupId],
|
||||
() => client.experimental.groups.getGroup(groupId),
|
||||
{
|
||||
|
||||
@@ -18,7 +18,7 @@ const useGroups = () => {
|
||||
);
|
||||
const { relationships } = useGroupRelationships(
|
||||
['search', ''],
|
||||
entities.map(entity => entity.id),
|
||||
entities.map((entity) => entity.id),
|
||||
);
|
||||
|
||||
const groups = entities.map((group) => ({
|
||||
|
||||
@@ -11,8 +11,14 @@ const usePromoteGroupMember = (group: Pick<Group, 'id'>, groupMember: Pick<Group
|
||||
|
||||
const { createEntity } = useCreateEntity(
|
||||
[Entities.GROUP_MEMBERSHIPS, groupMember.id],
|
||||
({ account_ids, role }: { account_ids: string[]; role: GroupRole }) => client.experimental.groups.promoteGroupUsers(group.id, account_ids, role),
|
||||
{ schema: v.pipe(v.any(), v.transform(arr => arr[0])) },
|
||||
({ account_ids, role }: { account_ids: string[]; role: GroupRole }) =>
|
||||
client.experimental.groups.promoteGroupUsers(group.id, account_ids, role),
|
||||
{
|
||||
schema: v.pipe(
|
||||
v.any(),
|
||||
v.transform((arr) => arr[0]),
|
||||
),
|
||||
},
|
||||
);
|
||||
|
||||
return createEntity;
|
||||
|
||||
@@ -7,25 +7,36 @@ import { getAccessToken } from '@/utils/auth';
|
||||
|
||||
import type { StreamingEvent } from 'pl-api';
|
||||
|
||||
const useTimelineStream = (stream: string, params: { list?: string; tag?: string } = {}, enabled = true, listener?: (event: StreamingEvent) => any) => {
|
||||
const useTimelineStream = (
|
||||
stream: string,
|
||||
params: { list?: string; tag?: string } = {},
|
||||
enabled = true,
|
||||
listener?: (event: StreamingEvent) => any,
|
||||
) => {
|
||||
const firstUpdate = useRef(true);
|
||||
|
||||
const client = useClient();
|
||||
|
||||
const instance = useInstance();
|
||||
const socket = useRef<({
|
||||
const socket = useRef<{
|
||||
listen: (listener: any, stream?: string) => number;
|
||||
unlisten: (listener: any) => void;
|
||||
subscribe: (stream: string, params?: {
|
||||
subscribe: (
|
||||
stream: string,
|
||||
params?: {
|
||||
list?: string;
|
||||
tag?: string;
|
||||
}) => void;
|
||||
unsubscribe: (stream: string, params?: {
|
||||
},
|
||||
) => void;
|
||||
unsubscribe: (
|
||||
stream: string,
|
||||
params?: {
|
||||
list?: string;
|
||||
tag?: string;
|
||||
}) => void;
|
||||
},
|
||||
) => void;
|
||||
close: () => void;
|
||||
}) | null>(null);
|
||||
} | null>(null);
|
||||
|
||||
const accessToken = useAppSelector(getAccessToken);
|
||||
const streamingUrl = instance.configuration.urls.streaming;
|
||||
|
||||
@@ -21,11 +21,17 @@ import { updateReactions } from '../../../queries/announcements/use-announcement
|
||||
import { useTimelineStream } from './use-timeline-stream';
|
||||
|
||||
import type { AppDispatch, RootState } from '@/store';
|
||||
import type { Announcement, AnnouncementReaction, FollowRelationshipUpdate, Relationship, StreamingEvent } from 'pl-api';
|
||||
import type {
|
||||
Announcement,
|
||||
AnnouncementReaction,
|
||||
FollowRelationshipUpdate,
|
||||
Relationship,
|
||||
StreamingEvent,
|
||||
} from 'pl-api';
|
||||
|
||||
const updateAnnouncementReactions = (reaction: AnnouncementReaction) => {
|
||||
queryClient.setQueryData(['announcements'], (prevResult: Announcement[]) =>
|
||||
prevResult.map(value => {
|
||||
prevResult.map((value) => {
|
||||
if (value.id !== reaction.announcement_id) return value;
|
||||
|
||||
return {
|
||||
@@ -40,16 +46,16 @@ const updateAnnouncement = (announcement: Announcement) =>
|
||||
queryClient.setQueryData(['announcements'], (prevResult: Announcement[]) => {
|
||||
let updated = false;
|
||||
|
||||
const result = prevResult.map(value => value.id === announcement.id
|
||||
? (updated = true, announcement)
|
||||
: value);
|
||||
const result = prevResult.map((value) =>
|
||||
value.id === announcement.id ? ((updated = true), announcement) : value,
|
||||
);
|
||||
|
||||
if (!updated) return [announcement, ...result];
|
||||
});
|
||||
|
||||
const deleteAnnouncement = (announcementId: string) =>
|
||||
queryClient.setQueryData(['announcements'], (prevResult: Announcement[]) =>
|
||||
prevResult.filter(value => value.id !== announcementId),
|
||||
prevResult.filter((value) => value.id !== announcementId),
|
||||
);
|
||||
|
||||
const followStateToRelationship = (followState: FollowRelationshipUpdate['state']) => {
|
||||
@@ -65,17 +71,23 @@ const followStateToRelationship = (followState: FollowRelationshipUpdate['state'
|
||||
}
|
||||
};
|
||||
|
||||
const updateFollowRelationships = (update: FollowRelationshipUpdate) =>
|
||||
(dispatch: AppDispatch, getState: () => RootState) => {
|
||||
const updateFollowRelationships =
|
||||
(update: FollowRelationshipUpdate) => (dispatch: AppDispatch, getState: () => RootState) => {
|
||||
const state = getState();
|
||||
|
||||
const me = state.me;
|
||||
|
||||
if (update.follower.id === me) {
|
||||
queryClient.setQueryData<Relationship>(['accountRelationships', update.following.id], (relationship) => relationship ? ({
|
||||
...relationship,
|
||||
...followStateToRelationship(update.state),
|
||||
}) : undefined);
|
||||
queryClient.setQueryData<Relationship>(
|
||||
['accountRelationships', update.following.id],
|
||||
(relationship) =>
|
||||
relationship
|
||||
? {
|
||||
...relationship,
|
||||
...followStateToRelationship(update.state),
|
||||
}
|
||||
: undefined,
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -110,11 +122,13 @@ const useUserStream = () => {
|
||||
dispatch(deleteFromTimelines(event.payload));
|
||||
break;
|
||||
case 'notification':
|
||||
messages[getLocale()]().then(messages => {
|
||||
dispatch(updateNotificationsQueue(event.payload, messages, getLocale()));
|
||||
}).catch(error => {
|
||||
console.error(error);
|
||||
});
|
||||
messages[getLocale()]()
|
||||
.then((messages) => {
|
||||
dispatch(updateNotificationsQueue(event.payload, messages, getLocale()));
|
||||
})
|
||||
.catch((error) => {
|
||||
console.error(error);
|
||||
});
|
||||
break;
|
||||
case 'conversation':
|
||||
dispatch(updateConversations(event.payload));
|
||||
|
||||
@@ -8,15 +8,15 @@ import { buildFullPath } from '@/utils/url';
|
||||
import type { RootState, Store } from '@/store';
|
||||
|
||||
let store: Store;
|
||||
import('@/store').then((value) => store = value.store).catch(() => {});
|
||||
import('@/store').then((value) => (store = value.store)).catch(() => {});
|
||||
|
||||
type PlfeResponse<T = any> = Response & { data: string; json: T };
|
||||
|
||||
/**
|
||||
* Dumb client for grabbing static files.
|
||||
* It uses FE_SUBDIRECTORY and parses JSON if possible.
|
||||
* No authorization is needed.
|
||||
*/
|
||||
* Dumb client for grabbing static files.
|
||||
* It uses FE_SUBDIRECTORY and parses JSON if possible.
|
||||
* No authorization is needed.
|
||||
*/
|
||||
const staticFetch = async (input: URL | RequestInfo, init?: RequestInit) => {
|
||||
const fullPath = buildFullPath(input.toString(), BuildConfig.BACKEND_URL);
|
||||
|
||||
@@ -34,7 +34,17 @@ const staticFetch = async (input: URL | RequestInfo, init?: RequestInit) => {
|
||||
|
||||
const { headers, ok, redirected, status, statusText, type, url } = response;
|
||||
|
||||
return { headers, ok, redirected, status, statusText, type, url, data, json } as any as PlfeResponse;
|
||||
return {
|
||||
headers,
|
||||
ok,
|
||||
redirected,
|
||||
status,
|
||||
statusText,
|
||||
type,
|
||||
url,
|
||||
data,
|
||||
json,
|
||||
} as any as PlfeResponse;
|
||||
};
|
||||
|
||||
const getClient = (state: RootState | (() => RootState) = store?.getState()) => {
|
||||
@@ -43,8 +53,4 @@ const getClient = (state: RootState | (() => RootState) = store?.getState()) =>
|
||||
return state.auth.client;
|
||||
};
|
||||
|
||||
export {
|
||||
type PlfeResponse,
|
||||
staticFetch,
|
||||
getClient,
|
||||
};
|
||||
export { type PlfeResponse, staticFetch, getClient };
|
||||
|
||||
Reference in New Issue
Block a user