Skip to content

Commit

Permalink
Merge pull request #81 from CassandraGoose/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
CassandraGoose authored Apr 25, 2024
2 parents eb7c7b5 + e7b6d84 commit dad71dd
Show file tree
Hide file tree
Showing 18 changed files with 981 additions and 464 deletions.
26 changes: 6 additions & 20 deletions app/_components/CompetencyCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,32 +5,18 @@ export default function CompetencyCard({competency}: { competency: Competency })
return (
<div
key={competency.id}
className="border-black card rounded-md border md:max-w-[32%]"
className="border-black card rounded-md border md:w-[32%] w-full"
>
<div className="card-body h-[70%] overflow-y-hidden">
<p className="card-title" data-testid="competency-title">
<div className="card-body max-h-80">
<p className="card-title items-start grow-0" data-testid="competency-title">
{competency.title}
</p>
<p className="line-clamp-5 text-ellipsis">{competency.description}</p>
<div className="flex flex-wrap space-y-2 lg:space-x-2 lg:space-y-0 sm:space-y-0 sm:space-x-2">
{competency.contentAreas &&
competency.contentAreas.map((contentArea: ContentArea) => {
return (
<div
className="badge badge-outline h-fit md:text-xxs"
key={contentArea.id}
data-testid="competency-content-area-badge"
>
{contentArea.title}
</div>
);
})}
</div>
<p className="text-clamp-5 overflow-hidden ">{competency.description}</p>
</div>
{competency?.proofs?.length && (<div className="card-body card-actions flex flex-col bg-primary text-bright">
{competency?.proofs?.length ? (<div className="card-body card-actions flex flex-col bg-primary text-bright">
<p className="text-sm">Proof of competency:</p>
<ProofButtons competency={competency} />
</div>)}
</div>): null}
</div>
);
}
3 changes: 1 addition & 2 deletions app/actions/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,9 @@ interface ActionResult {

export async function login(formData: FormData): Promise<ActionResult> {
const username = formData.get('username');

// this is awful, but it's only for one user and it's for demo purposes.
// i don't care if this user gets messed up.
if (username === 'CassTheOG') {
if (username === 'IAmCass') {
formData.set('password', 'test123!');
}

Expand Down
108 changes: 32 additions & 76 deletions app/dashboard/[pathway]/_components/PathwayProgressDetails.tsx
Original file line number Diff line number Diff line change
@@ -1,86 +1,42 @@
"use client";
import { Fragment } from 'react';
import { Competency, Pathway, ContentArea } from '../../../lib/interface';
import PathwayProgressDetailsCompetencyList from './PathwayProgressDetailsCompetencyList';

import { useState } from "react";
import { Competency, Pathway } from "../../../lib/interface";
import Link from "next/link";
export default function PathwayProgressDetails({
pathway,
pathwayId,
}: {
pathway: Pathway;
pathwayId: string;
}) {
const totalCompetencies = pathway.contentAreas.reduce((acc, contentArea) => {
acc.push(...contentArea.competencies);
return acc;
}, [] as Competency[]);

export default function PathwayProgressDetails({ pathway, pathwayId }: { pathway: Pathway, pathwayId: string }) {
const [collapsed, setCollapsed] = useState(false);

const getCompletedCompetencies = (competencies: Competency[]) => {
return competencies.reduce((acc, competency) => {
const getCompletedCompetencies = (contentAreas: ContentArea[]) => {
return totalCompetencies.reduce((acc, competency) => {
if (competency.proofs && competency.proofs.length > 0) acc++;
return acc;
}, 0);
}

const checkCompetencyCompleted = (competency: Competency) => {
return competency.proofs && competency.proofs.length > 0;
}
};

return (
<div className="flex justify-center items-start mt-0">
<div
className="w-full border border-secondary bg-bright mt-16 rounded-md p-4"
>
<div>
<div className="flex justify-between items-center">
<p className="text-xl" data-testid="competency-progress">
{getCompletedCompetencies(pathway.competencies)} / {pathway.competencies.length} competencies met
</p>
<button
data-testid="toggle-competency-details"
className="text-4xl"
aria-controls={`${pathway.title}-details`}
aria-expanded={!collapsed}
onClick={() => setCollapsed(!collapsed)}
>
{collapsed ? "-" : "+"}
</button>
</div>
</div>
<div
className={` ${collapsed ? "block" : "hidden"} overflow-x-auto`}
id={`${pathway.title}-details`}
>
<table className="table table-xs">
<thead>
<tr>
<th className="text-primary">Completed</th>
<th className="text-primary">Competency</th>
<th className="text-primary">Description</th>
</tr>
</thead>
<tbody>
{pathway.competencies.map((competency: Competency) => (
<tr key={competency.id}>
<td>
<span className="flex items-center space-x-3 pl-4 text-xl" data-testid="completed-check">
{checkCompetencyCompleted(competency) ? '✓' : null}
</span>
</td>
<td>
<span className="flex items-center space-x-3">
<p>{competency.title}</p>
</span>
</td>
<td>
<p>{competency.description}</p>
</td>
<td>
<Link
data-testid="view-proofs"
href={`/dashboard/${pathwayId}/${competency.id}`}
className='btn btn-secondary'>
Proof
</Link>
</td>
</tr>
))}
</tbody>
</table>
</div>
</div>
<div className="mt-0 flex flex-col items-start justify-center space-y-6">
<p className="text-xl" data-testid="competency-progress">
{getCompletedCompetencies(pathway.contentAreas)} /{' '}
{totalCompetencies.length} competencies met
</p>
{pathway.contentAreas.map((contentArea) => {
return (
<Fragment key={contentArea.id}>
<PathwayProgressDetailsCompetencyList
contentArea={contentArea}
pathwayId={pathwayId}
/>
</Fragment>
);
})}
</div>
);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
'use client';

import { useState } from 'react';
import Link from 'next/link';
import { Competency, ContentArea } from '../../../lib/interface';

export default function PathwayProgressDetailsCompetencyList({ contentArea, pathwayId}: { contentArea: ContentArea, pathwayId: string }) {
const [collapsed, setCollapsed] = useState(false);

const checkCompetencyCompleted = (competency: Competency) => {
return competency.proofs && competency.proofs.length > 0;
};

return (<div key={contentArea.id} className="w-full rounded-md border border-secondary bg-bright p-4">
<div>
<div className="flex items-center justify-between">
<p className="text-xl">{contentArea.title}</p>

<button
data-testid="toggle-competency-details"
className="text-4xl"
aria-controls={`${contentArea.title}-details`}
aria-expanded={!collapsed}
onClick={() => setCollapsed(!collapsed)}
>
{collapsed ? '-' : '+'}
</button>
</div>
</div>
<div
className={` ${collapsed ? 'block' : 'hidden'} overflow-x-auto`}
id={`${contentArea.title}-details`}
>
<table className="table table-xs">
<thead>
<tr>
<th className="text-primary">Completed</th>
<th className="text-primary">Competency</th>
<th className="text-primary">Description</th>
</tr>
</thead>
<tbody>
{contentArea.competencies.map((competency: Competency) => (
<tr key={competency.id}>
<td>
<span
className="flex items-center space-x-3 pl-4 text-xl"
data-testid="completed-check"
>
{checkCompetencyCompleted(competency) ? '✓' : null}
</span>
</td>
<td>
<span className="flex items-center space-x-3">
<p>{competency.title}</p>
</span>
</td>
<td>
<p>{competency.description}</p>
</td>
<td>
<Link
data-testid="view-proofs"
href={`/dashboard/${pathwayId}/${competency.id}`}
className="btn btn-secondary"
>
Proof
</Link>
</td>
</tr>
))}
</tbody>
</table>
</div>
</div>);
}
2 changes: 1 addition & 1 deletion app/dashboard/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export default async function Page() {
notFound();
}

const pathways = userPathways.pathways;
const pathways = userPathways.pathways || [];

const createCardActionChild = (id: number) => (
<div className="card-actions">
Expand Down
6 changes: 3 additions & 3 deletions app/lib/interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,15 @@ export interface Pathway {
createdAt: string | Date;
title: string;
description: string;
competencies: Array<Competency>;
approved: boolean;
contentAreas: Array<ContentArea>;
}

export interface ContentArea {
id: number;
createdAt: string | Date;
title: string;
description: string;
competencies: Array<Competency>;
}

export interface Competency {
Expand All @@ -49,7 +50,6 @@ export interface Competency {
title: string;
description: string;
proofs?: Array<Proof>;
contentAreas?: Array<ContentArea>;
}

export interface Proof {
Expand Down
Loading

0 comments on commit dad71dd

Please sign in to comment.