Skip to content

Commit

Permalink
CHORE: Upgrade to React Query v5 (#136)
Browse files Browse the repository at this point in the history
Closes #131 

## Description

Upgrade `@tanstack/react-query` to v5 and migrate the breaking change
  • Loading branch information
amarangganar authored Oct 30, 2023
1 parent a3e919d commit 0e2dedb
Show file tree
Hide file tree
Showing 14 changed files with 133 additions and 146 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@
"@radix-ui/react-toggle": "^1.0.3",
"@radix-ui/react-tooltip": "^1.0.7",
"@sindresorhus/slugify": "^2.2.1",
"@tanstack/react-query": "^4.36.1",
"@tanstack/react-query-devtools": "^4.36.1",
"@tanstack/react-query": "^5.4.3",
"@tanstack/react-query-devtools": "^5.4.3",
"@types/node": "20.6.3",
"@types/react": "18.2.27",
"@types/react-dom": "18.2.12",
Expand Down
69 changes: 20 additions & 49 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 4 additions & 10 deletions src/app/account/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@ export default function Account() {
)
const { isLogin, isLoading, user } = useAuth(auth)

// @ts-ignore
const { data: dataOwner, isLoading: isLoadingOwner } = useOwner(user, {
const { data: dataOwner, isLoading: isLoadingOwner } = useOwner(user!, {
enabled: !isLoading && isLogin && !!user,
})

Expand All @@ -38,14 +37,9 @@ export default function Account() {
isLoading: isLoadingQuestions,
fetchNextPage,
isFetching,
} = useQuestionListPagination(
// @ts-ignore
user,
LIMIT,
{
enabled: !isLoading && isLogin && !!user,
},
)
} = useQuestionListPagination(user!, LIMIT, {
enabled: !isLoading && isLogin && !!user,
})

const handleClickQuestion = (question: Question) => {
setSelectedQuestion(question)
Expand Down
7 changes: 2 additions & 5 deletions src/app/account/settings/notification/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,12 @@ const auth = getFirebaseAuth()
export default function SettingOgImage() {
const { isLogin, isLoading, user } = useAuth(auth)

// @ts-ignore
const { data: dataOwner, isLoading: isLoadingOwner } = useOwner(user, {
const { data: dataOwner, isLoading: isLoadingOwner } = useOwner(user!, {
enabled: !isLoading && isLogin && !!user,
})

// @ts-ignore
const { data: dataNotifChannel, isLoading: isLoadingNotifChannel } =
// @ts-ignore
useNotifChannelByUser(user, {
useNotifChannelByUser(user!, {
enabled: !isLoading && isLogin && !!user,
})

Expand Down
7 changes: 2 additions & 5 deletions src/app/account/settings/og-image/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,12 @@ const auth = getFirebaseAuth()
export default function SettingOgImage() {
const { isLogin, isLoading, user } = useAuth(auth)

// @ts-ignore
const { data: dataOwner, isLoading: isLoadingOwner } = useOwner(user, {
const { data: dataOwner, isLoading: isLoadingOwner } = useOwner(user!, {
enabled: !isLoading && isLogin && !!user,
})

// @ts-ignore
const { data: dataCustomOg, isLoading: isLoadingCustomOg } =
// @ts-ignore
useCustomOgByUser(user, {
useCustomOgByUser(user!, {
enabled: !isLoading && isLogin && !!user,
})

Expand Down
5 changes: 2 additions & 3 deletions src/app/account/settings/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -76,12 +76,11 @@ export default function Account() {
const dialog = useDialog()
const { isLogin, isLoading, user } = useAuth(auth)

// @ts-ignore
const { data: dataOwner, isLoading: isLoadingOwner } = useOwner(user, {
const { data: dataOwner, isLoading: isLoadingOwner } = useOwner(user!, {
enabled: !isLoading && isLogin && !!user,
})

const { mutate: updateUser, isLoading: isSubmitting } = useUpdateUser()
const { mutate: updateUser, isPending: isSubmitting } = useUpdateUser()

const form = useForm<FormValues>({
resolver: valibotResolver(schema),
Expand Down
3 changes: 1 addition & 2 deletions src/components/Header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,7 @@ export function Header() {
const router = useRouter()
const { toast } = useToast()
const { isLogin, user, isLoading } = useAuth(auth)
// @ts-ignore
const { data: dataOwner, isLoading: isLoadingOwner } = useOwner(user, {
const { data: dataOwner, isLoading: isLoadingOwner } = useOwner(user!, {
enabled: !isLoading && isLogin && !!user,
})

Expand Down
6 changes: 3 additions & 3 deletions src/components/PublicAccessToggler.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ const PublicAccessToggler = ({
const { toast } = useToast()
const dialog = useDialog()

const { mutate, isLoading } = usePatchQuestionAsPublicOrPrivate()
const { mutate, isPending } = usePatchQuestionAsPublicOrPrivate()

const hitMutation = async () => {
trackEvent('click toggle public access')
Expand Down Expand Up @@ -64,10 +64,10 @@ const PublicAccessToggler = ({
variant="outline"
size="sm"
className={question?.public ? '' : 'border-red-500'}
disabled={disabled ?? isLoading}
disabled={disabled ?? isPending}
onClick={handleTogglePrivacy}
>
{isLoading ? (
{isPending ? (
<>
<Loader2 className="mr-2 h-4 w-4 animate-spin" />
</>
Expand Down
4 changes: 2 additions & 2 deletions src/modules/AccountSettings/SettingNotif/SettingTelegram.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,9 @@ export default function SettingTelegram({
existing: NotifChannel[] | null | undefined
}) {
const { toast } = useToast()
const { mutate: mutateUpdateChannelNotif, isLoading: isLoadingUpdate } =
const { mutate: mutateUpdateChannelNotif, isPending: isLoadingUpdate } =
usePatchUpdateChannelNotif()
const { mutate: mutateAddNewChannelNotif, isLoading: isLoadingAdd } =
const { mutate: mutateAddNewChannelNotif, isPending: isLoadingAdd } =
usePostAddNewChannelNotif()

const form = useForm<FormValues>({
Expand Down
4 changes: 2 additions & 2 deletions src/modules/AccountSettings/SettingOg/SimpleMode.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,9 @@ export default function SimpleMode({
}) {
const [activeGradient, setActiveGradient] = useState<string>('hyper')
const { toast } = useToast()
const { mutate: addNewOgMutation, isLoading: isAddingNewCustomOg } =
const { mutate: addNewOgMutation, isPending: isAddingNewCustomOg } =
useAddNewCustomOg()
const { mutate: updateCustomOgMutation, isLoading: isUpdatingCustomOg } =
const { mutate: updateCustomOgMutation, isPending: isUpdatingCustomOg } =
useUpdateCustomOg()

const isSubmitting = isAddingNewCustomOg || isUpdatingCustomOg
Expand Down
4 changes: 2 additions & 2 deletions src/modules/EskplorPage/ContentPublicUserList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const ContentPublicUserList = () => {
isFetching,
isFetchingNextPage,
fetchNextPage,
isInitialLoading,
isLoading,
} = useGetPublicUser({
limit: 20,
name,
Expand All @@ -28,7 +28,7 @@ const ContentPublicUserList = () => {
<PublicUserList
dataPublicUsers={dataPublicUsers}
isFetching={isFetchingNextPage}
isInitialLoading={isInitialLoading}
isInitialLoading={isLoading}
/>

<div className="w-full justify-center flex mt-4">
Expand Down
2 changes: 1 addition & 1 deletion src/modules/LoginPage/LoginButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ export const LoginButtonWithRedirect = () => {

postAddUser(user).then((result) => {
if (result.isNewUser) {
queryClient.refetchQueries(['/owner', user.uid])
queryClient.refetchQueries({ queryKey: ['/owner', user.uid] })
}
})
})
Expand Down
6 changes: 3 additions & 3 deletions src/modules/PublicQuestionPage/QuestionForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ type FormValues = Output<typeof schema>

export function QuestionForm({ owner }: { owner: UserProfile }) {
const { toast } = useToast()
const { mutate, isLoading } = useSendQuestion()
const { mutate, isPending } = useSendQuestion()

const form = useForm<FormValues>({
resolver: valibotResolver(schema),
Expand Down Expand Up @@ -154,8 +154,8 @@ export function QuestionForm({ owner }: { owner: UserProfile }) {
)}
/>
<div className="flex flex-wrap justify-between gap-2">
<Button type="submit" disabled={isLoading}>
{isLoading ? (
<Button type="submit" disabled={isPending}>
{isPending ? (
<>
<Loader2 className="mr-2 h-4 w-4 animate-spin" />
<span>Sedang mengirim...</span>
Expand Down
Loading

0 comments on commit 0e2dedb

Please sign in to comment.