react-toolkits 2.13.34 → 2.13.35

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # react-toolkits
2
2
 
3
+ ## 2.13.35
4
+
5
+ ### Patch Changes
6
+
7
+ - 36f96c7: fix: swr cache not been cleared
8
+
3
9
  ## 2.13.34
4
10
 
5
11
  ### Patch Changes
package/lib/index.d.ts CHANGED
@@ -439,7 +439,7 @@ interface MenuListItem {
439
439
  }
440
440
 
441
441
  declare function usePermission(code?: string, config?: AxiosRequestConfig): SWRResponse<boolean>;
442
- declare function usePermission(code?: string[], config?: AxiosRequestConfig): SWRResponse<true> | SWRResponse<Record<string, boolean>>;
442
+ declare function usePermission(code?: string[], config?: AxiosRequestConfig): SWRResponse<Record<string, boolean>>;
443
443
  declare function useMenuList(): SWRResponse<MenuListItem[], any, any>;
444
444
 
445
445
  declare const _default$2: react_jsx_runtime.JSX.Element;
package/lib/index.js CHANGED
@@ -634,15 +634,21 @@ function usePermission(code, config) {
634
634
  (args) => axios2.post(...args).then((response) => response.data.data)
635
635
  );
636
636
  let newData;
637
- if (typeof code === "undefined" || Array.isArray(code) && code.length === 0) {
638
- newData = true;
639
- } else if (typeof code === "string") {
640
- newData = data?.has_all ? true : data?.[code] ?? false;
641
- } else {
642
- newData = permissionCodes.reduce((acc, curr) => {
643
- acc[curr] = data?.has_all ? true : data?.[curr] ?? false;
644
- return acc;
645
- }, {});
637
+ if (data !== void 0) {
638
+ if (typeof code === "undefined") {
639
+ newData = true;
640
+ } else if (typeof code === "string") {
641
+ newData = data.has_all ? true : data[code] ?? false;
642
+ } else {
643
+ if (code.length === 0) {
644
+ newData = { [code[0]]: true };
645
+ } else {
646
+ newData = permissionCodes.reduce((acc, curr) => {
647
+ acc[curr] = data.has_all ? true : data[curr] ?? false;
648
+ return acc;
649
+ }, {});
650
+ }
651
+ }
646
652
  }
647
653
  return {
648
654
  ...rest,
@@ -919,16 +925,23 @@ var init_GameSelect = __esm({
919
925
  const { t } = useTranslation();
920
926
  const { gameApiV2, gameId, setGameId } = useToolkitsStore((s) => s);
921
927
  const { data, isLoading } = useGames();
922
- const { mutate: mutate2 } = useSWRConfig();
928
+ const { cache } = useSWRConfig();
923
929
  const filteredData = data?.filter((item) => filter?.(item) ?? true);
924
930
  const _options = typeof options === "function" ? options(filteredData) : filteredData?.map((item) => ({
925
931
  label: item.name,
926
932
  value: gameApiV2 ? item.game_id : item.id
927
933
  }));
928
- const onChange = async (value) => {
929
- await mutate2((key) => key !== "/api/game/list" && key !== "/api/usystem/game/all", void 0, false);
934
+ const onChange = (value) => {
935
+ clearCache();
930
936
  setGameId(value);
931
937
  };
938
+ const clearCache = () => {
939
+ for (const key of cache.keys()) {
940
+ if (key !== "/api/game/list" && key !== "/api/usystem/game/all") {
941
+ cache.delete(key);
942
+ }
943
+ }
944
+ };
932
945
  useEffect(() => {
933
946
  if (data && data.length > 0) {
934
947
  const firstId = gameApiV2 ? data[0].game_id : data[0].id;