Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions packages/shared/src/hooks/bookmark/useBookmarkFolder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ interface UseBookmarkFolder {
query: {
isPending: boolean;
isReady: boolean;
folder: BookmarkFolder;
folder?: BookmarkFolder;
};
update: {
isPending: boolean;
Expand Down Expand Up @@ -62,7 +62,7 @@ export const useBookmarkFolder = ({

logEvent({
event_name: LogEvent.RenameBookmarkFolder,
target_id: folder.id,
target_id: folder!.id,
});
},
onError: () => {
Expand Down
6 changes: 3 additions & 3 deletions packages/shared/src/hooks/integrations/slack/useSlack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,11 @@ export const useSlack = (): UseSlack => {
const redirectUrl = new URL(`${apiUrl}/integrations/slack/auth/callback`);
url.searchParams.append('redirect_uri', redirectUrl.toString());

url.searchParams.append('state', user.id);
url.searchParams.append('state', user!.id);
url.searchParams.append('scope', scopes.join(','));
url.searchParams.append(
'client_id',
process.env.NEXT_PUBLIC_SLACK_CLIENT_ID,
process.env.NEXT_PUBLIC_SLACK_CLIENT_ID!,
);

setCookie('slackRedirectPath', redirectPath, {
Expand All @@ -54,7 +54,7 @@ export const useSlack = (): UseSlack => {

window.location.href = url.toString();
},
[user?.id],
[user],
);

const connectSource = useCallback<UseSlack['connectSource']>(
Expand Down
6 changes: 1 addition & 5 deletions packages/shared/src/hooks/post/usePostCodeSnippets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export const usePostCodeSnippetsQuery = ({
const enabled = !!postId;

const queryResult = useInfiniteQuery({
queryKey: generateQueryKey(RequestKey.PostCodeSnippets, null, {
queryKey: generateQueryKey(RequestKey.PostCodeSnippets, undefined, {
id: postId,
}),
queryFn: async ({ pageParam }) => {
Expand All @@ -65,10 +65,6 @@ export const usePostCodeSnippetsQuery = ({
: enabled,
getNextPageParam: (lastPage) => getNextPageParam(lastPage?.pageInfo),
select: useCallback((data: InfiniteData<UsePostCodeSnippetsData>) => {
if (!data) {
return undefined;
}

return {
...data,
// filter out last page with no edges returned by api paginator
Expand Down
6 changes: 3 additions & 3 deletions packages/shared/src/hooks/post/usePostImage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { useMemo } from 'react';
import { PostType } from '../../graphql/posts';
import type { Post } from '../../graphql/posts';

export const usePostImage = (post: Post): string =>
export const usePostImage = (post: Post): string | undefined =>
useMemo(() => {
if (post?.type === PostType.SocialTwitter && post?.subType === 'thread') {
return undefined;
Expand All @@ -15,10 +15,10 @@ export const usePostImage = (post: Post): string =>
}

const parser = new DOMParser();
const doc = parser.parseFromString(post?.contentHtml, 'text/html');
const doc = parser.parseFromString(post?.contentHtml ?? '', 'text/html');
const imgTag = doc.querySelector('img');
if (imgTag) {
return imgTag.getAttribute('src');
return imgTag.getAttribute('src') ?? undefined;
}

return undefined;
Expand Down
4 changes: 2 additions & 2 deletions packages/shared/src/hooks/post/useRelatedPosts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export type UseRelatedPostsProps = {
type RelatedPostsQueryData = Connection<RelatedPost>;

export type UseRelatedPosts = {
relatedPosts: InfiniteData<RelatedPostsQueryData>;
relatedPosts?: InfiniteData<RelatedPostsQueryData>;
isLoading: boolean;
hasNextPage: boolean;
fetchNextPage: UseInfiniteQueryResult['fetchNextPage'];
Expand All @@ -51,7 +51,7 @@ export const useRelatedPosts = ({
fetchNextPage,
isFetchingNextPage,
} = useInfiniteQuery({
queryKey: generateQueryKey(RequestKey.RelatedPosts, null, {
queryKey: generateQueryKey(RequestKey.RelatedPosts, undefined, {
id: postId,
type: relationType,
}),
Expand Down
12 changes: 7 additions & 5 deletions packages/shared/src/hooks/post/useViewPost.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,13 @@ export const useViewPost = (): UseMutateAsyncFunction<
onSuccess: async () => {
const streak = client.getQueryData<UserStreak>(streakKey);
const isNewStreak = !streak?.lastViewAt;
const isFirstViewToday = !isSameDayInTimezone(
new Date(streak?.lastViewAt),
new Date(),
user.timezone,
);
const isFirstViewToday =
!isNewStreak &&
!isSameDayInTimezone(
new Date(streak!.lastViewAt!),
new Date(),
user!.timezone,
);

if (isNewStreak || isFirstViewToday) {
await client.refetchQueries({ queryKey: streakKey });
Expand Down
6 changes: 3 additions & 3 deletions packages/shared/src/hooks/profile/useDevCard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export interface DevCardQueryData {
}

export interface UseDevCard {
devcard: DevCardData;
devcard: Partial<DevCardData> & { streak: { max: number } };
isLoading: boolean;
coverImage: string;
}
Expand All @@ -53,13 +53,13 @@ export const useDevCard = (userId: string): UseDevCard => {

const { isProfileCover, user } = devCard ?? {};
const coverImage =
(isProfileCover ? user.cover : undefined) ??
(isProfileCover ? user!.cover : undefined) ??
cloudinaryDevcardDefaultCoverImage;

return {
devcard: {
...devCard,
streak: { ...userStreakProfile },
streak: { max: userStreakProfile?.max ?? 0 },
},
isLoading,
coverImage,
Expand Down
4 changes: 2 additions & 2 deletions packages/shared/src/hooks/profile/useProfile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@ export function useProfile(initialUser?: PublicProfile): {
});
const { data: user } = useQuery({
queryKey: userQueryKey,
queryFn: () => getProfile(initialUser?.id),
queryFn: () => getProfile(initialUser!.id),
...disabledRefetch,
staleTime: StaleTime.OneHour,
initialData: initialUser,
enabled: !!initialUser?.id,
});

return {
user,
user: user!,
userQueryKey,
isUserSame: !!(loggedUser && loggedUser?.id === initialUser?.id),
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { useAuthContext } from '../../contexts/AuthContext';
import { getSourcePostModeration } from '../../graphql/posts';

interface UseSourcePostModerationById {
moderated: SourcePostModeration;
moderated?: SourcePostModeration;
isLoading: boolean;
}

Expand All @@ -21,7 +21,7 @@ export const useSourcePostModerationById = ({
const { user } = useAuthContext();
const { data, isLoading } = useQuery({
queryKey: generateQueryKey(RequestKey.SourcePostModeration, user, id),
queryFn: () => getSourcePostModeration({ id }),
queryFn: () => getSourcePostModeration({ id: id! }),
enabled: !!id && enabled,
});

Expand Down
4 changes: 2 additions & 2 deletions packages/shared/src/hooks/streaks/useReadingStreak.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ type UpdateReadingStreakConfig = {
};

interface UserReadingStreak {
streak: UserStreak;
streak?: UserStreak;
isLoading: boolean;
isUpdatingConfig: boolean;
checkReadingStreak: () => void;
Expand Down Expand Up @@ -67,7 +67,7 @@ export const useReadingStreak = (): UserReadingStreak => {
isSameDayInTimezone(
new Date(streak.lastViewAt),
new Date(),
user.timezone,
user!.timezone,
);

if (!hasReadToday) {
Expand Down
4 changes: 2 additions & 2 deletions packages/shared/src/hooks/useCheckCoresRole.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ export const useCheckCoresRole = (): void => {
checkCoresRole: Pick<LoggedUser, 'coresRole'>;
}>(CHECK_CORES_ROLE_QUERY);

if (result.checkCoresRole.coresRole !== user.coresRole) {
if (result.checkCoresRole.coresRole !== user!.coresRole) {
await updateUser({
...user,
...user!,
coresRole: result.checkCoresRole.coresRole,
});
}
Expand Down
4 changes: 2 additions & 2 deletions packages/shared/src/hooks/useDebounceFn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export default function useDebounceFn<T = unknown>(
}
timeoutRef.current = window.setTimeout(() => {
lastExecutionRef.current = new Date();
timeoutRef.current = null;
timeoutRef.current = undefined;
callbackRef.current?.(args);
}, delay);
},
Expand All @@ -45,7 +45,7 @@ export default function useDebounceFn<T = unknown>(
const cancelCallback = useCallback(() => {
if (timeoutRef.current) {
window.clearTimeout(timeoutRef.current);
timeoutRef.current = null;
timeoutRef.current = undefined;
}
}, [timeoutRef]);

Expand Down
6 changes: 3 additions & 3 deletions packages/shared/src/hooks/useDeleteSquad.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,10 @@ export const useDeleteSquad = ({
if (await showPrompt(options)) {
logEvent({
event_name: LogEvent.DeleteSquad,
extra: JSON.stringify({ squad: squad.id }),
extra: JSON.stringify({ squad: squad.id! }),
});
await deleteSquad(squad.id);
deleteCachedSquad(squad.id);
await deleteSquad(squad.id!);
deleteCachedSquad(squad.id!);
await callback?.();
}
};
Expand Down
6 changes: 3 additions & 3 deletions packages/shared/src/hooks/useLeaveSquad.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,10 @@ export const useLeaveSquad = ({ squad }: UseLeaveSquadProps): UseLeaveSquad => {
if (left) {
logEvent({
event_name: LogEvent.LeaveSquad,
extra: JSON.stringify({ squad: squad.id }),
extra: JSON.stringify({ squad: squad.id! }),
});
await leaveSquad(squad.id);
deleteCachedSquad(squad.id);
await leaveSquad(squad.id!);
deleteCachedSquad(squad.id!);

queryClient.setQueryData(
generateQueryKey(RequestKey.ContentPreference, user, {
Expand Down
Loading