Skip to content

Commit 9983320

Browse files
author
Carms Ng
authored
Merge pull request #29 from coderbunker/avatar-link
[UPD] avatar to be linked to the corresponding profile
2 parents f1609fa + 310d348 commit 9983320

File tree

6 files changed

+75
-42
lines changed

6 files changed

+75
-42
lines changed

src/components/carousel-card.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@ import { FiLinkedin, FiGithub, FiChevronLeft, FiChevronRight } from 'react-icons
55
import { GatsbyImage } from "gatsby-plugin-image";
66
import team from '../assets/content/team.json';
77

8-
export default function CarouselCard({pic, index, count, activeIndex, setActiveIndex}) {
8+
export default function CarouselCard({ pic, index, count, teamIndex, setTeamIndex }) {
99
// handle carousel navigation
1010
const handlePrev = () => {
11-
setActiveIndex(activeIndex - 1)
11+
setTeamIndex(teamIndex - 1)
1212
}
1313
const handleNext = () => {
14-
setActiveIndex(activeIndex + 1)
14+
setTeamIndex(teamIndex + 1)
1515
}
1616

1717
// set the person based on the image
@@ -20,7 +20,7 @@ export default function CarouselCard({pic, index, count, activeIndex, setActiveI
2020
})[0]
2121

2222
return (
23-
<CarouselCardStyles className={`${activeIndex === index ? "active" : ""}`}>
23+
<CarouselCardStyles className={`${teamIndex === index ? "active" : ""}`}>
2424
<div className="flex md:flex-row-reverse overflow-hidden bg-peach md:bg-white">
2525
<GatsbyImage
2626
image={pic.node.childImageSharp.gatsbyImageData}

src/components/carousel.js

Lines changed: 27 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,42 @@
1-
import React, { useState } from 'react';
1+
import React from 'react';
22
import { graphql, useStaticQuery } from 'gatsby';
33
import CarouselCard from "./carousel-card";
44

5-
export default function Carousel() {
6-
// state to determine the active slide for the carousel
7-
const [activeIndex, setActiveIndex] = useState(0);
8-
5+
export default function Carousel({ teamIndex, setTeamIndex }) {
96
// query all team pics
107
const data = useStaticQuery(graphql`{
11-
allFile(filter: {absolutePath: {regex: "/portraits/"}}, sort: {fields: base}) {
12-
edges {
13-
node {
14-
base
15-
childImageSharp {
16-
gatsbyImageData(
17-
width: 500,
18-
placeholder: BLURRED,
19-
layout: CONSTRAINED
20-
)
8+
allFile(filter: {absolutePath: {regex: "/portraits/"}}, sort: {fields: base}) {
9+
edges {
10+
node {
11+
id
12+
base
13+
childImageSharp {
14+
gatsbyImageData(
15+
width: 500,
16+
placeholder: BLURRED,
17+
layout: CONSTRAINED
18+
)
19+
}
2120
}
22-
id
2321
}
2422
}
25-
}
26-
}
27-
`);
23+
}`);
24+
2825
const pics = data.allFile.edges;
26+
2927
return (
3028
<>
3129
{pics.map((pic, index) => {
32-
return (<CarouselCard pic={pic} key={pic.node.id} index={index} count={pics.length} activeIndex={activeIndex} setActiveIndex={setActiveIndex}/>)
30+
return (
31+
<CarouselCard
32+
pic={pic}
33+
key={pic.node.id}
34+
index={index}
35+
count={pics.length}
36+
teamIndex={teamIndex}
37+
setTeamIndex={setTeamIndex}
38+
/>
39+
)
3340
})}
3441
</>
3542
)

src/components/hero.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import LogoGarden from '../components/logo-garden';
77
import SiteBorderStyles from '../styles/SiteBorderStyles';
88
import StackedAvatar from "./stacked-avatar";
99

10-
export default function Hero() {
10+
export default function Hero({ sectionRefs, setTeamIndex, pausedRef }) {
1111
return (
1212
<HeroStyles>
1313
<SiteBorderStyles>
@@ -25,7 +25,11 @@ export default function Hero() {
2525
<p className="text-1xl md:text-2xl mt-2">
2626
<Trans>We empower freelancer community to excel in long term projects.</Trans>
2727
</p>
28-
<StackedAvatar />
28+
<StackedAvatar
29+
sectionRefs={sectionRefs}
30+
setTeamIndex={setTeamIndex}
31+
pausedRef={pausedRef}
32+
/>
2933

3034
</div>
3135

src/components/stacked-avatar.js

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import * as React from "react";
22
import { graphql, useStaticQuery } from 'gatsby';
33
import { GatsbyImage } from "gatsby-plugin-image";
44

5-
export default function StackedAvatar() {
5+
export default function StackedAvatar({ sectionRefs, setTeamIndex, pausedRef }) {
66
// query all team pics
77
const data = useStaticQuery(graphql`{
88
allFile(filter: {absolutePath: {regex: "/portraits/"}}, sort: {fields: base}) {
@@ -22,20 +22,36 @@ export default function StackedAvatar() {
2222
}
2323
}`);
2424

25+
const handleClick = (ev) => {
26+
// Pause Observer
27+
pausedRef.current = true
28+
// Update Team Index
29+
const updatedTeamIndex = parseInt(ev.currentTarget.dataset.team)
30+
setTeamIndex(updatedTeamIndex)
31+
// Find Team Section Top
32+
const top = sectionRefs.current[2].offsetTop
33+
// Navigate to the Team Section
34+
window.scrollTo({ top, behavior: 'smooth' })
35+
setTimeout(() => {
36+
pausedRef.current = false
37+
}, 1000);
38+
}
39+
2540
const pics = data.allFile.edges;
2641
return (
2742
<div className="py-8">
2843
{pics.map((pic, i) => {
2944
const zIndex = pics.length - i;
3045
const translateX = i * -30;
3146
return (
32-
<GatsbyImage
33-
image={pic.node.childImageSharp.gatsbyImageData}
34-
className="inline-block rounded-full"
35-
style={{width: `75px`, height: `75px`, zIndex: `${zIndex}`, border: `1px solid var(--white)`, transform: `translateX(${translateX}%)`}}
36-
imgStyle={{objectPosition: `top center`}}
37-
key={pic.node.childImageSharp.id}
38-
alt="pic.node.base.split('.')[0]" />
47+
<button data-team={i} onClick={handleClick} key={pic.node.childImageSharp.id}>
48+
<GatsbyImage
49+
image={pic.node.childImageSharp.gatsbyImageData}
50+
className="inline-block rounded-full"
51+
style={{width: `75px`, height: `75px`, zIndex: `${zIndex}`, border: `1px solid var(--white)`, transform: `translateX(${translateX}%)`}}
52+
imgStyle={{objectPosition: `top center`}}
53+
alt="pic.node.base.split('.')[0]" />
54+
</button>
3955
);
4056
}).slice(0, 7)}
4157
{/* TODO: handle representation for members with count above 7 */}

src/components/team.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import SiteBorderStyles from '../styles/SiteBorderStyles';
66
import BackgroundImage from "./bg-image";
77
import Carousel from "./carousel";
88

9-
export default function Team() {
9+
export default function Team({ teamIndex, setTeamIndex }) {
1010
return (
1111
<TeamStyles>
1212
<SiteBorderStyles className="wrapper">
@@ -23,7 +23,7 @@ export default function Team() {
2323
</p>
2424
</div>
2525
{/* Carousel */}
26-
<Carousel />
26+
<Carousel teamIndex={teamIndex} setTeamIndex={setTeamIndex} />
2727
</SiteBorderStyles>
2828
<div className="bg-img-wrapper">
2929
<BackgroundImage style={{width: `48vw`}}/>

src/pages/index.js

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, { useEffect, useRef } from "react"
1+
import React, { useState, useEffect, useRef } from "react"
22
import { useTranslation } from 'gatsby-plugin-react-i18next';
33
import { graphql } from 'gatsby';
44
import Layout from "../components/layout"
@@ -14,7 +14,11 @@ import AOS from 'aos';
1414
import 'aos/dist/aos.css';
1515

1616
export default function IndexPage() {
17-
// you can access the elements with itemsRef.current[n]
17+
// Set who in the team is being featured
18+
const pausedRef = useRef(false);
19+
const [teamIndex, setTeamIndex ] = useState(0);
20+
21+
// You can access the elements with itemsRef.current[n]
1822
const sectionRefs = useRef([]);
1923

2024
// Compile all the refs
@@ -31,7 +35,7 @@ export default function IndexPage() {
3135

3236
// Set up observer
3337
const observer = new IntersectionObserver(([entry]) => {
34-
if (entry.isIntersecting) {
38+
if (entry.isIntersecting && !pausedRef.current) {
3539
const refIndex = parseInt(entry.target.dataset.step)
3640
const top = sectionRefs.current[refIndex].offsetTop
3741
window.scrollTo({ top, behavior: 'smooth' })
@@ -54,15 +58,17 @@ export default function IndexPage() {
5458
}
5559
})
5660
}
57-
}, [sectionRefs])
61+
}, [sectionRefs, pausedRef])
5862

5963
const {t} = useTranslation();
6064
return (
6165
<Layout>
6266
<Seo title={t('Home')} />
63-
<div ref={addToRefs} data-step="0"><Hero /></div>
67+
<div ref={addToRefs} data-step="0">
68+
<Hero sectionRefs={sectionRefs} setTeamIndex={setTeamIndex} pausedRef={pausedRef} />
69+
</div>
6470
<div ref={addToRefs} data-step="1"><Service /></div>
65-
<div ref={addToRefs} data-step="2"><Team /></div>
71+
<div ref={addToRefs} data-step="2"><Team teamIndex={teamIndex} setTeamIndex={setTeamIndex} /></div>
6672
<div ref={addToRefs} data-step="3"><Steps /></div>
6773
<div ref={addToRefs} data-step="4"><Join /></div>
6874
<div ref={addToRefs} data-step="5"><Contact /></div>

0 commit comments

Comments
 (0)