initial commit

This commit is contained in:
2026-02-06 15:16:49 +09:00
commit 1c72c185ab
12 changed files with 837 additions and 0 deletions

48
services/storage.ts Normal file
View File

@@ -0,0 +1,48 @@
import { WiFiHotspot } from '../types';
const STORAGE_KEY = 'wifi_hotspots_v2_db';
export const storageService = {
getHotspots: (): WiFiHotspot[] => {
try {
const data = localStorage.getItem(STORAGE_KEY);
if (!data) return [];
const parsed = JSON.parse(data);
return Array.isArray(parsed) ? parsed : [];
} catch (e) {
console.error("Failed to load hotspots from storage", e);
return [];
}
},
saveHotspot: (hotspot: WiFiHotspot): void => {
try {
const hotspots = storageService.getHotspots();
const index = hotspots.findIndex(h => h.id === hotspot.id);
if (index > -1) {
hotspots[index] = hotspot;
} else {
hotspots.push(hotspot);
}
localStorage.setItem(STORAGE_KEY, JSON.stringify(hotspots));
// Trigger a storage event for cross-tab sync if needed
window.dispatchEvent(new Event('storage_updated'));
} catch (e) {
console.error("Failed to save hotspot", e);
}
},
deleteHotspot: (id: string): void => {
try {
const hotspots = storageService.getHotspots();
const filtered = hotspots.filter(h => h.id !== id);
localStorage.setItem(STORAGE_KEY, JSON.stringify(filtered));
window.dispatchEvent(new Event('storage_updated'));
} catch (e) {
console.error("Failed to delete hotspot", e);
}
}
};