Upgrade swr to 1.0.1

This commit is contained in:
Kalle (Sendou) 2021-09-18 21:54:50 +03:00
parent 4c54b12273
commit b59ba4908e
15 changed files with 31 additions and 22 deletions

View File

@ -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<HTMLDivElement>;
}) => {
const { mutate } = useSWRConfig();
const addLikeMutation = useMutation<{ postId: number }>({
url: "/api/free-agents/likes",
method: "POST",

View File

@ -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<SuggestionsData>({
resolver: zodResolver(resuggestionSchema),
});
const { mutate } = useSWRConfig();
const suggestionMutation = useMutation<SuggestionsData>({
url: "/api/plus/suggestions",

View File

@ -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<Props> = ({ userPlusMembershipTier }) => {
useForm<SuggestionsData>({
resolver: zodResolver(suggestionFullSchema),
});
const { mutate } = useSWRConfig();
const suggestionMutation = useMutation<SuggestionsData>({
url: "/api/plus/suggestions",

View File

@ -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<Props> = ({ 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);

View File

@ -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<typeof teamSchema>;
const TeamProfileModal: React.FC<Props> = ({ team, closeModal }) => {
const { i18n } = useLingui();
const toast = useToast();
const { mutate } = useSWRConfig();
const [sending, setSending] = useState(false);
const { handleSubmit, errors, register, watch } = useForm<FormData>({

View File

@ -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<Props> = ({ 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<FormData>({
resolver: zodResolver(buildSchema),

View File

@ -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<typeof profileSchemaFrontend>;
const ProfileModal: React.FC<Props> = ({ onClose, user }) => {
const [sending, setSending] = useState(false);
const { i18n } = useLingui();
const { mutate } = useSWRConfig();
const { handleSubmit, errors, register, watch, control } = useForm<FormData>({
resolver: zodResolver(profileSchemaFrontend),

View File

@ -63,7 +63,7 @@ export function useFreeAgents(postsInitialData: FreeAgentsGet) {
const [user] = useUser();
const posts = useSWR<FreeAgentsGet>("/api/free-agents", {
initialData: postsInitialData,
fallbackData: postsInitialData,
});
const usersPost = posts.data?.find(

14
package-lock.json generated
View File

@ -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"
}

View File

@ -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"

View File

@ -22,7 +22,7 @@ interface Props {
const CalendarPage = ({ eventsInitialData }: Props) => {
const events = useSWR<CalendarGet>("/api/calendar", {
initialData: eventsInitialData,
fallbackData: eventsInitialData,
});
const [eventToEdit, setEventToEdit] = useState<
boolean | (FormData & { id: number })

View File

@ -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";

View File

@ -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<typeof salmonRunRecordSchema>;
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<FormData>({

View File

@ -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<GetTeamData>["roster"]) => {
const TeamPage: React.FC<Props> = (props) => {
const { data } = useSWR<GetTeamData>(`/api/teams/${props.team!.id}`, {
initialData: props.team!,
fallbackData: props.team!,
});
const team = data!;
@ -108,6 +108,7 @@ const TeamPage: React.FC<Props> = (props) => {
const [profileModalIsOpen, setProfileModalIsOpen] = useState(false);
const [user] = useUser();
const toast = useToast();
const { mutate } = useSWRConfig();
useEffect(() => {
mutate(`/api/teams/${props.team!.id}`);

View File

@ -53,7 +53,7 @@ const ProfilePage = (props: Props) => {
const [loggedInUser] = useUser();
const { data, mutate } = useSWR<GetUserByIdentifierData>(apiUrl(), {
initialData: props.user,
fallbackData: props.user,
});
const user = data ? data : props.user!;