me + unseen-count dont request if do not login
This commit is contained in:
@@ -132,7 +132,7 @@ function FoodPage({}: Props) {
|
|||||||
<div className="relative w-full lg:h-full min-h-0 not-lg:bg-container rounded-2xl overflow-hidden lg:rounded-r-none lg:order-1">
|
<div className="relative w-full lg:h-full min-h-0 not-lg:bg-container rounded-2xl overflow-hidden lg:rounded-r-none lg:order-1">
|
||||||
{/* eslint-disable-next-line @next/next/no-img-element */}
|
{/* eslint-disable-next-line @next/next/no-img-element */}
|
||||||
<img
|
<img
|
||||||
className="lg:object-contain h-auto object-cover bg-[#F2F2F9] w-full"
|
className="lg:object-cover lg:h-full object-cover bg-[#F2F2F9] w-full"
|
||||||
src={foodImage}
|
src={foodImage}
|
||||||
alt={foodName}
|
alt={foodName}
|
||||||
onError={(event) => {
|
onError={(event) => {
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
import { useQuery } from "@tanstack/react-query";
|
import { useQuery } from "@tanstack/react-query";
|
||||||
import * as api from "../service/MenuService";
|
import * as api from "../service/MenuService";
|
||||||
import { useParams } from "next/navigation";
|
import { useParams } from "next/navigation";
|
||||||
|
import { hasAuthToken } from "@/lib/api/func";
|
||||||
|
|
||||||
export const useGetFoods = () => {
|
export const useGetFoods = () => {
|
||||||
const { name } = useParams<{ name: string }>();
|
const { name } = useParams<{ name: string }>();
|
||||||
@@ -26,5 +27,6 @@ export const useGetNotificationsCount = () => {
|
|||||||
return useQuery({
|
return useQuery({
|
||||||
queryKey: ["notifications-count"],
|
queryKey: ["notifications-count"],
|
||||||
queryFn: api.getNotificationsCount,
|
queryFn: api.getNotificationsCount,
|
||||||
|
enabled: hasAuthToken(),
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,13 +1,13 @@
|
|||||||
import { useMutation, useQuery } from "@tanstack/react-query";
|
import { useMutation, useQuery } from "@tanstack/react-query";
|
||||||
import * as api from "../service/ProfileService";
|
import * as api from "../service/ProfileService";
|
||||||
import { getToken } from "@/lib/api/func";
|
import { hasAuthToken } from "@/lib/api/func";
|
||||||
|
|
||||||
export const useGetProfile = () => {
|
export const useGetProfile = () => {
|
||||||
return useQuery({
|
return useQuery({
|
||||||
queryKey: ["profile"],
|
queryKey: ["profile"],
|
||||||
queryFn: api.getProfile,
|
queryFn: api.getProfile,
|
||||||
retry: false,
|
retry: false,
|
||||||
enabled: !!getToken(),
|
enabled: hasAuthToken(),
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,10 @@
|
|||||||
import { REFRESH_TOKEN_NAME, TOKEN_NAME } from "@/config/const";
|
import { REFRESH_TOKEN_NAME, TOKEN_NAME } from "@/config/const";
|
||||||
|
|
||||||
|
export const hasAuthToken = (): boolean => {
|
||||||
|
if (typeof window === "undefined") return false;
|
||||||
|
return !!localStorage.getItem(TOKEN_NAME);
|
||||||
|
};
|
||||||
|
|
||||||
export const getToken = async (): Promise<string | null> => {
|
export const getToken = async (): Promise<string | null> => {
|
||||||
if (typeof window === "undefined") return null;
|
if (typeof window === "undefined") return null;
|
||||||
return localStorage.getItem(TOKEN_NAME);
|
return localStorage.getItem(TOKEN_NAME);
|
||||||
|
|||||||
Reference in New Issue
Block a user