Skip to content

Commit

Permalink
Refactored numbered cursors to type unknown;
Browse files Browse the repository at this point in the history
  • Loading branch information
stef-coenen committed Jan 23, 2025
1 parent c872b5c commit 9c82d03
Show file tree
Hide file tree
Showing 8 changed files with 22 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ export const useActiveConnections = (
const dotYouClient = useDotYouClientContext();

const fetchConnections = async (
{ pageSize, cursor }: { pageSize: number; cursor?: number } = {
{ pageSize, cursor }: { pageSize: number; cursor?: unknown } = {
pageSize: 10,
}
) => {
Expand All @@ -202,7 +202,7 @@ export const useActiveConnections = (
return {
fetch: useInfiniteQuery({
queryKey: ['active-connections', pageSize],
initialPageParam: undefined as number | undefined,
initialPageParam: undefined as unknown | undefined,
queryFn: ({ pageParam }) => fetchConnections({ pageSize: pageSize, cursor: pageParam }),
getNextPageParam: (lastPage) =>
lastPage.results?.length >= pageSize && lastPage.cursor !== 0 ? lastPage.cursor : undefined,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { getDomains } from '../../provider/network/domainNetwork/DomainProvider'

interface useActiveDomainsProps {
pageSize: number;
cursor?: number;
cursor?: unknown;
}

export const useDomains = (
Expand All @@ -15,7 +15,7 @@ export const useDomains = (
const dotYouClient = useDotYouClientContext();

const fetchDomains = async (
{ pageSize, cursor }: { pageSize: number; cursor?: number } = {
{ pageSize, cursor }: { pageSize: number; cursor?: unknown } = {
pageSize: 10,
}
) => {
Expand All @@ -37,7 +37,7 @@ export const useDomains = (
fetch: useInfiniteQuery({
queryKey: ['active-domains', activePageSize, activePage],
queryFn: ({ pageParam }) => fetchDomains({ pageSize: activePageSize, cursor: pageParam }),
initialPageParam: undefined as number | undefined,
initialPageParam: undefined as unknown | undefined,
getNextPageParam: (lastPage) =>
lastPage.results?.length >= activePageSize ? lastPage.cursor : undefined,
refetchOnWindowFocus: false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export const usePushNotifications = () => {
const dotYouClient = useDotYouClientContext();
const queryClient = useQueryClient();

const getNotifications = async (cursor: number | undefined) =>
const getNotifications = async (cursor: unknown | undefined) =>
await GetNotifications(dotYouClient, undefined, PAGE_SIZE, cursor);

const markAsRead = async (notificationIds: string[]) =>
Expand All @@ -38,7 +38,7 @@ export const usePushNotifications = () => {
return {
fetch: useInfiniteQuery({
queryKey: ['push-notifications'],
initialPageParam: undefined as number | undefined,
initialPageParam: undefined as unknown | undefined,
queryFn: ({ pageParam }) => getNotifications(pageParam),
getNextPageParam: (lastPage) =>
lastPage?.results && lastPage?.results?.length >= PAGE_SIZE ? lastPage.cursor : undefined,
Expand All @@ -50,14 +50,14 @@ export const usePushNotifications = () => {
const existingData = queryClient.getQueryData<
InfiniteData<{
results: PushNotification[];
cursor: number;
cursor: unknown;
}>
>(['push-notifications']);

if (!existingData) return;
const newData: InfiniteData<{
results: PushNotification[];
cursor: number;
cursor: unknown;
}> = {
...existingData,
pages: existingData.pages.map((page) => ({
Expand All @@ -71,7 +71,7 @@ export const usePushNotifications = () => {
queryClient.setQueryData<
InfiniteData<{
results: PushNotification[];
cursor: number;
cursor: unknown;
}>
>(['push-notifications'], newData);

Expand All @@ -87,14 +87,14 @@ export const usePushNotifications = () => {
const existingData = queryClient.getQueryData<
InfiniteData<{
results: PushNotification[];
cursor: number;
cursor: unknown;
}>
>(['push-notifications']);

if (!existingData) return;
const newData: InfiniteData<{
results: PushNotification[];
cursor: number;
cursor: unknown;
}> = {
...existingData,
pages: existingData.pages.map((page) => ({
Expand All @@ -105,7 +105,7 @@ export const usePushNotifications = () => {
queryClient.setQueryData<
InfiniteData<{
results: PushNotification[];
cursor: number;
cursor: unknown;
}>
>(['push-notifications'], newData);

Expand All @@ -125,14 +125,14 @@ export const insertNewNotification = (
const existingData = queryClient.getQueryData<
InfiniteData<{
results: PushNotification[];
cursor: number;
cursor: unknown;
}>
>(['push-notifications']);

if (!existingData) return;
const newData: InfiniteData<{
results: PushNotification[];
cursor: number;
cursor: unknown;
}> = {
...existingData,
pages: existingData.pages.map((page, index) => ({
Expand All @@ -150,7 +150,7 @@ export const insertNewNotification = (
queryClient.setQueryData<
InfiniteData<{
results: PushNotification[];
cursor: number;
cursor: unknown;
}>
>(['push-notifications'], newData);
};
Expand Down Expand Up @@ -244,7 +244,7 @@ export const insertPushNotification = async (
) => {
const existingNotificationData = queryClient.getQueryData<{
results: PushNotification[] | undefined;
cursor: number;
cursor: unknown;
}>(['push-notifications']);

if (existingNotificationData) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export const getDomains = async (
// eslint-disable-next-line @typescript-eslint/no-unused-vars
data: {
count: number;
cursor?: number;
cursor?: unknown;
}
): Promise<NumberCursoredResult<DomainMembership>> => {
const client = dotYouClient.createAxiosClient();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ export interface GetBatchQueryResultOptions {

export interface QueryModifiedResponse {
includeHeaderContent: boolean;
cursor: number;
cursor: unknown;
searchResults: (HomebaseFile | DeletedHomebaseFile)[];
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export interface CursoredResult<T> {

export interface NumberCursoredResult<T> {
results: T[];
cursor: number;
cursor: unknown;
}

export interface MultiRequestCursoredResult<T> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export const GetNotifications = async (
dotYouClient: DotYouClient,
appId: string | undefined,
count: number | undefined = 50,
cursor: number | undefined
cursor: unknown | undefined
) => {
const axiosClient = dotYouClient.createAxiosClient();
return await axiosClient
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export const getConnections = async (
dotYouClient: DotYouClient,
data: {
count: number;
cursor?: number;
cursor?: unknown;
}
): Promise<NumberCursoredResult<DotYouProfile>> => {
const client = dotYouClient.createAxiosClient();
Expand Down

0 comments on commit 9c82d03

Please sign in to comment.