Skip to content

Commit

Permalink
feat: support refresh the storage data (#49)
Browse files Browse the repository at this point in the history
  • Loading branch information
wqcstrong authored Oct 16, 2023
1 parent 72e8374 commit 581b534
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 14 deletions.
6 changes: 5 additions & 1 deletion src/pages/Devtools/StoragePanel/index.less
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
.storage-panel {
position: relative;
display: flex;
flex-direction: column;
justify-content: flex-end;
gap: 8px;
&__layout {
height: 100%;
flex: 1;
}
&__sider {
position: absolute;
Expand Down
32 changes: 25 additions & 7 deletions src/pages/Devtools/StoragePanel/index.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import type { SpyStorage } from '@huolala-tech/page-spy';
import { Layout, Menu, Table, Tooltip } from 'antd';
import { useMemo, useRef, useState } from 'react';
import { Button, Col, Layout, Menu, Row, Table, Tooltip } from 'antd';
import { useMemo, useState } from 'react';
import ReactJsonView from '@huolala-tech/react-json-view';
import './index.less';
import { useSocketMessageStore } from '@/store/socket-message';
import { Resizable } from 'react-resizable';
import { HolderOutlined } from '@ant-design/icons';
import { HolderOutlined, ReloadOutlined } from '@ant-design/icons';
import { useTranslation } from 'react-i18next';
import { capitalize } from 'lodash-es';

Expand All @@ -14,8 +14,12 @@ const { Column } = Table;

export const StoragePanel = () => {
const { t } = useTranslation();
const storageMsg = useSocketMessageStore((state) => state.storageMsg);
const [activeTab, setActiveTab] = useState<SpyStorage.DataType>('local');
const [storageMsg, refresh] = useSocketMessageStore((state) => [
state.storageMsg,
state.refresh,
]);
const [activeTab, setActiveTab] =
useState<SpyStorage.DataType>('localStorage');
const data = useMemo(() => {
return Object.values(storageMsg[activeTab]);
}, [activeTab, storageMsg]);
Expand All @@ -28,6 +32,19 @@ export const StoragePanel = () => {
const [detailInfo, setDetailInfo] = useState('');
return (
<div className="storage-panel">
<Row justify="end">
<Col>
<Tooltip title={t('common.refresh')}>
<Button
onClick={() => {
refresh(activeTab);
}}
>
<ReloadOutlined />
</Button>
</Tooltip>
</Col>
</Row>
<Layout className="storage-panel__layout">
<Sider className="storage-panel__sider">
<Menu
Expand All @@ -36,15 +53,16 @@ export const StoragePanel = () => {
selectedKeys={[activeTab]}
onSelect={({ key }) => setActiveTab(key as SpyStorage.DataType)}
items={[
{ key: 'local', label: 'Local Storage' },
{ key: 'session', label: 'Session Storage' },
{ key: 'localStorage', label: 'Local Storage' },
{ key: 'sessionStorage', label: 'Session Storage' },
{ key: 'cookie', label: 'Cookie' },
]}
/>
</Sider>
<Layout>
<Content className="storage-panel__content">
<Table
rowKey="name"
bordered={false}
dataSource={data}
pagination={false}
Expand Down
12 changes: 6 additions & 6 deletions src/store/socket-message/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ interface SocketMessage {
Record<string, Omit<SpyStorage.DataItem, 'type' | 'action'>>
>;
initSocket: (url: string) => void;
clearRecord: (key: SpyMessage.MessageType) => void;
refresh: (key: SpyMessage.MessageType) => void;
clearRecord: (key: string) => void;
refresh: (key: string) => void;
}

export const useSocketMessageStore = create<SocketMessage>((set, get) => ({
Expand All @@ -49,8 +49,8 @@ export const useSocketMessageStore = create<SocketMessage>((set, get) => ({
location: null,
},
storageMsg: {
local: {},
session: {},
localStorage: {},
sessionStorage: {},
cookie: {},
},
initSocket: (room: string) => {
Expand Down Expand Up @@ -161,7 +161,7 @@ export const useSocketMessageStore = create<SocketMessage>((set, get) => ({
}
});
},
clearRecord: (key: SpyMessage.MessageType) => {
clearRecord: (key: string) => {
switch (key) {
case 'console':
set({ consoleMsg: [] });
Expand All @@ -173,7 +173,7 @@ export const useSocketMessageStore = create<SocketMessage>((set, get) => ({
break;
}
},
refresh: (key: SpyMessage.MessageType) => {
refresh: (key: string) => {
const socket = get().socket;
if (!socket) return;
socket.unicastMessage({
Expand Down

0 comments on commit 581b534

Please sign in to comment.