@@ -3,7 +3,7 @@ import Image from "next/image";
3
3
import React , { useEffect , useState } from "react" ;
4
4
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome" ;
5
5
import { faToolbox } from "@fortawesome/free-solid-svg-icons" ;
6
- import IconCloud from "@/world/effects/iconCloud"
6
+ import IconCloud from "@/world/effects/iconCloud" ;
7
7
8
8
export default function Skills ( ) {
9
9
// █▀▀ █▀▀ ▀█▀ █▀▀ █░█ █▀ █▄▀ █ █░░ █░░ █▀
@@ -43,26 +43,18 @@ export default function Skills() {
43
43
return < p > Loading...</ p > ;
44
44
}
45
45
46
- // █▀█ █▀▀ █▄░█ █▀▄ █▀▀ █▀█ █▀ █▄▀ █ █░░ █░░ █▀
47
- // █▀▄ ██▄ █░▀█ █▄▀ ██▄ █▀▄ ▄█ █░█ █ █▄▄ █▄▄ ▄█
48
- // Prints skills from given category
49
- // Syntax: renderSkills("category", data.category)
50
- // Example: renderSkills("languages", skills.languages)
51
- const renderSkills = ( title : string , skillList : Skill [ ] ) => (
52
- < div className = "w-full grid sm:grid-cols-4 md:grid-cols-6 lg:grid-cols-8 gap-4 text-center py-2 sm:px-0" >
53
- { skillList . map ( ( skill , index ) => (
54
- < div key = { `skill-${ index } ` } className = "block p-4" >
55
- < Image
56
- src = { `/ico/${ title } /${ skill . icon } .svg` }
57
- alt = { `${ skill . name } icon` }
58
- width = { 150 }
59
- height = { 150 }
60
- data-blobity-tooltip = { `${ skill . name } ` }
61
- />
62
- </ div >
63
- ) ) }
64
- </ div >
65
- ) ;
46
+ // █▀ █░█ █▀▀ █▀█ █ █▀▄▀█ █▀█ █▀█ █▀█ ▀█▀
47
+ // ▄█ ▀▄▀ █▄█ █▀▄ █ █░▀░█ █▀▀ █▄█ █▀▄ ░█░
48
+ // Function to dynamically import SVGs as React Component using SVGR
49
+ const importSvgIcon = ( title : String , icon : String ) => {
50
+ try {
51
+ const IconComponent = require ( `/public/ico/${ title } /${ icon } .svg` ) . default ;
52
+ return IconComponent ;
53
+ } catch ( error ) {
54
+ console . error ( "Error importing SVG:" , error ) ;
55
+ return null ;
56
+ }
57
+ } ;
66
58
67
59
// █▀█ █▀▀ █▄░█ █▀▄ █▀▀ █▀█ ▄▀█ █░░ █░░ █▀ █▄▀ █ █░░ █░░ █▀
68
60
// █▀▄ ██▄ █░▀█ █▄▀ ██▄ █▀▄ █▀█ █▄▄ █▄▄ ▄█ █░█ █ █▄▄ █▄▄ ▄█
@@ -75,23 +67,28 @@ export default function Skills() {
75
67
// Using loops over .map() as Heap/GC allocation in JS is expensive.
76
68
for ( let index = 0 ; index < skillList . length ; index ++ ) {
77
69
const skill = skillList [ index ] ;
78
- skillElements . push (
79
- < div
80
- key = { `${ title } -${ index } ` }
81
- className = "place-content-center p-5 bg-white border border-gray-200 rounded-lg shadow hover:bg-gray-100 dark:bg-[#161D1F] dark:border-gray-700 dark:hover:bg-gray-700"
82
- data-blobity-tooltip = { `${ skill . name } ` }
83
- data-blobity-magnetic = "false"
84
- >
85
- < Image
86
- src = { `/ico/${ title } /${ skill . icon } .svg` }
87
- alt = { `${ skill . name } icon` }
70
+ const IconComponent = importSvgIcon ( title , skill . icon ) ;
71
+
72
+ if ( IconComponent ) {
73
+ skillElements . push (
74
+ < div
75
+ key = { `${ title } -${ index } ` }
76
+ className = "place-content-center p-5 bg-white border border-gray-200 rounded-lg shadow hover:bg-gray-100 dark:bg-[#161D1F] dark:border-gray-700 dark:hover:bg-gray-700"
88
77
data-blobity-tooltip = { `${ skill . name } ` }
89
- data-blobity-magnetic = "true"
90
- width = { 100 }
91
- height = { 100 }
92
- />
93
- </ div >
94
- ) ;
78
+ data-blobity-magnetic = "false"
79
+ >
80
+ < IconComponent
81
+ className = "w-full h-full object-contain text-gray-800 dark:text-gray-200"
82
+ src = { `/ico/${ title } /${ skill . icon } .svg` }
83
+ alt = { `${ skill . name } icon` }
84
+ data-blobity-tooltip = { `${ skill . name } ` }
85
+ data-blobity-magnetic = "true"
86
+ width = { 100 }
87
+ height = { 100 }
88
+ />
89
+ </ div > ,
90
+ ) ;
91
+ }
95
92
}
96
93
}
97
94
}
@@ -105,9 +102,7 @@ export default function Skills() {
105
102
const skillIcons = [ ] ;
106
103
if ( skills ) {
107
104
for ( const skillList of Object . values ( skills ) ) {
108
- skillIcons . push (
109
- ...skillList . map ( ( skill ) => skill . icon )
110
- ) ;
105
+ skillIcons . push ( ...skillList . map ( ( skill ) => skill . icon ) ) ;
111
106
}
112
107
}
113
108
return skillIcons ;
@@ -116,19 +111,14 @@ export default function Skills() {
116
111
const skillNames = [ ] ;
117
112
if ( skills ) {
118
113
for ( const skillList of Object . values ( skills ) ) {
119
- skillNames . push (
120
- ...skillList . map ( ( skill ) => skill . name )
121
- ) ;
114
+ skillNames . push ( ...skillList . map ( ( skill ) => skill . name ) ) ;
122
115
}
123
116
}
124
117
return skillNames ;
125
118
} ;
126
119
127
120
return (
128
- < section
129
- id = "skills"
130
- className = "px-3 md:px-[100px] py-[100px]"
131
- >
121
+ < section id = "skills" className = "px-3 md:px-[100px] py-[100px]" >
132
122
< h2 >
133
123
< FontAwesomeIcon className = "pe-4" icon = { faToolbox } />
134
124
Skills
@@ -137,16 +127,12 @@ export default function Skills() {
137
127
< div className = "flex gap-10" >
138
128
{ /* CLOUD ONLY FOR PC-MASTER-RACE ;) */ }
139
129
< div className = "w-fit mx-auto hidden lg:block" >
140
- < IconCloud
141
- iconSlugs = { getSkillIcons ( ) }
142
- names = { getSkillNames ( ) }
143
- />
130
+ < IconCloud iconSlugs = { getSkillIcons ( ) } names = { getSkillNames ( ) } />
144
131
</ div >
145
132
< div className = "w-fit mx-auto grid grid-cols-3 sm:grid-cols-4 md:grid-cols-6 lg:grid-cols-5 xl:grid-cols-7 gap-6" >
146
133
{ renderAllSkills ( ) }
147
134
</ div >
148
135
</ div >
149
-
150
136
</ section >
151
137
) ;
152
138
}
0 commit comments