Skip to content

Commit

Permalink
Redireccionar URL de acuerdo al lenguaje
Browse files Browse the repository at this point in the history
  • Loading branch information
arendondiosa committed Jan 29, 2024
1 parent 1c77c95 commit cc07b8d
Show file tree
Hide file tree
Showing 7 changed files with 177 additions and 25 deletions.
15 changes: 6 additions & 9 deletions src/app/[lang]/components/NavbarCustom.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use client';

import React from 'react';
import { useRouter, usePathname } from 'next/navigation';
import { useRouter, useSelectedLayoutSegments } from 'next/navigation';
import Link from 'next/link';
import propTypes from 'prop-types';
import Container from 'react-bootstrap/Container';
Expand All @@ -15,10 +15,10 @@ import { locales } from '@/utils/locale';
const NavbarCustom = ({ lang }) => {
const i18nDictionary = useI18n();
const router = useRouter();
const pathname = usePathname();
const urlSegments = useSelectedLayoutSegments();

const onChangeLocale = (locale) => {
router.replace(pathname, { locale });
router.replace(`/${locale}/${urlSegments.join('/')}`);
};

return (
Expand Down Expand Up @@ -54,16 +54,13 @@ const NavbarCustom = ({ lang }) => {
</Nav.Link>
</Nav>
<Nav>
<NavDropdown
title={lang}
id="collapsible-nav-dropdown"
onChange={(e) => onChangeLocale(e.target.value)}>
<NavDropdown title={lang} id="collapsible-nav-dropdown" onSelect={onChangeLocale}>
{locales.map(
(locale) =>
locale !== lang && (
<Nav.Link as={Link} key={locale} href={`/${locale}`}>
<NavDropdown.Item key={locale} eventKey={locale}>
{locale}
</Nav.Link>
</NavDropdown.Item>
)
)}
</NavDropdown>
Expand Down
80 changes: 80 additions & 0 deletions src/app/[lang]/keynotes/[uniquepage]/page.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
import React from 'react';
import propTypes from 'prop-types';
import { notFound } from 'next/navigation';
import Image from 'next/image';
import Link from 'next/link';
import speakerslist from '@/data/speakers.json';
import talksList from '@/data/talks.json';
import Avatar from '@/app/[lang]/speakers/images/avatar.jpeg';

export async function generateStaticParams() {
return speakerslist.map((p) => ({
uniquepage: p.id.toString()
}));
}

const Speaker = ({ params: { uniquepage, lang } }) => {
const speaker = speakerslist.find((p) => p.id.toString() === uniquepage);
let talks = [];

if (!speaker) {
console.info('speaker not found');
notFound();
} else {
talks = talksList.filter((talk) => talk.speakers.includes(speaker.id));
}

return (
<>
<Image src={Avatar} width={200} height={200} placeholder="blur" alt="Picture of the author" />
<h1>
{speaker.first_name} {speaker.last_name}
</h1>
<h2>{speaker.affiliation}</h2>
<h3>{speaker.country_residence}</h3>
<ul>
<li>
<Link href={speaker.facebook} target="_blank">
{speaker.facebook}
</Link>
</li>
<li>
<Link href={speaker.twitter} target="_blank">
{speaker.twitter}
</Link>
</li>
<li>
<Link href={speaker.linkedin} target="_blank">
{speaker.linkedin}
</Link>
</li>
<li>
<Link href={speaker.github} target="_blank">
{speaker.github}
</Link>
</li>
<li>
<Link href={speaker.website} target="_blank">
{speaker.website}
</Link>
</li>
</ul>
{speaker.biography ? <p>{speaker.biography[lang]}</p> : null}
<h3>Talks</h3>
{talks.map((talk) => (
<Link key={talk.id} href={`/talks/${talk.id}`} locale={lang}>
<h1>{talk.title[lang]}</h1>
</Link>
))}
</>
);
};

Speaker.propTypes = {
params: propTypes.shape({
uniquepage: propTypes.string,
lang: propTypes.string
})
};

export default Speaker;
Binary file added src/app/[lang]/keynotes/images/avatar.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
49 changes: 49 additions & 0 deletions src/app/[lang]/keynotes/page.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
'use client';

import React from 'react';
import propTypes from 'prop-types';
import Row from 'react-bootstrap/Row';
import Col from 'react-bootstrap/Col';
import Image from 'next/image';
import Link from 'next/link';
import speakerslist from '@/data/speakers.json';

import Avatar from '@/app/[lang]/speakers/images/avatar.jpeg';

const Speakers = ({ params: { lang } }) => {
return (
<>
{speakerslist.map(
(speaker) =>
speaker.type === 'keynote' && (
<Row key={speaker.id}>
<Col md={4}>
<Link href={`/keynotes/${speaker.id}`} locale={lang}>
<Image src={Avatar} width={200} height={200} alt="Picture of the author" />
</Link>
</Col>
<Col md={8}>
<Link href={`/keynotes/${speaker.id}`} locale={lang}>
<h1>
{speaker.first_name} {speaker.last_name}
</h1>
<h2>{speaker.affiliation}</h2>
</Link>
<Link href={`https://twitter.com/${speaker.twitter}`} target="_blank">
<span>{speaker.twitter}</span>
</Link>
</Col>
</Row>
)
)}
</>
);
};

Speakers.propTypes = {
params: propTypes.shape({
lang: propTypes.string.isRequired
}).isRequired
};

export default Speakers;
11 changes: 10 additions & 1 deletion src/app/[lang]/layout.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

import React, { useState, useEffect } from 'react';
import props from 'prop-types';
import Container from 'react-bootstrap/Container';
import Row from 'react-bootstrap/Row';
import Col from 'react-bootstrap/Col';
import NavbarCustom from '@/app/[lang]/components/NavbarCustom';
import { I18nContext } from '@/contexts/I18nContext';

Expand All @@ -24,7 +27,13 @@ const Root = ({ children, params: { lang } }) => {
<html lang={lang}>
<body>
<NavbarCustom lang={lang} />
{children}
<main>
<Container>
<Row className="justify-content-md-center">
<Col lg={10}>{children}</Col>
</Row>
</Container>
</main>
</body>
</html>
</I18nContext.Provider>
Expand Down
45 changes: 30 additions & 15 deletions src/app/[lang]/speakers/page.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,41 @@

import React from 'react';
import propTypes from 'prop-types';
import Row from 'react-bootstrap/Row';
import Col from 'react-bootstrap/Col';
import Image from 'next/image';
import Link from 'next/link';
import speakerslist from '@/data/speakers.json';

import Avatar from '@/app/[lang]/speakers/images/avatar.jpeg';

const Speakers = ({ params: { lang } }) => {
return (
<main>
{speakerslist.map((speaker) => (
<div key={speaker.id}>
<Link href={`./speakers/${speaker.id}`} locale={lang}>
<h1>
{speaker.first_name} {speaker.last_name}
</h1>
<h2>{speaker.affiliation}</h2>
</Link>
<Link href={`https://twitter.com/${speaker.twitter}`} target="_blank">
<span>{speaker.twitter}</span>
</Link>
</div>
))}
</main>
<>
{speakerslist.map(
(speaker) =>
speaker.type === 'speaker' && (
<Row key={speaker.id}>
<Col md={4}>
<Link href={`/${lang}/speakers/${speaker.id}`} locale={lang}>
<Image src={Avatar} width={200} height={200} alt="Picture of the author" />
</Link>
</Col>
<Col md={8}>
<Link href={`/${lang}/speakers/${speaker.id}`} locale={lang}>
<h1>
{speaker.first_name} {speaker.last_name}
</h1>
<h2>{speaker.affiliation}</h2>
</Link>
<Link href={`https://twitter.com/${speaker.twitter}`} target="_blank">
<span>{speaker.twitter}</span>
</Link>
</Col>
</Row>
)
)}
</>
);
};

Expand Down
2 changes: 2 additions & 0 deletions src/data/speakers.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
[
{
"id": "john-doe",
"type": "speaker",
"first_name": "John",
"last_name": "Doe",
"email": "[email protected]",
Expand All @@ -20,6 +21,7 @@
},
{
"id": "jane-doe",
"type": "keynote",
"first_name": "Jane",
"last_name": "Doe",
"email": "[email protected]",
Expand Down

0 comments on commit cc07b8d

Please sign in to comment.