1
1
import styles from './CompanyIcon.module.css' ;
2
2
import { DDG_STATS_OTHER_COMPANY_IDENTIFIER } from '../privacy-stats/constants.js' ;
3
3
import { h } from 'preact' ;
4
- import { useState } from 'preact/hooks' ;
5
4
import { memo } from 'preact/compat' ;
6
5
7
6
const mappings = {
8
7
'google-analytics-google' : 'google-analytics' ,
8
+ 'google-ads-google' : 'google-ads' ,
9
9
} ;
10
10
11
- const states = /** @type {const } */ ( {
12
- loading : 'loading' ,
13
- loaded : 'loaded' ,
14
- loadingFallback : 'loadingFallback' ,
15
- loadedFallback : 'loadedFallback' ,
16
- errored : 'errored' ,
17
- } ) ;
18
-
19
- /**
20
- * @typedef {states[keyof states] } State
21
- */
22
11
export const CompanyIcon = memo (
23
12
/**
24
13
* @param {object } props
@@ -29,38 +18,23 @@ export const CompanyIcon = memo(
29
18
const cleaned = icon . replace ( / [ ^ a - z ] / g, '' ) . replace ( / / g, '-' ) ;
30
19
const id = cleaned in mappings ? mappings [ cleaned ] : cleaned ;
31
20
const firstChar = id [ 0 ] ;
32
- const [ state , setState ] = useState ( /** @type {State } */ ( states . loading ) ) ;
33
-
34
- const src =
35
- state === 'loading' || state === 'loaded'
36
- ? `./company-icons/${ id } .svg`
37
- : state === 'loadingFallback' || state === 'loadedFallback'
38
- ? `./company-icons/${ firstChar } .svg`
39
- : null ;
40
21
41
- if ( src === null || icon === DDG_STATS_OTHER_COMPANY_IDENTIFIER ) {
22
+ if ( icon === DDG_STATS_OTHER_COMPANY_IDENTIFIER ) {
42
23
return (
43
24
< span className = { styles . icon } >
44
25
< Other />
45
26
</ span >
46
27
) ;
47
28
}
48
29
30
+ // prettier-ignore
31
+ const src = names . has ( id )
32
+ ? `./company-icons/${ id } .svg`
33
+ : `./company-icons/${ firstChar } .svg` ;
34
+
49
35
return (
50
36
< span className = { styles . icon } >
51
- < img
52
- src = { src }
53
- alt = { '' }
54
- class = { styles . companyImgIcon }
55
- data-loaded = { state === states . loaded || state === states . loadedFallback }
56
- onLoad = { ( ) => setState ( ( prev ) => ( prev === states . loading ? states . loaded : states . loadedFallback ) ) }
57
- onError = { ( ) => {
58
- setState ( ( prev ) => {
59
- if ( prev === states . loading ) return states . loadingFallback ;
60
- return states . errored ;
61
- } ) ;
62
- } }
63
- />
37
+ < img src = { src } alt = { '' } class = { styles . companyImgIcon } data-loaded = "true" />
64
38
</ span >
65
39
) ;
66
40
} ,
@@ -78,3 +52,143 @@ function Other() {
78
52
</ svg >
79
53
) ;
80
54
}
55
+
56
+ /**
57
+ * A static list of names representing the icons in `./public/company-icons`
58
+ * We don't want the bundler to crawl through that folder, or include the SVGs in JS,
59
+ * so this static list have to do for now. Perhaps it can be generated later.
60
+ *
61
+ * @type {Set<string> }
62
+ */
63
+ const names = new Set ( [
64
+ '33across' ,
65
+ 'a' ,
66
+ 'acuityads' ,
67
+ 'adform' ,
68
+ 'adjust' ,
69
+ 'adobe' ,
70
+ 'akamai' ,
71
+ 'amazon' ,
72
+ 'amplitude' ,
73
+ 'appsflyer' ,
74
+ 'automattic' ,
75
+ 'b' ,
76
+ 'beeswax' ,
77
+ 'bidtellect' ,
78
+ 'branch-metrics' ,
79
+ 'braze' ,
80
+ 'bugsnag' ,
81
+ 'bytedance' ,
82
+ 'c' ,
83
+ 'chartbeat' ,
84
+ 'cloudflare' ,
85
+ 'cognitiv' ,
86
+ 'comscore' ,
87
+ 'crimtan-holdings' ,
88
+ 'criteo' ,
89
+ 'd' ,
90
+ 'deepintent' ,
91
+ 'e' ,
92
+ 'exoclick' ,
93
+ 'eyeota' ,
94
+ 'f' ,
95
+ 'facebook' ,
96
+ 'g' ,
97
+ 'google' ,
98
+ 'google-ads' ,
99
+ 'google-analytics' ,
100
+ 'gumgum' ,
101
+ 'h' ,
102
+ 'hotjar' ,
103
+ 'i' ,
104
+ 'id5' ,
105
+ 'improve-digital' ,
106
+ 'index-exchange' ,
107
+ 'inmar' ,
108
+ 'instagram' ,
109
+ 'intent-iq' ,
110
+ 'iponweb' ,
111
+ 'j' ,
112
+ 'k' ,
113
+ 'kargo' ,
114
+ 'kochava' ,
115
+ 'l' ,
116
+ 'line' ,
117
+ 'linkedin' ,
118
+ 'liveintent' ,
119
+ 'liveramp' ,
120
+ 'loopme-ltd' ,
121
+ 'lotame-solutions' ,
122
+ 'm' ,
123
+ 'magnite' ,
124
+ 'mediamath' ,
125
+ 'medianet-advertising' ,
126
+ 'mediavine' ,
127
+ 'merkle' ,
128
+ 'microsoft' ,
129
+ 'mixpanel' ,
130
+ 'n' ,
131
+ 'narrative' ,
132
+ 'nativo' ,
133
+ 'neustar' ,
134
+ 'new-relic' ,
135
+ 'o' ,
136
+ 'onetrust' ,
137
+ 'openjs-foundation' ,
138
+ 'openx' ,
139
+ 'opera-software' ,
140
+ 'oracle' ,
141
+ 'other' ,
142
+ 'other-dark' ,
143
+ 'outbrain' ,
144
+ 'p' ,
145
+ 'pinterest' ,
146
+ 'prospect-one' ,
147
+ 'pubmatic' ,
148
+ 'pulsepoint' ,
149
+ 'q' ,
150
+ 'quantcast' ,
151
+ 'r' ,
152
+ 'rhythmone' ,
153
+ 'roku' ,
154
+ 'rtb-house' ,
155
+ 'rubicon' ,
156
+ 's' ,
157
+ 'salesforce' ,
158
+ 'semasio' ,
159
+ 'sharethrough' ,
160
+ 'simplifi-holdings' ,
161
+ 'smaato' ,
162
+ 'snap' ,
163
+ 'sonobi' ,
164
+ 'sovrn-holdings' ,
165
+ 'spotx' ,
166
+ 'supership' ,
167
+ 'synacor' ,
168
+ 't' ,
169
+ 'taboola' ,
170
+ 'tapad' ,
171
+ 'teads' ,
172
+ 'the-nielsen-company' ,
173
+ 'the-trade-desk' ,
174
+ 'triplelift' ,
175
+ 'twitter' ,
176
+ 'u' ,
177
+ 'unruly-group' ,
178
+ 'urban-airship' ,
179
+ 'v' ,
180
+ 'verizon-media' ,
181
+ 'w' ,
182
+ 'warnermedia' ,
183
+ 'wpp' ,
184
+ 'x' ,
185
+ 'xaxis' ,
186
+ 'y' ,
187
+ 'yahoo-japan' ,
188
+ 'yandex' ,
189
+ 'yieldmo' ,
190
+ 'youtube' ,
191
+ 'z' ,
192
+ 'zeotap' ,
193
+ 'zeta-global' ,
194
+ ] ) ;
0 commit comments