import { useCallback } from 'react' export interface RecentRepo { ownerName: string name: string visitedAt: number } const KEY = 'fb_recent_repos' const MAX = 5 function read(): RecentRepo[] { try { return JSON.parse(localStorage.getItem(KEY) ?? '[]') } catch { return [] } } export function useRecentRepos() { const repos = read() const track = useCallback((ownerName: string, name: string) => { const existing = read().filter(r => !(r.ownerName === ownerName && r.name === name)) const updated: RecentRepo[] = [{ ownerName, name, visitedAt: Date.now() }, ...existing].slice(0, MAX) localStorage.setItem(KEY, JSON.stringify(updated)) }, []) return { repos, track } }