Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

18 new jurisdictions via config #30

Merged
merged 10 commits into from
May 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion __tests__/index.test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import '@testing-library/jest-dom';
import { render, screen } from '@testing-library/react';
import TopicsPage from '../src/app/page';
import Page from '../src/app/page';
import RootLayout from '../src/app/layout';
import { fetchInterviews } from '../src/data/fetchInterviewData';

Expand Down
3 changes: 3 additions & 0 deletions prefix.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
const prefix = process.env.NEXT_PUBLIC_BASE_PATH || '';

export { prefix };
8 changes: 5 additions & 3 deletions src/app/[topic]/page.tsx → src/app/[path]/[topic]/page.tsx
Original file line number Diff line number Diff line change
@@ -1,20 +1,22 @@
import { GetStaticPathsResult } from 'next';
import { legalTopics, Topic } from '../../config/topics.config';
import { legalTopics, Topic } from '../../../config/topics.config';

interface PageProps {
params: {
topic: string;
path: string;
};
}

const Page = ({ params }: PageProps) => {
const { topic } = params;
const { topic, path } = params;
return <div>Topic: {topic}</div>;
};

export default Page;

export async function generateStaticParams() {
export async function generateStaticParams({ params }) {
const { path } = params;
return legalTopics.map((topic) => ({
topic: topic.name.toLowerCase(),
}));
Expand Down
13 changes: 13 additions & 0 deletions src/app/[path]/layout.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { pathToServerConfig } from '../../config/formSources.config';

// This is only necessary because there is a bug within next that doesnt allow static params to be passed from page to page properly. This layout only exists to assist in passing said props

export async function generateStaticParams() {
return Object.keys(pathToServerConfig).map((key) => ({
path: key.toLowerCase(),
}));
}

export default function Layout({ children }) {
return <>{children}</>;
}
29 changes: 29 additions & 0 deletions src/app/[path]/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import HowItWorksSection from '../components/HowItWorksSection';
import TopicsSection from '../components/TopicsSection';
import HeroSection from '../components/HeroSection';
import { fetchInterviews } from '../../data/fetchInterviewData';

interface PageProps {
params: {
path: string;
};
}

const Page = async ({ params }: PageProps) => {
const { path } = params;
const { interviewsByTopic, isError } = await fetchInterviews(path);

return (
<div>
<HeroSection />
<HowItWorksSection />
<TopicsSection
path={path}
interviews={interviewsByTopic}
isError={isError}
/>
</div>
);
};

export default Page;
3 changes: 2 additions & 1 deletion src/app/components/Footer.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import Link from 'next/link';
import Image from 'next/image';
import { prefix } from '../../../prefix';

export default function Footer() {
return (
Expand All @@ -9,7 +10,7 @@ export default function Footer() {
<div className="col">
<a href="https://suffolk.edu">
<Image
src="/suffolk_law.png"
src={`${prefix}/suffolk_law.png`}
alt="Suffolk University Law School"
className="img-fluid mb-2 suffolk-logo"
width={497}
Expand Down
8 changes: 3 additions & 5 deletions src/app/components/NavigationBar.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import Link from 'next/link';
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
import { faLanguage } from '@fortawesome/free-solid-svg-icons';
import Image from 'next/image';
import { prefix } from '../../../prefix';

export default function NavigationBar() {
return (
Expand All @@ -11,10 +11,8 @@ export default function NavigationBar() {
>
<div className="container">
<Link href="/" className="navbar-brand d-flex align-items-center">
<Image
src="/logo-short.png"
width={66.5}
height={40}
<img
src={`${prefix}/logo-short.png`}
alt="Logo"
className="logo-image me-2"
/>
Expand Down
46 changes: 27 additions & 19 deletions src/app/components/TopicCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ interface TopicCardProps {
interviews: any[];
index: number;
serverUrl: string;
path: string;
}

interface IconProps {
Expand All @@ -28,10 +29,15 @@ const FontAwesomeIcon = ({
return <i className={`fas fa-${iconName} ${className}`} style={style}></i>;
};

const TopicCard = ({ topic, interviews, index, serverUrl }: TopicCardProps) => {
const TopicCard = ({
topic,
interviews,
index,
serverUrl,
path,
}: TopicCardProps) => {
const [isExpanded, setIsExpanded] = useState(false);
const visibilityClass = index > 8 ? 'hidden' : '';

const displayInterviews = isExpanded
? interviews.slice(0, Math.min(10, interviews.length))
: interviews.slice(0, 3);
Expand All @@ -54,13 +60,10 @@ const TopicCard = ({ topic, interviews, index, serverUrl }: TopicCardProps) => {
key={topic.codes[0]}
>
<Link
href={`/${topic.name.toLowerCase()}`}
href={`/${path}/${topic.name.toLowerCase()}`}
className="text-decoration-none text-dark"
>
<div
className="card topic-card m-1 h-100"
onClick={(e) => e.preventDefault()}
>
<div className="card topic-card m-1 h-100">
<div className="card-header d-flex align-items-center">
<div
style={{ minWidth: '40px', minHeight: '40px' }}
Expand All @@ -75,18 +78,23 @@ const TopicCard = ({ topic, interviews, index, serverUrl }: TopicCardProps) => {
className="tag-container"
style={{ maxHeight: isExpanded ? '800px' : '200px' }}
>
{displayInterviews.map((interview, index) => (
<span
key={index}
className="form-tag text-decoration-none"
onClick={(e) => {
e.preventDefault();
handleNavigation(serverUrl + interview.link);
}}
>
{interview.metadata.title}
</span>
))}
{displayInterviews.map((interview, index) => {
if (interview.metadata && interview.metadata.title) {
return (
<span
key={index}
className="form-tag text-decoration-none"
onClick={(e) => {
e.preventDefault();
handleNavigation(interview.serverUrl + interview.link);
}}
>
{interview.metadata.title}
</span>
);
}
return null;
})}
</div>
{interviews.length > 3 && (
<div className="show-container">
Expand Down
44 changes: 44 additions & 0 deletions src/app/components/TopicsSection.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import { legalTopics } from '../../config/topics.config';
import { formSources } from '../../config/formSources.config';
import TopicCard from './TopicCard';
import ShowAllToggle from './ShowAllToggle';

const TopicsSection = async ({ path, interviews, isError }) => {
if (isError) {
return <div>Error fetching data.</div>;
}

const server =
formSources.docassembleServers.find((server) => server.path === path) ||
formSources.docassembleServers[0];
const serverUrl = server.url;

const filteredTopics = legalTopics
.sort((a, b) => b.priority - a.priority)
.filter(
(topic) => topic.always_visible || interviews[topic.name].length > 0
);

return (
<section id="topics">
<div className="container">
<h2>Browse court forms by category</h2>
<div className="row row-cols-1 row-cols-md-3 g-5 card-container">
{filteredTopics.map((topic, index) => (
<TopicCard
key={topic.codes[0]}
topic={topic}
interviews={interviews[topic.name] || []}
path={path}
serverUrl={serverUrl}
index={index}
/>
))}
</div>
{filteredTopics.length > 9 && <ShowAllToggle />}
</div>
</section>
);
};

export default TopicsSection;
8 changes: 0 additions & 8 deletions src/app/globals.css
Original file line number Diff line number Diff line change
Expand Up @@ -192,14 +192,6 @@ h5,
font-weight: 600;
}

h1,
h2,
h3,
h4,
h5 {
margin-top: 2em;
}

body {
font-family: 'Inter';
}
Expand Down
50 changes: 9 additions & 41 deletions src/app/page.tsx
Original file line number Diff line number Diff line change
@@ -1,52 +1,20 @@
import HeroSection from './components/HeroSection';
import HowItWorksSection from './components/HowItWorksSection';
import TopicsSection from './components/TopicsSection';
import HeroSection from './components/HeroSection';
import { fetchInterviews } from '../data/fetchInterviewData';
import TopicCard from './components/TopicCard';
import { legalTopics } from '../config/topics.config';
import ShowAllToggle from './components/ShowAllToggle';
import { formSources } from '../config/formSources.config';

export default async function TopicsPage() {
const interviewsResult = await fetchInterviews();
const { interviewsByTopic } = interviewsResult;

// Modify this to account for various jurisdictions
const serverKey = 'suffolkListLab';
const server = formSources.docassembleServers.find(
(server) => server.key === serverKey
);
const url = server ? server.url : 'https://apps.suffolklitlab.org';

const filteredTopics = legalTopics
.sort((a, b) => b.priority - a.priority)
.filter(
(topic, index) =>
topic.always_visible ||
(interviewsByTopic[topic.name] &&
interviewsByTopic[topic.name].length > 0)
);
export default async function Page() {
const { interviewsByTopic, isError } = await fetchInterviews('ma');

return (
<div>
<HeroSection />
<HowItWorksSection />
<section id="topics">
<div className="container">
<h2>Browse court forms by category</h2>
<div className="row row-cols-1 row-cols-md-3 g-5 card-container">
{filteredTopics.map((topic, index) => (
<TopicCard
key={topic.codes[0]}
topic={topic}
interviews={interviewsByTopic[topic.name] || []}
index={index}
serverUrl={url}
/>
))}
</div>
{filteredTopics.length > 9 && <ShowAllToggle />}
</div>
</section>
<TopicsSection
path={'ma'}
interviews={interviewsByTopic}
isError={isError}
/>
</div>
);
}
11 changes: 11 additions & 0 deletions src/config/formSources.config.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
export const pathToServerConfig = {
ma: {
path: 'ma',
servers: ['Suffolk LIT Lab', 'Greater Boston Legal Services'],
},
gb: {
path: 'gb',
servers: ['Greater Boston Legal Services'],
},
};

export const formSources = {
docassembleServers: [
{
Expand Down
Loading