diff --git a/src/components/DevCompanion.tsx b/src/components/DevCompanion.tsx index eb0c665..8b5fb10 100644 --- a/src/components/DevCompanion.tsx +++ b/src/components/DevCompanion.tsx @@ -1,8 +1,10 @@ import React, { useEffect, useState } from 'react'; import { initFetchInterceptor, NetworkLog } from '../core/fetchInterceptor'; +import { StorageInspector } from './StorageInspector'; export const DevCompanion: React.FC = () => { const [isOpen, setIsOpen] = useState(false); + const [activeTab, setActiveTab] = useState<'network' | 'storage'>('network'); const [logs, setLogs] = useState([]); useEffect(() => { @@ -26,7 +28,7 @@ export const DevCompanion: React.FC = () => { boxShadow: '0 4px 12px rgba(0,0,0,0.15)' }} > - 🛠️ Dev Companion ({logs.length}) + Dev Companion ({logs.length}) {isOpen && ( @@ -35,44 +37,83 @@ export const DevCompanion: React.FC = () => { position: 'absolute', bottom: 50, right: 0, - width: 360, - height: 300, + width: 380, + height: 340, background: '#0f172a', color: '#f8fafc', borderRadius: '8px', padding: '12px', boxShadow: '0 8px 24px rgba(0,0,0,0.3)', - overflowY: 'auto' + display: 'flex', + flexDirection: 'column' }} > -

- Tráfego de API -

- {logs.length === 0 ? ( -

Nenhuma requisição capturada ainda.

+ {/* Main Panel Navigation Header */} +
+ + +
+ + {/* Panel Content */} + {activeTab === 'network' ? ( +
+ {logs.length === 0 ? ( +

No requests captured yet.

+ ) : ( + logs.map((log: NetworkLog) => ( +
+ + [{log.method}] + + + {log.url} + + = 400 ? '#f87171' : '#facc15' }}> + {log.status || 'PENDING'} + +
+ )) + )} +
) : ( - logs.map((log: NetworkLog) => ( -
- - [{log.method}] - - - {log.url} - - = 400 ? '#f87171' : '#facc15' }}> - {log.status || 'PENDING'} - -
- )) + )} )} diff --git a/src/components/StorageInspector.tsx b/src/components/StorageInspector.tsx new file mode 100644 index 0000000..045a158 --- /dev/null +++ b/src/components/StorageInspector.tsx @@ -0,0 +1,118 @@ +import React, { useState, useEffect } from 'react'; +import { + StorageItem, + getLocalStorageItems, + getSessionStorageItems, + getCookieItems, + deleteStorageItem, + setStorageItem +} from '../core/storageManager'; + +export const StorageInspector: React.FC = () => { + const [activeTab, setActiveTab] = useState<'local' | 'session' | 'cookie'>('local'); + const [items, setItems] = useState([]); + const [newKey, setNewKey] = useState(''); + const [newValue, setNewValue] = useState(''); + + const refreshItems = () => { + if (activeTab === 'local') setItems(getLocalStorageItems()); + else if (activeTab === 'session') setItems(getSessionStorageItems()); + else if (activeTab === 'cookie') setItems(getCookieItems()); + }; + + useEffect(() => { + refreshItems(); + }, [activeTab]); + + const handleDelete = (key: string) => { + deleteStorageItem(key, activeTab); + refreshItems(); + }; + + const handleAdd = (e: React.FormEvent) => { + e.preventDefault(); + if (!newKey.trim()) return; + setStorageItem(newKey.trim(), newValue.trim(), activeTab); + setNewKey(''); + setNewValue(''); + refreshItems(); + }; + + return ( +
+ {/* Tab Selectors */} +
+ {(['local', 'session', 'cookie'] as const).map((tab) => ( + + ))} +
+ + {/* Add Item Form */} +
+ setNewKey(e.target.value)} + style={{ flex: 1, padding: '4px', fontSize: '11px', background: '#1e293b', color: '#fff', border: '1px solid #334155', borderRadius: '4px' }} + /> + setNewValue(e.target.value)} + style={{ flex: 1, padding: '4px', fontSize: '11px', background: '#1e293b', color: '#fff', border: '1px solid #334155', borderRadius: '4px' }} + /> + +
+ + {/* List */} +
+ {items.length === 0 ? ( +

No items found.

+ ) : ( + items.map((item) => ( +
+
+ {item.key}: {item.value} +
+ +
+ )) + )} +
+
+ ); +}; \ No newline at end of file diff --git a/src/core/storageManager.ts b/src/core/storageManager.ts new file mode 100644 index 0000000..50c81bd --- /dev/null +++ b/src/core/storageManager.ts @@ -0,0 +1,59 @@ +export interface StorageItem { + key: string; + value: string; + type: 'local' | 'session' | 'cookie'; +} + +export const getLocalStorageItems = (): StorageItem[] => { + const items: StorageItem[] = []; + for (let i = 0; i < localStorage.length; i++) { + const key = localStorage.key(i); + if (key) { + items.push({ key, value: localStorage.getItem(key) || '', type: 'local' }); + } + } + return items; +}; + +export const getSessionStorageItems = (): StorageItem[] => { + const items: StorageItem[] = []; + for (let i = 0; i < sessionStorage.length; i++) { + const key = sessionStorage.key(i); + if (key) { + items.push({ key, value: sessionStorage.getItem(key) || '', type: 'session' }); + } + } + return items; +}; + +export const getCookieItems = (): StorageItem[] => { + if (!document.cookie) return []; + return document.cookie.split('; ').map((cookie) => { + const [key, ...val] = cookie.split('='); + return { + key: key.trim(), + value: decodeURIComponent(val.join('=')), + type: 'cookie' + }; + }); +}; + +export const deleteStorageItem = (key: string, type: 'local' | 'session' | 'cookie') => { + if (type === 'local') { + localStorage.removeItem(key); + } else if (type === 'session') { + sessionStorage.removeItem(key); + } else if (type === 'cookie') { + document.cookie = `${key}=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/;`; + } +}; + +export const setStorageItem = (key: string, value: string, type: 'local' | 'session' | 'cookie') => { + if (type === 'local') { + localStorage.setItem(key, value); + } else if (type === 'session') { + sessionStorage.setItem(key, value); + } else if (type === 'cookie') { + document.cookie = `${key}=${encodeURIComponent(value)}; path=/;`; + } +}; \ No newline at end of file