From b59ba4908e0132072b38828b8cc51242de00c854 Mon Sep 17 00:00:00 2001 From: "Kalle (Sendou)" <38327916+Sendouc@users.noreply.github.com> Date: Sat, 18 Sep 2021 21:54:50 +0300 Subject: [PATCH] Upgrade swr to 1.0.1 --- components/freeagents/FreeAgentSection.tsx | 3 ++- components/plus/Suggestion.tsx | 3 ++- components/plus/SuggestionModal.tsx | 3 ++- components/t/TeamManagementModal.tsx | 3 ++- components/t/TeamProfileModal.tsx | 3 ++- components/u/BuildModal.tsx | 3 ++- components/u/ProfileModal.tsx | 3 ++- hooks/freeagents.ts | 2 +- package-lock.json | 14 +++++++------- package.json | 2 +- pages/calendar.tsx | 2 +- pages/sr/leaderboards/admin.tsx | 2 +- pages/sr/leaderboards/new.tsx | 3 ++- pages/t/[team].tsx | 5 +++-- pages/u/[identifier].tsx | 2 +- 15 files changed, 31 insertions(+), 22 deletions(-) diff --git a/components/freeagents/FreeAgentSection.tsx b/components/freeagents/FreeAgentSection.tsx index 626e1c63e..b3f3b031f 100644 --- a/components/freeagents/FreeAgentSection.tsx +++ b/components/freeagents/FreeAgentSection.tsx @@ -20,8 +20,8 @@ import { } from "react-icons/ri"; import { Unpacked } from "utils/types"; import { FreeAgentsGet } from "pages/api/free-agents"; -import { mutate } from "swr"; import { useMutation } from "hooks/common"; +import { useSWRConfig } from "swr"; const playstyleToEmoji = { FRONTLINE: RiSwordLine, @@ -44,6 +44,7 @@ const FreeAgentSection = ({ showPlusServerMembership: boolean; postRef?: RefObject; }) => { + const { mutate } = useSWRConfig(); const addLikeMutation = useMutation<{ postId: number }>({ url: "/api/free-agents/likes", method: "POST", diff --git a/components/plus/Suggestion.tsx b/components/plus/Suggestion.tsx index a025c2a83..ad119d16c 100644 --- a/components/plus/Suggestion.tsx +++ b/components/plus/Suggestion.tsx @@ -17,7 +17,7 @@ import { useMutation } from "hooks/common"; import type { SuggestionsGet } from "pages/api/plus/suggestions"; import { useState } from "react"; import { useForm } from "react-hook-form"; -import { mutate } from "swr"; +import { useSWRConfig } from "swr"; import { getVotingRange } from "utils/plus"; import { getFullUsername } from "utils/strings"; import { Unpacked } from "utils/types"; @@ -40,6 +40,7 @@ const Suggestion = ({ const { handleSubmit, errors, register, watch } = useForm({ resolver: zodResolver(resuggestionSchema), }); + const { mutate } = useSWRConfig(); const suggestionMutation = useMutation({ url: "/api/plus/suggestions", diff --git a/components/plus/SuggestionModal.tsx b/components/plus/SuggestionModal.tsx index a8750a040..de65e5eff 100644 --- a/components/plus/SuggestionModal.tsx +++ b/components/plus/SuggestionModal.tsx @@ -19,7 +19,7 @@ import UserSelector from "components/common/UserSelector"; import { useMutation } from "hooks/common"; import { useState } from "react"; import { Controller, useForm } from "react-hook-form"; -import { mutate } from "swr"; +import { useSWRConfig } from "swr"; import { suggestionFullSchema, SUGGESTION_DESCRIPTION_LIMIT, @@ -38,6 +38,7 @@ const SuggestionModal: React.FC = ({ userPlusMembershipTier }) => { useForm({ resolver: zodResolver(suggestionFullSchema), }); + const { mutate } = useSWRConfig(); const suggestionMutation = useMutation({ url: "/api/plus/suggestions", diff --git a/components/t/TeamManagementModal.tsx b/components/t/TeamManagementModal.tsx index 8a70768a0..96b87250e 100644 --- a/components/t/TeamManagementModal.tsx +++ b/components/t/TeamManagementModal.tsx @@ -20,7 +20,7 @@ import { useRouter } from "next/router"; import { GetTeamData } from "prisma/queries/getTeam"; import { Fragment, useEffect, useState } from "react"; import { FiCheck, FiTrash, FiUsers } from "react-icons/fi"; -import { mutate } from "swr"; +import { useSWRConfig } from "swr"; import { getToastOptions } from "utils/objects"; import { sendData } from "utils/postData"; @@ -31,6 +31,7 @@ interface Props { const TeamManagementModal: React.FC = ({ team }) => { const router = useRouter(); const toast = useToast(); + const { mutate } = useSWRConfig(); const [isOpen, setIsOpen] = useState(false); const [sending, setSending] = useState(false); const [copied, setCopied] = useState(false); diff --git a/components/t/TeamProfileModal.tsx b/components/t/TeamProfileModal.tsx index 2ea4604d7..2479805f1 100644 --- a/components/t/TeamProfileModal.tsx +++ b/components/t/TeamProfileModal.tsx @@ -25,7 +25,7 @@ import { GetTeamData } from "prisma/queries/getTeam"; import { useState } from "react"; import { useForm } from "react-hook-form"; import { FaTwitter } from "react-icons/fa"; -import { mutate } from "swr"; +import { useSWRConfig } from "swr"; import { getToastOptions } from "utils/objects"; import { sendData } from "utils/postData"; import { @@ -45,6 +45,7 @@ type FormData = z.infer; const TeamProfileModal: React.FC = ({ team, closeModal }) => { const { i18n } = useLingui(); const toast = useToast(); + const { mutate } = useSWRConfig(); const [sending, setSending] = useState(false); const { handleSubmit, errors, register, watch } = useForm({ diff --git a/components/u/BuildModal.tsx b/components/u/BuildModal.tsx index 7b15139af..c3d1a65d8 100644 --- a/components/u/BuildModal.tsx +++ b/components/u/BuildModal.tsx @@ -30,7 +30,7 @@ import { GetBuildsByUserData } from "prisma/queries/getBuildsByUser"; import { useState } from "react"; import { Controller, useForm } from "react-hook-form"; import { FiTrash } from "react-icons/fi"; -import { mutate } from "swr"; +import { useSWRConfig } from "swr"; import { weapons } from "utils/lists/weapons"; import { getToastOptions } from "utils/objects"; import { sendData } from "utils/postData"; @@ -55,6 +55,7 @@ const BuildModal: React.FC = ({ onClose, build, weaponFromQuery }) => { const [sending, setSending] = useState(false); const [deleting, setDeleting] = useState(false); const [loggedInUser] = useUser(); + const { mutate } = useSWRConfig(); const { handleSubmit, errors, register, watch, control } = useForm({ resolver: zodResolver(buildSchema), diff --git a/components/u/ProfileModal.tsx b/components/u/ProfileModal.tsx index 7aae145ed..1cb220b68 100644 --- a/components/u/ProfileModal.tsx +++ b/components/u/ProfileModal.tsx @@ -27,7 +27,7 @@ import { GetUserByIdentifierData } from "prisma/queries/getUserByIdentifier"; import { useState } from "react"; import { Controller, useForm } from "react-hook-form"; import { FaGamepad, FaTwitch, FaTwitter, FaYoutube } from "react-icons/fa"; -import { mutate } from "swr"; +import { useSWRConfig } from "swr"; import { getToastOptions } from "utils/objects"; import { sendData } from "utils/postData"; import { @@ -76,6 +76,7 @@ type FormData = z.infer; const ProfileModal: React.FC = ({ onClose, user }) => { const [sending, setSending] = useState(false); const { i18n } = useLingui(); + const { mutate } = useSWRConfig(); const { handleSubmit, errors, register, watch, control } = useForm({ resolver: zodResolver(profileSchemaFrontend), diff --git a/hooks/freeagents.ts b/hooks/freeagents.ts index 5c744b487..1a246ef0d 100644 --- a/hooks/freeagents.ts +++ b/hooks/freeagents.ts @@ -63,7 +63,7 @@ export function useFreeAgents(postsInitialData: FreeAgentsGet) { const [user] = useUser(); const posts = useSWR("/api/free-agents", { - initialData: postsInitialData, + fallbackData: postsInitialData, }); const usersPost = posts.data?.find( diff --git a/package-lock.json b/package-lock.json index 0243c9cdf..33464ca66 100644 --- a/package-lock.json +++ b/package-lock.json @@ -41,7 +41,7 @@ "react-string-replace": "^0.4.4", "recharts": "^2.1.2", "remark-gfm": "^1.0.0", - "swr": "^0.5.6", + "swr": "^1.0.1", "ts-trueskill": "^3.2.2", "uuid": "^8.3.2", "zod": "^1.11.17" @@ -9135,9 +9135,9 @@ } }, "node_modules/swr": { - "version": "0.5.6", - "resolved": "https://registry.npmjs.org/swr/-/swr-0.5.6.tgz", - "integrity": "sha512-Bmx3L4geMZjYT5S2Z6EE6/5Cx6v1Ka0LhqZKq8d6WL2eu9y6gHWz3dUzfIK/ymZVHVfwT/EweFXiYGgfifei3w==", + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/swr/-/swr-1.0.1.tgz", + "integrity": "sha512-EPQAxSjoD4IaM49rpRHK0q+/NzcwoT8c0/Ylu/u3/6mFj/CWnQVjNJ0MV2Iuw/U+EJSd2TX5czdAwKPYZIG0YA==", "dependencies": { "dequal": "2.0.2" }, @@ -17386,9 +17386,9 @@ } }, "swr": { - "version": "0.5.6", - "resolved": "https://registry.npmjs.org/swr/-/swr-0.5.6.tgz", - "integrity": "sha512-Bmx3L4geMZjYT5S2Z6EE6/5Cx6v1Ka0LhqZKq8d6WL2eu9y6gHWz3dUzfIK/ymZVHVfwT/EweFXiYGgfifei3w==", + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/swr/-/swr-1.0.1.tgz", + "integrity": "sha512-EPQAxSjoD4IaM49rpRHK0q+/NzcwoT8c0/Ylu/u3/6mFj/CWnQVjNJ0MV2Iuw/U+EJSd2TX5czdAwKPYZIG0YA==", "requires": { "dequal": "2.0.2" } diff --git a/package.json b/package.json index 9313e0d22..7c18a939b 100644 --- a/package.json +++ b/package.json @@ -57,7 +57,7 @@ "react-string-replace": "^0.4.4", "recharts": "^2.1.2", "remark-gfm": "^1.0.0", - "swr": "^0.5.6", + "swr": "^1.0.1", "ts-trueskill": "^3.2.2", "uuid": "^8.3.2", "zod": "^1.11.17" diff --git a/pages/calendar.tsx b/pages/calendar.tsx index 9831384d8..181b53789 100644 --- a/pages/calendar.tsx +++ b/pages/calendar.tsx @@ -22,7 +22,7 @@ interface Props { const CalendarPage = ({ eventsInitialData }: Props) => { const events = useSWR("/api/calendar", { - initialData: eventsInitialData, + fallbackData: eventsInitialData, }); const [eventToEdit, setEventToEdit] = useState< boolean | (FormData & { id: number }) diff --git a/pages/sr/leaderboards/admin.tsx b/pages/sr/leaderboards/admin.tsx index d4e81c27c..d33f81ebf 100644 --- a/pages/sr/leaderboards/admin.tsx +++ b/pages/sr/leaderboards/admin.tsx @@ -13,7 +13,7 @@ import { useUser } from "hooks/common"; import { useRouter } from "next/router"; import { GetAllSalmonRunRecordsData } from "prisma/queries/getAllSalmonRunRecords"; import { useState } from "react"; -import useSWR, { mutate } from "swr"; +import useSWR from "swr"; import { SALMON_RUN_ADMIN_DISCORD_IDS } from "utils/constants"; import { sendData } from "utils/postData"; import { salmonRunCategoryToNatural } from "./new"; diff --git a/pages/sr/leaderboards/new.tsx b/pages/sr/leaderboards/new.tsx index 63778f20d..dc17563f1 100644 --- a/pages/sr/leaderboards/new.tsx +++ b/pages/sr/leaderboards/new.tsx @@ -23,7 +23,7 @@ import Image from "next/image"; import { useRouter } from "next/router"; import { useState } from "react"; import { Controller, useForm } from "react-hook-form"; -import { mutate } from "swr"; +import { useSWRConfig } from "swr"; import { sendData } from "utils/postData"; import { salmonRunRecordSchema } from "utils/validators/salmonRunRecord"; import * as z from "zod"; @@ -56,6 +56,7 @@ type FormData = z.infer; const AddRecordModal = () => { const { i18n } = useLingui(); const router = useRouter(); + const { mutate } = useSWRConfig(); const [sending, setSending] = useState(false); const [loggedInUser] = useUser(); const { handleSubmit, errors, register, control, watch } = useForm({ diff --git a/pages/t/[team].tsx b/pages/t/[team].tsx index d7cda768a..47d4172ca 100644 --- a/pages/t/[team].tsx +++ b/pages/t/[team].tsx @@ -31,7 +31,7 @@ import { getTeam, GetTeamData } from "prisma/queries/getTeam"; import { Fragment, useEffect, useState } from "react"; import { FaTwitter } from "react-icons/fa"; import { FiEdit } from "react-icons/fi"; -import useSWR, { mutate } from "swr"; +import useSWR, { useSWRConfig } from "swr"; import { CSSVariables } from "utils/CSSVariables"; import { getToastOptions } from "utils/objects"; import { sendData } from "utils/postData"; @@ -100,7 +100,7 @@ const getTeamXPInfo = (roster: NonNullable["roster"]) => { const TeamPage: React.FC = (props) => { const { data } = useSWR(`/api/teams/${props.team!.id}`, { - initialData: props.team!, + fallbackData: props.team!, }); const team = data!; @@ -108,6 +108,7 @@ const TeamPage: React.FC = (props) => { const [profileModalIsOpen, setProfileModalIsOpen] = useState(false); const [user] = useUser(); const toast = useToast(); + const { mutate } = useSWRConfig(); useEffect(() => { mutate(`/api/teams/${props.team!.id}`); diff --git a/pages/u/[identifier].tsx b/pages/u/[identifier].tsx index c1946d59c..e8a0832d9 100644 --- a/pages/u/[identifier].tsx +++ b/pages/u/[identifier].tsx @@ -53,7 +53,7 @@ const ProfilePage = (props: Props) => { const [loggedInUser] = useUser(); const { data, mutate } = useSWR(apiUrl(), { - initialData: props.user, + fallbackData: props.user, }); const user = data ? data : props.user!;