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

feat: add reordering custom hook and component #18

Merged
merged 2 commits into from
Oct 10, 2024

Conversation

6ri4n
Copy link
Contributor

@6ri4n 6ri4n commented Oct 6, 2024

Resolves issue #8

This custom hook and component allows a user to hold and drag one item over another item to swap item positions.

A request will be sent to the backend once the user no longer reorders anything for 3 seconds.

Payload:

{
    data: [...] // updated array
}

Usage Example:

import React, { useState } from "react";
import Reorder from "./Reorder/Reorder";
import useReorder from "./Reorder/useReorder";

function Demo() {
  const [items, setItems] = useState([
    "item-1",
    "item-2",
    "item-3",
    "item-4",
    "item-5",
  ]);

  const { response, error, reorderObj } = useReorder(
    items,
    setItems,
    "education"
  );

  return (
    <>
      {items.map((element, index) => (
        <Reorder key={index} index={index} reorderObj={reorderObj}>
          <div key={index}>{element}</div>
        </Reorder>
      ))}
    </>
  );
}

export default Demo;

You must import the useReorder hook and Reorder component.

The useReorder hook requires 3 arguments, items must be an array, setItems must be the array setter, and sectionType must be a string that identifies the resume section (e.g. "education", "experience", and "skills"). The useReorder hook returns an object containing response, error, and reorderObj.

The Reorder component requires 3 props: key and index should be assigned an index from the items array, and reorderObj which takes in reorderObj from the useReorder hook. The Reorder component should wrap the section item component.

@6ri4n
Copy link
Contributor Author

6ri4n commented Oct 9, 2024

@yashika51

@yashika51
Copy link
Collaborator

@yashika51

can you include fix for failing test as well?

@6ri4n
Copy link
Contributor Author

6ri4n commented Oct 10, 2024

@yashika51

can you include fix for failing test as well?

the test cases are unrelated to my PR

@yashika51 yashika51 merged commit 8185269 into MLH-Fellowship:main Oct 10, 2024
1 of 2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants