GoalComplete a Next.js tool to help parse and visualize a graph data structure as an adjacency matrix.
ScoreOut of 80 - for code quality, functionality, completedness, fidelity, animations and overall design.
Maximum Time3 hours
A->B for a connection from node A to node B), and
the app generates a corresponding adjacency matrix. This matrix
visually represents connections between nodes, helping users
understand graph structures easily.
TextArea, following a specific
notation (like A->B), and submit it for processing.
dashboard/ route. The presence of a cookie is checked
in the dashboard to ensure the user is authenticated.
Dashboard component updates its state with the nodes
and edges returned by the server.
Matrix component renders the adjacency matrix based on
the user input.
useState,
useEffect) to manage state and handle dynamic updates.
Suspense will be used for managing asynchronous actions.
src/. This is where you
will spend your time writing designing and code. You can ignore the
folder named /instructions.
npm i via the terminal in the
src/ folder to install the necessary packages.
src/app/page.tsx file. Use the following GIF
for your reference for this task:
<section> element for layout and apply
Tailwind CSS classes to center content both vertically and
horizontally.
<div> containing a
welcome message. Add Tailwind classes to add a
pulsing animation and gradient effect from teal colors to
make the text dynamic.
<div> with a 2px border, 5px padding and
background color bg-slate-50 to create a rounded
container. Include a <label> with "What's
your name?".
Input component with a suitable id,
type, and placeholder text.
Button component with
type = "submit" and theme = "primary".
redirectToDashboard). If the action fails, set an
error using the state variable error.
border-gray-300,
rounded, text-gray-600 for final
touches, ensuring consistent design and spacing.
Write code for this task within the TASK 2.2 comment fence in
page.tsx
src/app/actions.ts file.redirectToDashboard function based on the
following steps:
formData and cast it as a
string.
"Hey, your name is missing!" if it is.
cookies API to set a cookie with the name
gr-name and the cleaned value.
redirect function to navigate the user to
/dashboard.
Write code for this task within the TASK 2.4 comment fence in
actions.ts
npm run dev on the src/ folder. Commit and
push your work to your personal forked repository. You may now move
on to Task 3.
src/app/dashboard/page.tsx file.cookies function to retrieve the
gr-name cookie from the user's browser.
gr-name cookie does not exist or has no
value, use the redirect function to send the user
back to the homepage (/).
gr-name cookie exists, render the
Header component wrapped inside a
Suspense tag with a fallback of
HeaderSkeleton.
Dashboard component to render the dashboard
interface.
Write code for this task within the TASK 3.2 comment fence in
page.tsx
src/app/dashboard/actions.tsx file.renderGraph
server action, which is called when a
user submits graph notation data via the "Generate" button in the
dashboard.tsx component.formData as input, from which the
graph-notation key has been extracted as a string.dashboard.tsx.renderGraph function:
source->target.
A->B B->C C->D
source->target pattern, you should throw an
error and return a helpful error message.
Hey, there was an error parsing line 3 of your graph
notation!.
Hey, there was an error parsing your graph
notation!.
6 nodes, set by the
MAX_NODES constant. If the input contains more
than 6 unique nodes, slice the list to only include the
first 6.
Set to ensure uniqueness
(since a node may appear in multiple edges).
Set, ensuring that
duplicate edges are not included.
edges: An array of unique edges, each
represented as a concatenation of the source and target
(e.g., "AB").
nodes: An array of unique node names, up to a
maximum of 6.
Here are a few examples of valid inputs to the server action
(after parsing formData) and their expected outputs:
A->B B->C C->D
Output
{
edges: ["AB", "BC", "CD"],
nodes: ["A", "B", "C", "D"]
}
A->B B->C C->B D->E C->B F->G
Output
{
edges: ["AB","BC", "CB", "DE", "FG"], // Duplicate edges are removed
nodes: ["A", "B", "C", "D", "E", "F"] // Only the first 6 nodes
}
A->B C-D
Output
{
message: "Hey, there was an error parsing line 2 of your graph notation!"
}
Write code for this task within the TASK 3.4 comment fence in
actions.ts
npm run dev on the src/ folder. Commit and
push your work to your personal forked repository. You may now move
on to Task 4.
src/components/dashboard.tsx file. Use the
following GIF for your reference for this task:
bg-teal-100 and should be a flex container.
Inside, create two primary sections: one for the instructions
and one for the "Graph Editor" and "Adjacency Matrix".
bg-teal-500 and text color of
text-white. Use bold and uppercase text with
tracking for better readability. text-teal-700 and
font-bold classes to highlight important text.
TextArea component for the graph notation
input (e.g., A->B). It should have an
id = "graph-notation" and a
placeholder = "e.g. A->B".
renderGraph function with the
formData.
Error component, and reset the nodes and edges
state.
Button component with the
primary theme for submitting the form.
Button component
with the secondary theme to reset the form.
Matrix component to display the adjacency
matrix. Pass in the graphNodes and
graphEdges as props to the
Matrix component.
useState hook to manage the
error, graphNodes, and
graphEdges states. Error component.
Button, Error, Matrix,
and TextArea.
Write code for this task within the TASK 4.2 comment fence in
dashboard.tsx
Congratulations on completing this assessment! You may now submit a pull request (ensuring that all local changes have been pushed) to the main repository from your forked repository to confirm your submission.
Make sure to include your name in the pull request message, along with any additional details in a README.md if you wish to explain / comment on any of the solutions for the previous tasks.