Skip to content

Commit e8c79f9

Browse files
authored
chore: add workos gold sponsor to package search (#4049)
* chore: add workos gold sponsor to package search * refactor: select new sponsor to show first on each component creation
1 parent 86f2dcf commit e8c79f9

File tree

6 files changed

+138
-28
lines changed

6 files changed

+138
-28
lines changed

.pnp.cjs

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

packages/gatsby/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@
7272
"react-icons": "^3.10.0",
7373
"react-instantsearch-dom": "^6.6.0",
7474
"react-monaco-editor": "^0.36.0",
75+
"react-responsive-carousel": "^3.2.22",
7576
"react-scroll-into-view-if-needed": "^2.1.7",
7677
"react-select": "^3.1.0",
7778
"react-spinners": "^0.8.3",

packages/gatsby/src/components/search/SearchResults.js

Lines changed: 93 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,28 @@
1+
import 'react-responsive-carousel/lib/styles/carousel.min.css';
12
import styled from '@emotion/styled';
23
import {connectHits, connectStateResults} from 'react-instantsearch-dom';
34
import {Stats} from 'react-instantsearch-dom';
4-
import React from 'react';
5+
import {Carousel} from 'react-responsive-carousel';
6+
import ReactTooltip from 'react-tooltip';
7+
import React, {useRef} from 'react';
58

69
import {Hit} from '../hit';
710
import {isEmpty} from '../util';
811

912
import {Pagination} from './Pagination';
1013

14+
const SPONSORS = [{
15+
name: `Doppler`,
16+
description: `Universal Secrets Platform`,
17+
icon: `https://dashboard.doppler.com/imgs/logo_color.png`,
18+
url: `https://www.doppler.com/?utm_campaign=github_repo&utm_medium=referral&utm_content=yarn&utm_source=github`,
19+
}, {
20+
name: `WorkOS`,
21+
description: `all-in-one solution for enterprise-ready apps`,
22+
icon: `https://assets-global.website-files.com/5ef26797488fe01cc1b89848/61426734f2f4a013c6f2d774_Favicon%2032x32.png`,
23+
url: `https://workos.com/?utm_campaign=github_repo&utm_medium=referral&utm_content=berry&utm_source=github`,
24+
}];
25+
1126
const Hits = connectHits(({hits, onTagClick, onOwnerClick, searchState}) =>
1227
hits.map(hit => (
1328
<Hit
@@ -42,17 +57,38 @@ const StatsText = styled.div`
4257
margin-right: 1rem;
4358
`;
4459

45-
const Sponsors = styled.a`
46-
padding: 0.7rem 0;
60+
const SponsorCarousel = styled(Carousel)`
61+
margin: auto 0 auto auto;
4762
48-
flex: none;
49-
margin-left: auto;
63+
.carousel {
64+
display: flex;
65+
flex-direction: row-reverse;
66+
67+
.slide {
68+
text-align: right;
69+
70+
img {
71+
width: 1.2em;
72+
height: 1.2em;
73+
74+
vertical-align: middle;
75+
}
76+
}
77+
}
78+
79+
.control-dots {
80+
position: relative;
5081
82+
flex: 1;
83+
margin: 0;
84+
line-height: 1em;
85+
}
86+
`;
87+
88+
const SponsorContainer = styled.a`
5189
color: inherit;
5290
5391
span {
54-
display: inline-block;
55-
5692
color: #85ecf7;
5793
text-decoration: underline;
5894
text-underline-offset: 2px;
@@ -71,30 +107,59 @@ const SearchFooter = styled.div`
71107
margin-bottom: 50px;
72108
`;
73109

74-
const ResultsFound = ({pagination, onTagClick, onOwnerClick, searchState}) => <>
75-
<InfoBar>
76-
<InfoContainer>
77-
<StatsText>
78-
<Stats translations={{stats: (num, time) => `found ${num.toLocaleString(`en`)} packages in ${time}ms`}}/>
79-
</StatsText>
80-
<Sponsors href={`https://www.doppler.com/?utm_campaign=github_repo&utm_medium=referral&utm_content=yarn&utm_source=github`}>
81-
Thanks to <span>Doppler</span>, the Universal Secrets Platform, for sponsoring Yarn!
82-
</Sponsors>
83-
</InfoContainer>
84-
</InfoBar>
85-
<ResultsContainer>
86-
<Hits onTagClick={onTagClick} onOwnerClick={onOwnerClick} searchState={searchState} />
87-
<Pagination pagination={pagination} />
88-
<SearchFooter>
110+
const Sponsor = ({name, description, icon, url}) => <>
111+
<SponsorContainer href={url} data-tip={`<a style="font-size: 17px;" href="https://opencollective.com/yarnpkg/contribute/gold-tier-24218">Become a Gold sponsor</a>`}>
112+
Thanks to <img src={icon} alt={`${name} icon`}/> <span>{name}</span>, the {description}, for sponsoring Yarn!
113+
</SponsorContainer>
114+
</>;
115+
116+
const ResultsFound = ({pagination, onTagClick, onOwnerClick, searchState}) => {
117+
// We use a ref to have a new selection on each component creation rather than on each rerender
118+
const selectedItem = useRef(Math.trunc(Math.random() * SPONSORS.length));
119+
120+
return <>
121+
<InfoBar>
122+
<InfoContainer>
123+
<StatsText>
124+
<Stats translations={{stats: (num, time) => `found ${num.toLocaleString(`en`)} packages in ${time}ms`}}/>
125+
</StatsText>
126+
<SponsorCarousel
127+
axis={`vertical`}
128+
autoPlay={true}
129+
infiniteLoop={true}
130+
interval={4000}
131+
showArrows={false}
132+
showStatus={false}
133+
showThumbs={false}
134+
selectedItem={selectedItem.current}
135+
>
136+
{SPONSORS.map(sponsor => <Sponsor key={sponsor.name} {...sponsor} />)}
137+
</SponsorCarousel>
138+
<ReactTooltip
139+
place={`right`}
140+
offset={{right: 20}}
141+
effect={`solid`}
142+
backgroundColor={`#ffac33`}
143+
delayHide={4000}
144+
html={true}
145+
clickable={true}
146+
/>
147+
</InfoContainer>
148+
</InfoBar>
149+
<ResultsContainer>
150+
<Hits onTagClick={onTagClick} onOwnerClick={onOwnerClick} searchState={searchState} />
151+
<Pagination pagination={pagination} />
152+
<SearchFooter>
89153
Search by Algolia
90-
{` - `}
91-
<a href={`https://discourse.algolia.com/t/2016-algolia-community-gift-yarn-package-search/319`}>
154+
{` - `}
155+
<a href={`https://discourse.algolia.com/t/2016-algolia-community-gift-yarn-package-search/319`}>
92156
read how it works
93-
</a>
157+
</a>
94158
.
95-
</SearchFooter>
96-
</ResultsContainer>
97-
</>;
159+
</SearchFooter>
160+
</ResultsContainer>
161+
</>;
162+
};
98163

99164
const NoPackagesFound = styled.div`
100165
padding: 0 15px;

yarn.lock

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5643,6 +5643,7 @@ __metadata:
56435643
react-icons: ^3.10.0
56445644
react-instantsearch-dom: ^6.6.0
56455645
react-monaco-editor: ^0.36.0
5646+
react-responsive-carousel: ^3.2.22
56465647
react-scroll-into-view-if-needed: ^2.1.7
56475648
react-select: ^3.1.0
56485649
react-spinners: ^0.8.3
@@ -21708,6 +21709,15 @@ __metadata:
2170821709
languageName: node
2170921710
linkType: hard
2171021711

21712+
"react-easy-swipe@npm:^0.0.21":
21713+
version: 0.0.21
21714+
resolution: "react-easy-swipe@npm:0.0.21"
21715+
dependencies:
21716+
prop-types: ^15.5.8
21717+
checksum: 225f12a9dd410db1c790220867ab1eb58e2ef0a2bdae8541330805fc5b9905e242ab307b019f9aaed76473849a753f363baff03fa8a77e7a1860d7b41dc83ec0
21718+
languageName: node
21719+
linkType: hard
21720+
2171121721
"react-error-overlay@npm:^6.0.9":
2171221722
version: 6.0.9
2171321723
resolution: "react-error-overlay@npm:6.0.9"
@@ -21836,6 +21846,17 @@ __metadata:
2183621846
languageName: node
2183721847
linkType: hard
2183821848

21849+
"react-responsive-carousel@npm:^3.2.22":
21850+
version: 3.2.22
21851+
resolution: "react-responsive-carousel@npm:3.2.22"
21852+
dependencies:
21853+
classnames: ^2.2.5
21854+
prop-types: ^15.5.8
21855+
react-easy-swipe: ^0.0.21
21856+
checksum: 6e6ef7a2c140494bb0186af292dd8327ecb8626a3e93fb188923881c760bc996ab84346370066913481d9a4e967555e3c6386046c2aadde69496d1f41ffd5096
21857+
languageName: node
21858+
linkType: hard
21859+
2183921860
"react-scroll-into-view-if-needed@npm:^2.1.7":
2184021861
version: 2.1.7
2184121862
resolution: "react-scroll-into-view-if-needed@npm:2.1.7"

0 commit comments

Comments
 (0)