Skip to content

Commit ed10b15

Browse files
REFACTOR: Apply simplified dictionary-based icon mapping
1 parent c8aa6cd commit ed10b15

5 files changed

Lines changed: 174 additions & 43 deletions

File tree

assets/index-DdXLIXgK.js

Lines changed: 67 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

frontend/dist/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
}(window.location));
1717
</script>
1818
<script src="./runtime-config.js"></script>
19-
<script type="module" crossorigin src="./assets/index-YN17OvDs.js"></script>
19+
<script type="module" crossorigin src="./assets/index-DdXLIXgK.js"></script>
2020
<link rel="stylesheet" crossorigin href="./assets/index-BHQWbmWP.css">
2121
</head>
2222
<body>

frontend/src/offlineStore.js

Lines changed: 37 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -2920,47 +2920,43 @@ export const offlineApi = {
29202920

29212921
// Map category to icon
29222922
const getIcon = (cat) => {
2923-
const lower = normalizeText(cat || '').toLowerCase();
2924-
console.log('DEBUG ICON:', cat, '->', lower);
2925-
// Explicit English Mapping (High Priority)
2926-
if (lower.includes('technology') || lower.includes('data') || lower.includes('it')) return 'tech.svg';
2927-
if (lower.includes('education')) return 'education.svg';
2928-
if (lower.includes('health') || lower.includes('medical') || lower.includes('doctor')) return 'health.svg';
2929-
if (lower.includes('business') || lower.includes('finance') || lower.includes('marketing') || lower.includes('sales')) return 'business.svg';
2930-
if (lower.includes('creative') || lower.includes('design') || lower.includes('art') || lower.includes('media')) return 'creative.svg';
2931-
if (lower.includes('science')) return 'science.svg';
2932-
if (lower.includes('security')) return 'security.svg';
2933-
if (lower.includes('service') || lower.includes('beauty') || lower.includes('retail')) return 'service.svg';
2934-
if (lower.includes('hospitality') || lower.includes('hotel') || lower.includes('tourism')) return 'hospitality.svg';
2935-
if (lower.includes('transport') || lower.includes('logistics')) return 'transport.svg';
2936-
if (lower.includes('construction') || lower.includes('architecture')) return 'construction.svg';
2937-
if (lower.includes('agriculture') || lower.includes('farming') || lower.includes('agri')) return 'agri.svg';
2938-
if (lower.includes('management') || lower.includes('manager')) return 'management.svg';
2939-
if (lower.includes('legal') || lower.includes('law')) return 'legal.svg';
2940-
if (lower.includes('admin') || lower.includes('government') || lower.includes('office')) return 'admin.svg';
2941-
if (lower.includes('community') || lower.includes('social') || lower.includes('sports')) return 'community.svg';
2942-
if (lower.includes('engineering') || lower.includes('industry') || lower.includes('technical') || lower.includes('trades')) return 'engineering.svg';
2943-
2944-
// Vietnamese Mapping (Fallback)
2945-
if (lower.includes('cong nghe')) return 'tech.svg';
2946-
if (lower.includes('giao duc')) return 'education.svg';
2947-
if (lower.includes('y te') || lower.includes('bac si')) return 'health.svg';
2948-
if (lower.includes('kinh doanh')) return 'business.svg';
2949-
if (lower.includes('nghe thuat') || lower.includes('thiet ke')) return 'creative.svg';
2950-
if (lower.includes('khoa hoc')) return 'science.svg';
2951-
if (lower.includes('an ninh')) return 'security.svg';
2952-
if (lower.includes('dich vu')) return 'service.svg';
2953-
if (lower.includes('du lich')) return 'hospitality.svg';
2954-
if (lower.includes('van tai')) return 'transport.svg';
2955-
if (lower.includes('xay dung')) return 'construction.svg';
2956-
if (lower.includes('nong nghiep')) return 'agri.svg';
2957-
if (lower.includes('quan ly')) return 'management.svg';
2958-
if (lower.includes('luat')) return 'legal.svg';
2959-
if (lower.includes('hanh chinh')) return 'admin.svg';
2960-
if (lower.includes('cong dong')) return 'community.svg';
2961-
if (lower.includes('ky thuat') || lower.includes('co khi')) return 'engineering.svg';
2962-
2963-
return 'default.svg';
2923+
const key = normalizeText(cat || '').toLowerCase().trim();
2924+
2925+
const MAPPING = {
2926+
'agriculture': 'agri.svg',
2927+
'beauty': 'service.svg',
2928+
'business': 'business.svg',
2929+
'construction': 'construction.svg',
2930+
'data': 'tech.svg',
2931+
'design': 'creative.svg',
2932+
'education': 'education.svg',
2933+
'engineering': 'engineering.svg',
2934+
'finance': 'business.svg',
2935+
'government': 'admin.svg',
2936+
'healthcare': 'health.svg',
2937+
'health': 'health.svg',
2938+
'hospitality': 'hospitality.svg',
2939+
'legal': 'legal.svg',
2940+
'logistics': 'transport.svg',
2941+
'marketing': 'business.svg',
2942+
'media': 'creative.svg',
2943+
'realestate': 'business.svg',
2944+
'retail': 'service.svg',
2945+
'science': 'science.svg',
2946+
'sports': 'community.svg',
2947+
'technology': 'tech.svg',
2948+
'tech': 'tech.svg',
2949+
'trades': 'engineering.svg',
2950+
'transportation': 'transport.svg',
2951+
'transport': 'transport.svg',
2952+
'security': 'security.svg',
2953+
'service': 'service.svg',
2954+
'management': 'management.svg',
2955+
'community': 'community.svg',
2956+
'admin': 'admin.svg'
2957+
};
2958+
2959+
return MAPPING[key] || 'default.svg';
29642960
};
29652961

29662962
const query = normalizeText(String(q || ''));

index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
}(window.location));
1717
</script>
1818
<script src="./runtime-config.js"></script>
19-
<script type="module" crossorigin src="./assets/index-YN17OvDs.js"></script>
19+
<script type="module" crossorigin src="./assets/index-DdXLIXgK.js"></script>
2020
<link rel="stylesheet" crossorigin href="./assets/index-BHQWbmWP.css">
2121
</head>
2222
<body>

scripts/simplifyIcons.js

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
const fs = require('fs');
2+
const path = require('path');
3+
const p = path.join(__dirname, '../frontend/src/offlineStore.js');
4+
let c = fs.readFileSync(p, 'utf8');
5+
6+
// Pattern to find the getIcon function
7+
const startStr = ' // Map category to icon';
8+
// We know exactly what the previous content looks like (with debug log)
9+
// Or we can just find the start and end by brace counting or marker
10+
const endMarker = "return 'default.svg';";
11+
const closingBrace = " };";
12+
13+
const startIndex = c.indexOf(startStr);
14+
if (startIndex === -1) {
15+
console.error('Do not find start'); process.exit(1);
16+
}
17+
const endIndex = c.indexOf(closingBrace, startIndex);
18+
if (endIndex === -1) {
19+
console.error('Do not find end'); process.exit(1);
20+
}
21+
const replaceEnd = endIndex + closingBrace.length;
22+
23+
const simpleLogic = ` // Map category to icon
24+
const getIcon = (cat) => {
25+
const key = normalizeText(cat || '').toLowerCase().trim();
26+
27+
const MAPPING = {
28+
'agriculture': 'agri.svg',
29+
'beauty': 'service.svg',
30+
'business': 'business.svg',
31+
'construction': 'construction.svg',
32+
'data': 'tech.svg',
33+
'design': 'creative.svg',
34+
'education': 'education.svg',
35+
'engineering': 'engineering.svg',
36+
'finance': 'business.svg',
37+
'government': 'admin.svg',
38+
'healthcare': 'health.svg',
39+
'health': 'health.svg',
40+
'hospitality': 'hospitality.svg',
41+
'legal': 'legal.svg',
42+
'logistics': 'transport.svg',
43+
'marketing': 'business.svg',
44+
'media': 'creative.svg',
45+
'realestate': 'business.svg',
46+
'retail': 'service.svg',
47+
'science': 'science.svg',
48+
'sports': 'community.svg',
49+
'technology': 'tech.svg',
50+
'tech': 'tech.svg',
51+
'trades': 'engineering.svg',
52+
'transportation': 'transport.svg',
53+
'transport': 'transport.svg',
54+
'security': 'security.svg',
55+
'service': 'service.svg',
56+
'management': 'management.svg',
57+
'community': 'community.svg',
58+
'admin': 'admin.svg'
59+
};
60+
61+
return MAPPING[key] || 'default.svg';
62+
};`;
63+
64+
const before = c.substring(0, startIndex);
65+
const after = c.substring(replaceEnd);
66+
67+
fs.writeFileSync(p, before + simpleLogic + after, 'utf8');
68+
console.log('Simplified getIcon logic');

0 commit comments

Comments
 (0)