diff --git a/src/components/atoms/sidebar-item.tsx b/src/components/atoms/sidebar-item.tsx index 289ab38..ce7576c 100644 --- a/src/components/atoms/sidebar-item.tsx +++ b/src/components/atoms/sidebar-item.tsx @@ -1,4 +1,4 @@ -import { useHash } from 'react-use'; +import { useLocation } from 'react-use'; import { MAIN_SECTION } from '@/constants/section'; import type { Section } from '@/types/data'; @@ -12,7 +12,7 @@ export interface Props { } const SidebarItem = ({ section, icon }: Props) => { - const [hash] = useHash(); + const { hash } = useLocation(); const href = `#${section}`; const active = hash === '' ? section === MAIN_SECTION : hash === href; diff --git a/src/components/sections/experience-section.astro b/src/components/sections/experience-section.astro index a386bfe..41d2238 100644 --- a/src/components/sections/experience-section.astro +++ b/src/components/sections/experience-section.astro @@ -1,8 +1,18 @@ --- import SectionCard from '@/atoms/section-card.astro'; +import Typography from '@/atoms/typography.astro'; +import type { Section } from '@/types/data'; import type { ExperienceSection } from '@/types/experience-section'; export interface Props extends ExperienceSection {} + +const { + config: { title }, +} = Astro.props; + +const section: Section = 'experience'; --- -Experience section +{title} + diff --git a/src/components/sections/favorites-section.astro b/src/components/sections/favorites-section.astro index 62da0b5..3c97766 100644 --- a/src/components/sections/favorites-section.astro +++ b/src/components/sections/favorites-section.astro @@ -1,8 +1,18 @@ --- import SectionCard from '@/atoms/section-card.astro'; +import Typography from '@/atoms/typography.astro'; +import type { Section } from '@/types/data'; import type { FavoritesSection } from '@/types/favorites-section'; export interface Props extends FavoritesSection {} + +const { + config: { title }, +} = Astro.props; + +const section: Section = 'favorites'; --- -Favorites section +{title} + diff --git a/src/components/sections/main-section.astro b/src/components/sections/main-section.astro index 63fa703..0508b1e 100644 --- a/src/components/sections/main-section.astro +++ b/src/components/sections/main-section.astro @@ -6,6 +6,7 @@ import IconButton from '@/atoms/icon-button.astro'; import SectionCard from '@/atoms/section-card.astro'; import Tag from '@/atoms/tag.astro'; import Typography from '@/atoms/typography.astro'; +import type { Section } from '@/types/data'; import type { MainSection } from '@/types/main-section'; export interface Props extends MainSection {} @@ -20,9 +21,11 @@ const { action: { label, url, downloadedFileName }, tags, } = Astro.props; + +const section: Section = 'main'; --- - +
- {fullName} + {fullName} {role}
{ diff --git a/src/components/sections/portfolio-section.astro b/src/components/sections/portfolio-section.astro index dd12910..8f9d557 100644 --- a/src/components/sections/portfolio-section.astro +++ b/src/components/sections/portfolio-section.astro @@ -1,8 +1,18 @@ --- import SectionCard from '@/atoms/section-card.astro'; +import Typography from '@/atoms/typography.astro'; +import type { Section } from '@/types/data'; import type { PortfolioSection } from '@/types/portfolio-section'; export interface Props extends PortfolioSection {} + +const { + config: { title }, +} = Astro.props; + +const section: Section = 'portfolio'; --- -Portfolio section +{title} + diff --git a/src/components/sections/skills-section.astro b/src/components/sections/skills-section.astro index fc7cfc7..b5ee281 100644 --- a/src/components/sections/skills-section.astro +++ b/src/components/sections/skills-section.astro @@ -2,6 +2,7 @@ import SectionCard from '@/atoms/section-card.astro'; import Typography from '@/atoms/typography.astro'; import SkillSubsection from '@/organisms/skill-subsection.astro'; +import type { Section } from '@/types/data'; import type { SkillsSection } from '@/types/skills-section'; export interface Props extends SkillsSection {} @@ -10,10 +11,12 @@ const { config: { title }, skillSets, } = Astro.props; + +const section: Section = 'skills'; --- - - {title} + + {title}
{skillSets.map((skillSet) => )}
diff --git a/src/components/sections/testimonials-section.astro b/src/components/sections/testimonials-section.astro index a366ec3..1e1d13d 100644 --- a/src/components/sections/testimonials-section.astro +++ b/src/components/sections/testimonials-section.astro @@ -3,6 +3,7 @@ import Divider from '@/atoms/divider.astro'; import SectionCard from '@/atoms/section-card.astro'; import Typography from '@/atoms/typography.astro'; import Testimonial from '@/organisms/testimonial.astro'; +import type { Section } from '@/types/data'; import type { TestimonialsSection } from '@/types/testimonials-section'; export interface Props extends TestimonialsSection {} @@ -11,10 +12,12 @@ const { testimonials, config: { title }, } = Astro.props; + +const section: Section = 'testimonials'; --- - - {title} + + {title}
{ testimonials.map((testimonial, index) => ( diff --git a/src/pages/index.astro b/src/pages/index.astro index f56f763..672c126 100644 --- a/src/pages/index.astro +++ b/src/pages/index.astro @@ -46,4 +46,10 @@ const { seo, ...dataWithoutSeo } = data;
+ diff --git a/src/scripts/updateHash.ts b/src/scripts/updateHash.ts new file mode 100644 index 0000000..fa44b77 --- /dev/null +++ b/src/scripts/updateHash.ts @@ -0,0 +1,28 @@ +import type { Data } from '@/types/data'; + +const updateHash = (data: Data) => { + const { seo, ...dataWithoutSeo } = data; + + const distancesToHeadingBottom = Object.keys(dataWithoutSeo) + .flatMap((section) => { + const sectionWrapper = document.getElementById(`${section}-heading`); + + if (!sectionWrapper) return []; + + const { bottom } = sectionWrapper.getBoundingClientRect(); + + return { + section, + bottom, + }; + }) + .filter((section) => section.bottom > 0); + + const currentSection = distancesToHeadingBottom.reduce((previous, current) => + previous.bottom < current.bottom ? previous : current + ); + + window.history.pushState({}, '', `${window.location.pathname}#${currentSection.section}`); +}; + +export default updateHash;