Skip to content

Commit

Permalink
Merge pull request #532 from antvis/fix/fix-assets-edit
Browse files Browse the repository at this point in the history
fix: fix issue that assets modify not effect
  • Loading branch information
Aarebecca authored Sep 27, 2023
2 parents 2ca5e6d + bd82c70 commit fc6174e
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions packages/gi-site/src/hooks/useUserInfo.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
import { useEffect, useState } from 'react';
import { getUser } from '../services/user';

const ASSETS_PACKAGES_KEY = 'GI_ASSETS_PACKAGES';
const VIP_ASSETS_RETRIEVED_KEY = 'GI_VIP_ASSETS_RETRIEVED';

export const setAssetPackages = newAssets => {
const prevAssets = JSON.parse(localStorage.getItem('GI_ASSETS_PACKAGES') || '{}');
const prevAssets = JSON.parse(localStorage.getItem(ASSETS_PACKAGES_KEY) || '{}');
newAssets.forEach(pkg => {
const { global } = pkg;
const prev = prevAssets[global];
Expand All @@ -12,18 +15,22 @@ export const setAssetPackages = newAssets => {
prevAssets[global] = pkg;
}
});
localStorage.setItem('GI_ASSETS_PACKAGES', JSON.stringify(prevAssets));
localStorage.setItem(ASSETS_PACKAGES_KEY, JSON.stringify(prevAssets));
};

export const getLoginUserInfo = async () => {
// 仅针对内网用户进行用户访问记录
try {
const result = await getUser();
if (result) {
const VIP_ASSETS = await fetch('https://unpkg.alipay.com/@alipay/gi-assets-vip@latest/json/assets.json').then(
res => res.json(),
);
setAssetPackages(VIP_ASSETS); //暂时移除从user中获取资产信息
if (!localStorage.getItem(VIP_ASSETS_RETRIEVED_KEY)) {
const VIP_ASSETS = await fetch('https://unpkg.alipay.com/@alipay/gi-assets-vip@latest/json/assets.json').then(
res => res.json(),
);
setAssetPackages(VIP_ASSETS);
localStorage.setItem(VIP_ASSETS_RETRIEVED_KEY, new Date().toLocaleString());
}

//@ts-ignore
window.GI_USER_INFO = result;
return result;
Expand Down

0 comments on commit fc6174e

Please sign in to comment.