Skip to content

Commit

Permalink
chore(deps-dev): bump swr from 2.2.4 to 2.2.5 (#10538)
Browse files Browse the repository at this point in the history
  • Loading branch information
dependabot[bot] committed Feb 21, 2024
1 parent 74c1448 commit 4cc6e36
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 12 deletions.
15 changes: 12 additions & 3 deletions client/src/plus/collections/api.ts
@@ -1,6 +1,6 @@
import { useState } from "react";
import useSWR, { KeyedMutator, mutate, SWRResponse } from "swr";
import useSWRInfinite from "swr/infinite";
import useSWRInfinite, { SWRInfiniteResponse } from "swr/infinite";
import {
MultipleCollectionInfo,
MultipleCollectionResponse,
Expand All @@ -10,6 +10,11 @@ import {
CollectionItemModificationRequest,
} from "./rust-types";

// "swr/infinite" doesn't export InfiniteKeyedMutator directly
type InfiniteKeyedMutator<T> = SWRInfiniteResponse<
T extends (infer I)[] ? I : T
>["mutate"];

export interface NewCollection {
name: string;
description?: string;
Expand Down Expand Up @@ -288,7 +293,9 @@ export function useItemAdd() {
);
}

export function useItemEdit(scopedMutator?: KeyedMutator<Item[][]>) {
export function useItemEdit(
scopedMutator?: KeyedMutator<Item[][]> | InfiniteKeyedMutator<Item[][]>
) {
return useMutation<Item, Response>(
({ collection_id, id, ...body }) =>
poster<CollectionItemModificationRequest>(
Expand All @@ -303,7 +310,9 @@ export function useItemEdit(scopedMutator?: KeyedMutator<Item[][]>) {
);
}

export function useItemDelete(scopedMutator?: KeyedMutator<Item[][]>) {
export function useItemDelete(
scopedMutator?: KeyedMutator<Item[][]> | InfiniteKeyedMutator<Item[][]>
) {
return useMutation<Item, Response>(
({ collection_id, id }) => deleter(getItemKey(collection_id, id)),
({ collection_id, url }) => {
Expand Down
8 changes: 7 additions & 1 deletion client/src/plus/collections/collection.tsx
Expand Up @@ -2,6 +2,7 @@ import { useEffect, useState } from "react";
import { useParams } from "react-router";
import { Link } from "react-router-dom";
import useSWR, { KeyedMutator } from "swr";
import { SWRInfiniteResponse } from "swr/infinite";
import { useScrollToTop, useLocale } from "../../hooks";
import { Button } from "../../ui/atoms/button";
import Container from "../../ui/atoms/container";
Expand All @@ -26,6 +27,11 @@ import { useGleanClick } from "../../telemetry/glean-context";
import { PLUS_COLLECTIONS } from "../../telemetry/constants";
dayjs.extend(relativeTime);

// "swr/infinite" doesn't export InfiniteKeyedMutator directly
type InfiniteKeyedMutator<T> = SWRInfiniteResponse<
T extends (infer I)[] ? I : T
>["mutate"];

export function CollectionComponent() {
const { collectionId } = useParams();
const { data: collection, error: collectionError } =
Expand Down Expand Up @@ -170,7 +176,7 @@ function ItemComponent({
}: {
addNoteEnabled?: boolean;
item: Item | FrequentlyViewedItem;
mutate?: KeyedMutator<Item[][]>;
mutate?: KeyedMutator<Item[][]> | InfiniteKeyedMutator<Item[][]>;
}) {
const [slicedNote, setSlicedNote] = useState<string>();
const [note, setNote] = useState<string>();
Expand Down
10 changes: 8 additions & 2 deletions client/src/ui/organisms/article-actions/bookmark-menu/index.tsx
Expand Up @@ -21,10 +21,16 @@ import { useGleanClick } from "../../../../telemetry/glean-context";
import { PLUS_COLLECTIONS } from "../../../../telemetry/constants";
import ExpandingTextarea from "../../../atoms/form/expanding-textarea";
import { KeyedMutator } from "swr";
import { SWRInfiniteResponse } from "swr/infinite";

import "./index.scss";
import { Overlay, useUIStatus } from "../../../../ui-context";

// "swr/infinite" doesn't export InfiniteKeyedMutator directly
type InfiniteKeyedMutator<T> = SWRInfiniteResponse<
T extends (infer I)[] ? I : T
>["mutate"];

const addValue = "add";

export default function BookmarkMenu({
Expand All @@ -34,7 +40,7 @@ export default function BookmarkMenu({
}: {
doc?: Doc | DocMetadata;
item?: Item;
scopedMutator?: KeyedMutator<Item[][]>;
scopedMutator?: KeyedMutator<Item[][]> | InfiniteKeyedMutator<Item[][]>;
}) {
const [show, setShow] = useState(false);
const [disableAutoClose, setDisableAutoClose] = useState(false);
Expand Down Expand Up @@ -101,7 +107,7 @@ function BookmarkMenuDropdown({
setSaved: React.Dispatch<React.SetStateAction<boolean>>;
setDisableAutoClose: React.Dispatch<React.SetStateAction<boolean>>;
item?: Item;
scopedMutator?: KeyedMutator<Item[][]>;
scopedMutator?: KeyedMutator<Item[][]> | InfiniteKeyedMutator<Item[][]>;
}) {
const { data: collections } = useCollections();
const { data: savedItems } = useBookmark(doc.mdn_url);
Expand Down
8 changes: 7 additions & 1 deletion client/src/ui/organisms/article-actions/index.tsx
Expand Up @@ -12,8 +12,14 @@ import BookmarkMenu from "./bookmark-menu";
import { Overlay, useUIStatus } from "../../../ui-context";
import { useEffect, useState } from "react";
import { KeyedMutator } from "swr";
import { SWRInfiniteResponse } from "swr/infinite";
import { Item } from "../../../plus/collections/api";

// "swr/infinite" doesn't export InfiniteKeyedMutator directly
type InfiniteKeyedMutator<T> = SWRInfiniteResponse<
T extends (infer I)[] ? I : T
>["mutate"];

export const ArticleActions = ({
doc,
showTranslations = true,
Expand All @@ -23,7 +29,7 @@ export const ArticleActions = ({
doc?: Doc | DocMetadata;
showTranslations?: boolean;
item?: Item;
scopedMutator?: KeyedMutator<Item[][]>;
scopedMutator?: KeyedMutator<Item[][]> | InfiniteKeyedMutator<Item[][]>;
}) => {
const [showArticleActionsMenu, setShowArticleActionsMenu] = useState(false);
const userData = useUserData();
Expand Down
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -251,7 +251,7 @@
"stylelint-order": "^6.0.4",
"stylelint-prettier": "^4.1.0",
"stylelint-scss": "^5.3.2",
"swr": "^2.2.4",
"swr": "^2.2.5",
"tailwindcss": "^3.4.1",
"terser-webpack-plugin": "^5.3.10",
"ts-jest": "^29.1.2",
Expand Down
8 changes: 4 additions & 4 deletions yarn.lock
Expand Up @@ -14441,10 +14441,10 @@ svgo@^3.2.0:
csso "^5.0.5"
picocolors "^1.0.0"

swr@^2.2.4:
version "2.2.4"
resolved "https://registry.yarnpkg.com/swr/-/swr-2.2.4.tgz#03ec4c56019902fbdc904d78544bd7a9a6fa3f07"
integrity sha512-njiZ/4RiIhoOlAaLYDqwz5qH/KZXVilRLvomrx83HjzCWTfa+InyfAjv05PSFxnmLzZkNO9ZfvgoqzAaEI4sGQ==
swr@^2.2.5:
version "2.2.5"
resolved "https://registry.yarnpkg.com/swr/-/swr-2.2.5.tgz#063eea0e9939f947227d5ca760cc53696f46446b"
integrity sha512-QtxqyclFeAsxEUeZIYmsaQ0UjimSq1RZ9Un7I68/0ClKK/U3LoyQunwkQfJZr2fc22DfIXLNDc2wFyTEikCUpg==
dependencies:
client-only "^0.0.1"
use-sync-external-store "^1.2.0"
Expand Down

0 comments on commit 4cc6e36

Please sign in to comment.