add initialData to queries
This commit is contained in:
parent
75b1ae738f
commit
a73e5fa6c6
|
@ -20,7 +20,7 @@ type Props = {
|
||||||
export default function CollectionCard({ collection, className }: Props) {
|
export default function CollectionCard({ collection, className }: Props) {
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
const { settings } = useLocalSettingsStore();
|
const { settings } = useLocalSettingsStore();
|
||||||
const { data: user = [] } = useUser();
|
const { data: user } = useUser();
|
||||||
|
|
||||||
const formattedDate = new Date(collection.createdAt as string).toLocaleString(
|
const formattedDate = new Date(collection.createdAt as string).toLocaleString(
|
||||||
"en-US",
|
"en-US",
|
||||||
|
|
|
@ -25,9 +25,9 @@ interface ExtendedTreeItem extends TreeItem {
|
||||||
const CollectionListing = () => {
|
const CollectionListing = () => {
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
const updateCollection = useUpdateCollection();
|
const updateCollection = useUpdateCollection();
|
||||||
const { data: collections = [] } = useCollections();
|
const { data: collections } = useCollections();
|
||||||
|
|
||||||
const { data: user = [] } = useUser();
|
const { data: user } = useUser();
|
||||||
const updateUser = useUpdateUser();
|
const updateUser = useUpdateUser();
|
||||||
|
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
|
|
|
@ -24,7 +24,7 @@ export default function CollectionSelection({
|
||||||
showDefaultValue = true,
|
showDefaultValue = true,
|
||||||
creatable = true,
|
creatable = true,
|
||||||
}: Props) {
|
}: Props) {
|
||||||
const { data: collections = [] } = useCollections();
|
const { data: collections } = useCollections();
|
||||||
|
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
|
|
||||||
|
|
|
@ -13,7 +13,7 @@ type Props = {
|
||||||
};
|
};
|
||||||
|
|
||||||
export default function TagSelection({ onChange, defaultValue }: Props) {
|
export default function TagSelection({ onChange, defaultValue }: Props) {
|
||||||
const { data: tags = [] } = useTags();
|
const { data: tags } = useTags();
|
||||||
|
|
||||||
const [options, setOptions] = useState<Options[]>([]);
|
const [options, setOptions] = useState<Options[]>([]);
|
||||||
|
|
||||||
|
|
|
@ -34,9 +34,9 @@ export default function LinkCard({ link, flipDropdown, editMode }: Props) {
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
|
|
||||||
const viewMode = localStorage.getItem("viewMode") || "card";
|
const viewMode = localStorage.getItem("viewMode") || "card";
|
||||||
const { data: collections = [] } = useCollections();
|
const { data: collections } = useCollections();
|
||||||
|
|
||||||
const { data: user = [] } = useUser();
|
const { data: user } = useUser();
|
||||||
|
|
||||||
const { links, getLink, setSelectedLinks, selectedLinks } = useLinkStore();
|
const { links, getLink, setSelectedLinks, selectedLinks } = useLinkStore();
|
||||||
|
|
||||||
|
|
|
@ -39,7 +39,7 @@ export default function LinkActions({
|
||||||
const [deleteLinkModal, setDeleteLinkModal] = useState(false);
|
const [deleteLinkModal, setDeleteLinkModal] = useState(false);
|
||||||
const [preservedFormatsModal, setPreservedFormatsModal] = useState(false);
|
const [preservedFormatsModal, setPreservedFormatsModal] = useState(false);
|
||||||
|
|
||||||
const { data: user = [] } = useUser();
|
const { data: user } = useUser();
|
||||||
|
|
||||||
const { removeLink, updateLink } = useLinkStore();
|
const { removeLink, updateLink } = useLinkStore();
|
||||||
|
|
||||||
|
|
|
@ -33,9 +33,9 @@ export default function LinkCardCompact({
|
||||||
}: Props) {
|
}: Props) {
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
|
|
||||||
const { data: collections = [] } = useCollections();
|
const { data: collections } = useCollections();
|
||||||
|
|
||||||
const { data: user = [] } = useUser();
|
const { data: user } = useUser();
|
||||||
const { links, setSelectedLinks, selectedLinks } = useLinkStore();
|
const { links, setSelectedLinks, selectedLinks } = useLinkStore();
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
|
|
@ -33,8 +33,8 @@ type Props = {
|
||||||
export default function LinkMasonry({ link, flipDropdown, editMode }: Props) {
|
export default function LinkMasonry({ link, flipDropdown, editMode }: Props) {
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
|
|
||||||
const { data: collections = [] } = useCollections();
|
const { data: collections } = useCollections();
|
||||||
const { data: user = [] } = useUser();
|
const { data: user } = useUser();
|
||||||
|
|
||||||
const { links, getLink, setSelectedLinks, selectedLinks } = useLinkStore();
|
const { links, getLink, setSelectedLinks, selectedLinks } = useLinkStore();
|
||||||
|
|
||||||
|
|
|
@ -46,7 +46,7 @@ export default function EditCollectionSharingModal({
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const { data: user = [] } = useUser();
|
const { data: user } = useUser();
|
||||||
const permissions = usePermissions(collection.id as number);
|
const permissions = usePermissions(collection.id as number);
|
||||||
|
|
||||||
const currentURL = new URL(document.URL);
|
const currentURL = new URL(document.URL);
|
||||||
|
|
|
@ -43,7 +43,7 @@ export default function NewLinkModal({ onClose }: Props) {
|
||||||
const [submitLoader, setSubmitLoader] = useState(false);
|
const [submitLoader, setSubmitLoader] = useState(false);
|
||||||
const [optionsExpanded, setOptionsExpanded] = useState(false);
|
const [optionsExpanded, setOptionsExpanded] = useState(false);
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
const { data: collections = [] } = useCollections();
|
const { data: collections } = useCollections();
|
||||||
|
|
||||||
const setCollection = (e: any) => {
|
const setCollection = (e: any) => {
|
||||||
if (e?.__isNew__) e.value = null;
|
if (e?.__isNew__) e.value = null;
|
||||||
|
|
|
@ -30,7 +30,7 @@ export default function PreservedFormatsModal({ onClose, activeLink }: Props) {
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
const session = useSession();
|
const session = useSession();
|
||||||
const { getLink } = useLinkStore();
|
const { getLink } = useLinkStore();
|
||||||
const { data: user = [] } = useUser();
|
const { data: user } = useUser();
|
||||||
const [link, setLink] =
|
const [link, setLink] =
|
||||||
useState<LinkIncludingShortenedCollectionAndTags>(activeLink);
|
useState<LinkIncludingShortenedCollectionAndTags>(activeLink);
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
|
|
|
@ -49,7 +49,7 @@ export default function UploadFileModal({ onClose }: Props) {
|
||||||
const [submitLoader, setSubmitLoader] = useState(false);
|
const [submitLoader, setSubmitLoader] = useState(false);
|
||||||
const [optionsExpanded, setOptionsExpanded] = useState(false);
|
const [optionsExpanded, setOptionsExpanded] = useState(false);
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
const { data: collections = [] } = useCollections();
|
const { data: collections } = useCollections();
|
||||||
|
|
||||||
const setCollection = (e: any) => {
|
const setCollection = (e: any) => {
|
||||||
if (e?.__isNew__) e.value = null;
|
if (e?.__isNew__) e.value = null;
|
||||||
|
|
|
@ -9,7 +9,7 @@ import { useUser } from "@/hooks/store/user";
|
||||||
export default function ProfileDropdown() {
|
export default function ProfileDropdown() {
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
const { settings, updateSettings } = useLocalSettingsStore();
|
const { settings, updateSettings } = useLocalSettingsStore();
|
||||||
const { data: user = [] } = useUser();
|
const { data: user } = useUser();
|
||||||
|
|
||||||
const isAdmin = user.id === Number(process.env.NEXT_PUBLIC_ADMIN || 1);
|
const isAdmin = user.id === Number(process.env.NEXT_PUBLIC_ADMIN || 1);
|
||||||
|
|
||||||
|
|
|
@ -46,7 +46,7 @@ export default function ReadableView({ link }: Props) {
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
|
|
||||||
const { getLink } = useLinkStore();
|
const { getLink } = useLinkStore();
|
||||||
const { data: collections = [] } = useCollections();
|
const { data: collections } = useCollections();
|
||||||
|
|
||||||
const collection = useMemo(() => {
|
const collection = useMemo(() => {
|
||||||
return collections.find(
|
return collections.find(
|
||||||
|
|
|
@ -22,9 +22,9 @@ export default function Sidebar({ className }: { className?: string }) {
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
const { data: collections = [] } = useCollections();
|
const { data: collections } = useCollections();
|
||||||
|
|
||||||
const { data: tags = [] } = useTags();
|
const { data: tags } = useTags();
|
||||||
const [active, setActive] = useState("");
|
const [active, setActive] = useState("");
|
||||||
|
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
|
|
|
@ -11,6 +11,7 @@ const useCollections = () => {
|
||||||
const data = await response.json();
|
const data = await response.json();
|
||||||
return data.response;
|
return data.response;
|
||||||
},
|
},
|
||||||
|
initialData: [],
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -13,6 +13,7 @@ const useTags = () => {
|
||||||
const data = await response.json();
|
const data = await response.json();
|
||||||
return data.response;
|
return data.response;
|
||||||
},
|
},
|
||||||
|
initialData: [],
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -14,6 +14,7 @@ const useTokens = () => {
|
||||||
const data = await response.json();
|
const data = await response.json();
|
||||||
return data.response as AccessToken[];
|
return data.response as AccessToken[];
|
||||||
},
|
},
|
||||||
|
initialData: [],
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -19,6 +19,7 @@ const useUser = () => {
|
||||||
return data.response;
|
return data.response;
|
||||||
},
|
},
|
||||||
enabled: !!userId,
|
enabled: !!userId,
|
||||||
|
initialData: {},
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -4,9 +4,9 @@ import { useCollections } from "./store/collections";
|
||||||
import { useUser } from "./store/user";
|
import { useUser } from "./store/user";
|
||||||
|
|
||||||
export default function useCollectivePermissions(collectionIds: number[]) {
|
export default function useCollectivePermissions(collectionIds: number[]) {
|
||||||
const { data: collections = [] } = useCollections();
|
const { data: collections } = useCollections();
|
||||||
|
|
||||||
const { data: user = [] } = useUser();
|
const { data: user } = useUser();
|
||||||
|
|
||||||
const [permissions, setPermissions] = useState<Member | true>();
|
const [permissions, setPermissions] = useState<Member | true>();
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
|
|
@ -6,7 +6,7 @@ import { useUser } from "./store/user";
|
||||||
export default function useInitialData() {
|
export default function useInitialData() {
|
||||||
const { status, data } = useSession();
|
const { status, data } = useSession();
|
||||||
// const { setLinks } = useLinkStore();
|
// const { setLinks } = useLinkStore();
|
||||||
const { data: user = [] } = useUser();
|
const { data: user } = useUser();
|
||||||
const { setSettings } = useLocalSettingsStore();
|
const { setSettings } = useLocalSettingsStore();
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
|
|
@ -4,9 +4,9 @@ import { useCollections } from "./store/collections";
|
||||||
import { useUser } from "./store/user";
|
import { useUser } from "./store/user";
|
||||||
|
|
||||||
export default function usePermissions(collectionId: number) {
|
export default function usePermissions(collectionId: number) {
|
||||||
const { data: collections = [] } = useCollections();
|
const { data: collections } = useCollections();
|
||||||
|
|
||||||
const { data: user = [] } = useUser();
|
const { data: user } = useUser();
|
||||||
|
|
||||||
const [permissions, setPermissions] = useState<Member | true>();
|
const [permissions, setPermissions] = useState<Member | true>();
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
|
|
@ -14,7 +14,7 @@ export default function AuthRedirect({ children }: Props) {
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
const { status } = useSession();
|
const { status } = useSession();
|
||||||
const [shouldRenderChildren, setShouldRenderChildren] = useState(false);
|
const [shouldRenderChildren, setShouldRenderChildren] = useState(false);
|
||||||
const { data: user = [] } = useUser();
|
const { data: user } = useUser();
|
||||||
|
|
||||||
useInitialData();
|
useInitialData();
|
||||||
|
|
||||||
|
|
|
@ -21,7 +21,7 @@ type UserModal = {
|
||||||
export default function Admin() {
|
export default function Admin() {
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
|
|
||||||
const { data: users = [] } = useUsers();
|
const { data: users } = useUsers();
|
||||||
|
|
||||||
const [searchQuery, setSearchQuery] = useState("");
|
const [searchQuery, setSearchQuery] = useState("");
|
||||||
const [filteredUsers, setFilteredUsers] = useState<User[]>();
|
const [filteredUsers, setFilteredUsers] = useState<User[]>();
|
||||||
|
|
|
@ -34,7 +34,7 @@ export default function Index() {
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
|
|
||||||
const { links } = useLinkStore();
|
const { links } = useLinkStore();
|
||||||
const { data: collections = [] } = useCollections();
|
const { data: collections } = useCollections();
|
||||||
|
|
||||||
const [sortBy, setSortBy] = useState<Sort>(Sort.DateNewestFirst);
|
const [sortBy, setSortBy] = useState<Sort>(Sort.DateNewestFirst);
|
||||||
|
|
||||||
|
@ -51,7 +51,7 @@ export default function Index() {
|
||||||
);
|
);
|
||||||
}, [router, collections]);
|
}, [router, collections]);
|
||||||
|
|
||||||
const { data: user = [] } = useUser();
|
const { data: user } = useUser();
|
||||||
|
|
||||||
const [collectionOwner, setCollectionOwner] = useState({
|
const [collectionOwner, setCollectionOwner] = useState({
|
||||||
id: null as unknown as number,
|
id: null as unknown as number,
|
||||||
|
|
|
@ -13,7 +13,7 @@ import { useCollections } from "@/hooks/store/collections";
|
||||||
|
|
||||||
export default function Collections() {
|
export default function Collections() {
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
const { data: collections = [] } = useCollections();
|
const { data: collections } = useCollections();
|
||||||
const [sortBy, setSortBy] = useState<Sort>(Sort.DateNewestFirst);
|
const [sortBy, setSortBy] = useState<Sort>(Sort.DateNewestFirst);
|
||||||
const [sortedCollections, setSortedCollections] = useState(collections);
|
const [sortedCollections, setSortedCollections] = useState(collections);
|
||||||
|
|
||||||
|
|
|
@ -22,9 +22,9 @@ import { useTags } from "@/hooks/store/tags";
|
||||||
|
|
||||||
export default function Dashboard() {
|
export default function Dashboard() {
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
const { data: collections = [] } = useCollections();
|
const { data: collections } = useCollections();
|
||||||
const { links } = useLinkStore();
|
const { links } = useLinkStore();
|
||||||
const { data: tags = [] } = useTags();
|
const { data: tags } = useTags();
|
||||||
|
|
||||||
const [numberOfLinks, setNumberOfLinks] = useState(0);
|
const [numberOfLinks, setNumberOfLinks] = useState(0);
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
import NoLinksFound from "@/components/NoLinksFound";
|
import NoLinksFound from "@/components/NoLinksFound";
|
||||||
import useLinks from "@/hooks/useLinks";
|
import useLinks from "@/hooks/useLinks";
|
||||||
|
// import { useLinks } from "@/hooks/store/links";
|
||||||
import MainLayout from "@/layouts/MainLayout";
|
import MainLayout from "@/layouts/MainLayout";
|
||||||
import useLinkStore from "@/store/links";
|
import useLinkStore from "@/store/links";
|
||||||
import React, { useEffect, useState } from "react";
|
import React, { useEffect, useState } from "react";
|
||||||
|
@ -15,6 +16,8 @@ import { useTranslation } from "next-i18next";
|
||||||
|
|
||||||
export default function Links() {
|
export default function Links() {
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
|
|
||||||
|
// const { data: links } = useLinks();
|
||||||
const { links } = useLinkStore();
|
const { links } = useLinkStore();
|
||||||
|
|
||||||
const [viewMode, setViewMode] = useState<string>(
|
const [viewMode, setViewMode] = useState<string>(
|
||||||
|
|
|
@ -32,7 +32,7 @@ export default function PublicCollections() {
|
||||||
|
|
||||||
const { settings } = useLocalSettingsStore();
|
const { settings } = useLocalSettingsStore();
|
||||||
|
|
||||||
const { data: collections = [] } = useCollections();
|
const { data: collections } = useCollections();
|
||||||
|
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
|
|
||||||
|
|
|
@ -18,7 +18,7 @@ export default function AccessTokens() {
|
||||||
setRevokeTokenModal(true);
|
setRevokeTokenModal(true);
|
||||||
};
|
};
|
||||||
|
|
||||||
const { data: tokens = [] } = useTokens();
|
const { data: tokens } = useTokens();
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<SettingsLayout>
|
<SettingsLayout>
|
||||||
|
|
|
@ -24,7 +24,7 @@ export default function Account() {
|
||||||
const [emailChangeVerificationModal, setEmailChangeVerificationModal] =
|
const [emailChangeVerificationModal, setEmailChangeVerificationModal] =
|
||||||
useState(false);
|
useState(false);
|
||||||
const [submitLoader, setSubmitLoader] = useState(false);
|
const [submitLoader, setSubmitLoader] = useState(false);
|
||||||
const { data: account = [] } = useUser();
|
const { data: account } = useUser();
|
||||||
const updateUser = useUpdateUser();
|
const updateUser = useUpdateUser();
|
||||||
const [user, setUser] = useState<AccountSettings>(
|
const [user, setUser] = useState<AccountSettings>(
|
||||||
!objectIsEmpty(account)
|
!objectIsEmpty(account)
|
||||||
|
|
|
@ -13,7 +13,7 @@ export default function Password() {
|
||||||
const [oldPassword, setOldPassword] = useState("");
|
const [oldPassword, setOldPassword] = useState("");
|
||||||
const [newPassword, setNewPassword] = useState("");
|
const [newPassword, setNewPassword] = useState("");
|
||||||
const [submitLoader, setSubmitLoader] = useState(false);
|
const [submitLoader, setSubmitLoader] = useState(false);
|
||||||
const { data: account = [] } = useUser();
|
const { data: account } = useUser();
|
||||||
const updateUser = useUpdateUser();
|
const updateUser = useUpdateUser();
|
||||||
|
|
||||||
const submit = async () => {
|
const submit = async () => {
|
||||||
|
|
|
@ -13,7 +13,7 @@ export default function Appearance() {
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
const { updateSettings } = useLocalSettingsStore();
|
const { updateSettings } = useLocalSettingsStore();
|
||||||
const [submitLoader, setSubmitLoader] = useState(false);
|
const [submitLoader, setSubmitLoader] = useState(false);
|
||||||
const { data: account = [] } = useUser();
|
const { data: account } = useUser();
|
||||||
const updateUser = useUpdateUser();
|
const updateUser = useUpdateUser();
|
||||||
const [user, setUser] = useState(account);
|
const [user, setUser] = useState(account);
|
||||||
|
|
||||||
|
|
|
@ -20,7 +20,7 @@ export default function Subscribe() {
|
||||||
|
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
|
|
||||||
const { data: user = [] } = useUser();
|
const { data: user } = useUser();
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const hasInactiveSubscription =
|
const hasInactiveSubscription =
|
||||||
|
|
|
@ -21,7 +21,7 @@ export default function Index() {
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
|
|
||||||
const { links } = useLinkStore();
|
const { links } = useLinkStore();
|
||||||
const { data: tags = [] } = useTags();
|
const { data: tags } = useTags();
|
||||||
const updateTag = useUpdateTag();
|
const updateTag = useUpdateTag();
|
||||||
const removeTag = useRemoveTag();
|
const removeTag = useRemoveTag();
|
||||||
|
|
||||||
|
|
Ŝarĝante…
Reference in New Issue