Skip to content

Commit e6c9f37

Browse files
feat: Cache repository configurations in frontend (#254)
Implement localStorage-based caching for repository configurations on the main page ('src/app/page.tsx'). This feature enables the application to remember user-specified settings for a given repository URL. When a user submits a repository URL along with configurations such as wiki language, wiki type, model provider, model selection, custom model options, and advanced exclusion paths/files, these settings are now cached locally in the browser's localStorage. If the user later inputs the same repository URL, the previously saved settings are automatically loaded and pre-filled in the configuration modal. This significantly improves user experience by reducing repetitive data entry for frequently used repositories. The following configuration items are cached: - Wiki Language - Wiki Type (Comprehensive/Concise) - Model Provider - Model Selection - Custom Model (boolean flag and name) - Selected Platform (GitHub, GitLab, Bitbucket) - Excluded Directories - Excluded Files - Included Directories - Included Files Access tokens and other sensitive information are intentionally not cached to maintain security. Co-authored-by: google-labs-jules[bot] <161369871+google-labs-jules[bot]@users.noreply.github.com>
1 parent 0efaec5 commit e6c9f37

File tree

1 file changed

+69
-1
lines changed

1 file changed

+69
-1
lines changed

src/app/page.tsx

Lines changed: 69 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,50 @@ export default function Home() {
7777

7878
const [repositoryInput, setRepositoryInput] = useState('https://github.com/AsyncFuncAI/deepwiki-open');
7979

80+
const REPO_CONFIG_CACHE_KEY = 'deepwikiRepoConfigCache';
81+
82+
const loadConfigFromCache = (repoUrl: string) => {
83+
if (!repoUrl) return;
84+
try {
85+
const cachedConfigs = localStorage.getItem(REPO_CONFIG_CACHE_KEY);
86+
if (cachedConfigs) {
87+
const configs = JSON.parse(cachedConfigs);
88+
const config = configs[repoUrl.trim()];
89+
if (config) {
90+
setSelectedLanguage(config.selectedLanguage || language);
91+
setIsComprehensiveView(config.isComprehensiveView === undefined ? true : config.isComprehensiveView);
92+
setProvider(config.provider || '');
93+
setModel(config.model || '');
94+
setIsCustomModel(config.isCustomModel || false);
95+
setCustomModel(config.customModel || '');
96+
setSelectedPlatform(config.selectedPlatform || 'github');
97+
setExcludedDirs(config.excludedDirs || '');
98+
setExcludedFiles(config.excludedFiles || '');
99+
setIncludedDirs(config.includedDirs || '');
100+
setIncludedFiles(config.includedFiles || '');
101+
}
102+
}
103+
} catch (error) {
104+
console.error('Error loading config from localStorage:', error);
105+
}
106+
};
107+
108+
const handleRepositoryInputChange = (e: React.ChangeEvent<HTMLInputElement>) => {
109+
const newRepoUrl = e.target.value;
110+
setRepositoryInput(newRepoUrl);
111+
if (newRepoUrl.trim() === "") {
112+
// Optionally reset fields if input is cleared
113+
} else {
114+
loadConfigFromCache(newRepoUrl);
115+
}
116+
};
117+
118+
useEffect(() => {
119+
if (repositoryInput) {
120+
loadConfigFromCache(repositoryInput);
121+
}
122+
}, []);
123+
80124
// Provider-based model selection state
81125
const [provider, setProvider] = useState<string>('');
82126
const [model, setModel] = useState<string>('');
@@ -262,6 +306,30 @@ export default function Home() {
262306
return;
263307
}
264308

309+
try {
310+
const currentRepoUrl = repositoryInput.trim();
311+
if (currentRepoUrl) {
312+
const existingConfigs = JSON.parse(localStorage.getItem(REPO_CONFIG_CACHE_KEY) || '{}');
313+
const configToSave = {
314+
selectedLanguage,
315+
isComprehensiveView,
316+
provider,
317+
model,
318+
isCustomModel,
319+
customModel,
320+
selectedPlatform,
321+
excludedDirs,
322+
excludedFiles,
323+
includedDirs,
324+
includedFiles,
325+
};
326+
existingConfigs[currentRepoUrl] = configToSave;
327+
localStorage.setItem(REPO_CONFIG_CACHE_KEY, JSON.stringify(existingConfigs));
328+
}
329+
} catch (error) {
330+
console.error('Error saving config to localStorage:', error);
331+
}
332+
265333
setIsSubmitting(true);
266334

267335
// Parse repository input
@@ -352,7 +420,7 @@ export default function Home() {
352420
<input
353421
type="text"
354422
value={repositoryInput}
355-
onChange={(e) => setRepositoryInput(e.target.value)}
423+
onChange={handleRepositoryInputChange}
356424
placeholder={t('form.repoPlaceholder') || "owner/repo, GitHub/GitLab/BitBucket URL, or local folder path"}
357425
className="input-japanese block w-full pl-10 pr-3 py-2.5 border-[var(--border-color)] rounded-lg bg-transparent text-[var(--foreground)] focus:outline-none focus:border-[var(--accent-primary)]"
358426
/>

0 commit comments

Comments
 (0)