Skip to content

Commit b112279

Browse files
Merge pull request #3 from PandaMystique/claude/explain-codebase-mljwgl8sbvguuo21-sEdSC
Séparer données et logique: centraliser l'accès aux données dans data.js
2 parents 3cfb6a6 + c4fff32 commit b112279

16 files changed

Lines changed: 762 additions & 505 deletions

www/index.html

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -307,8 +307,9 @@ <h1>Dictionnaire <span>de Philosophie</span></h1>
307307

308308
<!-- JavaScript modules (order matters: dependencies first) -->
309309

310-
<!-- Core: storage, state, utilities -->
310+
<!-- Core: storage, data layer, state, utilities -->
311311
<script src="js/storage.js"></script>
312+
<script src="js/data.js"></script>
312313
<script src="js/state.js"></script>
313314
<script src="js/theme.js"></script>
314315
<script src="js/search.js"></script>

www/js/article-ui.js

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -48,12 +48,8 @@ function showRandomArticle() {
4848
}
4949

5050
// ===== FEATURE: NOTES =====
51-
function getNote(id) { return articleNotes[id] || ''; }
52-
function saveNote(id, text) {
53-
if (text.trim()) articleNotes[id] = text.trim();
54-
else delete articleNotes[id];
55-
PhiloDB.set('philo-notes', JSON.stringify(articleNotes));
56-
}
51+
function getNote(id) { return Data.getNote(id); }
52+
function saveNote(id, text) { Data.saveNote(id, text); }
5753

5854
// ===== FEATURE: FICHE EXPRESS =====
5955
function buildFicheExpress(entry) {
@@ -219,8 +215,7 @@ function showStats() {
219215

220216
// ===== FEATURE: SORT =====
221217
function setSortMode(mode) {
222-
sortMode = mode;
223-
PhiloDB.set('philo-sort', mode);
218+
Data.setPref('sortMode', mode);
224219
renderEntryList();
225220
}
226221

@@ -260,7 +255,7 @@ function mobileJumpToLetter(letter) {
260255

261256
// ===== FEATURE: COLLECTIONS =====
262257
function saveCollections() {
263-
PhiloDB.set('philo-collections', JSON.stringify(collections));
258+
Data.saveCollections();
264259
}
265260

266261
function addToCollection(colName, articleId) {
@@ -336,7 +331,7 @@ function stopReadingTimer() {
336331
if (elapsed > 5 && elapsed < 3600) { // Between 5s and 1h
337332
var id = readingStartTimes._currentId;
338333
readingStartTimes[id] = (readingStartTimes[id] || 0) + elapsed;
339-
PhiloDB.set('philo-reading-times', JSON.stringify(readingStartTimes));
334+
Data.saveReadingTimes();
340335
}
341336
}
342337
readingStartTimes._current = null;

www/js/article.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -494,7 +494,7 @@ function toggleBookmark() {
494494
const idx = bookmarks.indexOf(currentArticle.id);
495495
if (idx > -1) bookmarks.splice(idx, 1);
496496
else bookmarks.push(currentArticle.id);
497-
PhiloDB.set('philo-bookmarks', JSON.stringify(bookmarks));
497+
Data.saveBookmarks();
498498

499499
if (isMobile()) { updateMobileBookmarkBtn(); }
500500
showArticle(currentArticle.id);

www/js/custom-tags.js

Lines changed: 15 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,38 @@
11
// ===== CUSTOM TAGS =====
2-
var customArticleTags = JSON.parse(lsGet('philo-custom-tags', '{}'));
3-
var allCustomTagNames = JSON.parse(lsGet('philo-all-custom-tags', '[]'));
2+
// Data (customArticleTags, allCustomTagNames) is managed by Data layer via aliases in state.js
43

54
function getCustomTags(id) {
6-
return customArticleTags[id] || [];
5+
return Data.getCustomTags()[id] || [];
76
}
87

98
function saveCustomTags() {
10-
var json = JSON.stringify(customArticleTags);
11-
PhiloDB.set('philo-custom-tags', json);
12-
try { localStorage.setItem('philo-custom-tags', json); } catch(e) {}
13-
var names = JSON.stringify(allCustomTagNames);
14-
PhiloDB.set('philo-all-custom-tags', names);
15-
try { localStorage.setItem('philo-all-custom-tags', names); } catch(e) {}
9+
Data.saveCustomTags();
1610
}
1711

1812
function addCustomTag(id, tagName) {
1913
tagName = tagName.trim().toLowerCase();
2014
if (!tagName || tagName.length > 30) return;
21-
if (!customArticleTags[id]) customArticleTags[id] = [];
22-
if (customArticleTags[id].indexOf(tagName) >= 0) return;
23-
customArticleTags[id].push(tagName);
24-
if (allCustomTagNames.indexOf(tagName) < 0) allCustomTagNames.push(tagName);
15+
var tags = Data.getCustomTags();
16+
var names = Data.getAllCustomTagNames();
17+
if (!tags[id]) tags[id] = [];
18+
if (tags[id].indexOf(tagName) >= 0) return;
19+
tags[id].push(tagName);
20+
if (names.indexOf(tagName) < 0) names.push(tagName);
2521
saveCustomTags();
2622
showArticle(id);
2723
}
2824

2925
function removeCustomTag(id, tagName) {
30-
if (!customArticleTags[id]) return;
31-
customArticleTags[id] = customArticleTags[id].filter(function(t) { return t !== tagName; });
32-
if (customArticleTags[id].length === 0) delete customArticleTags[id];
26+
var tags = Data.getCustomTags();
27+
if (!tags[id]) return;
28+
tags[id] = tags[id].filter(function(t) { return t !== tagName; });
29+
if (tags[id].length === 0) delete tags[id];
3330
saveCustomTags();
3431
showArticle(id);
3532
}
3633

3734
function promptAddCustomTag(id) {
38-
// Show inline prompt with suggestions
39-
var existingHtml = allCustomTagNames.length > 0
40-
? '<div style="display:flex;flex-wrap:wrap;gap:0.25rem;margin-bottom:0.5rem;">' +
41-
allCustomTagNames.slice(0, 15).map(function(t) {
42-
return '<span class="custom-tag" onclick="addCustomTag(\'' + id + '\',\'' + t.replace(/'/g, "\\'") + '\')">' + t + '</span>';
43-
}).join('') + '</div>'
44-
: '';
45-
46-
var name = prompt('Nouvelle étiquette :');
35+
var name = prompt('Nouvelle \u00e9tiquette :');
4736
if (name) addCustomTag(id, name);
4837
}
4938

@@ -54,7 +43,7 @@ function buildCustomTagsHtml(id) {
5443
html += '<span class="custom-tag">' + tag +
5544
' <span class="custom-tag-remove" onclick="event.stopPropagation();removeCustomTag(\'' + id + '\',\'' + tag.replace(/'/g, "\\'") + '\')">&times;</span></span>';
5645
});
57-
html += '<button class="custom-tag-add" onclick="promptAddCustomTag(\'' + id + '\')" title="Ajouter une étiquette">+</button>';
46+
html += '<button class="custom-tag-add" onclick="promptAddCustomTag(\'' + id + '\')" title="Ajouter une \u00e9tiquette">+</button>';
5847
html += '</div>';
5948
return html;
6049
}

0 commit comments

Comments
 (0)