Frontend School

Watchlist Reorderer

Machine Coding
medium

Watchlist Reorderer

Medium
Drag and Drop
React
Frontend
UI

Overview

In the fast-paced world of trading, efficient management of watchlists is paramount for investors. Traders often need to quickly reorder their watchlist items based on real-time market movements, personal preference, or strategic priorities. This problem challenges you to build a component that allows users to intuitively reorder their stock watchlist using a drag-and-drop interface.

What you need to do / Task

Your primary task is to implement a React component that displays a list of stock symbols and enables users to reorder these symbols using drag-and-drop interactions.

  1. Render the Watchlist: Display an initial list of mock stock symbols.
  2. Enable Dragging: Make each stock symbol item draggable.
  3. Handle Dropping: Implement the logic to correctly reorder the list when an item is dragged and dropped into a new position.
  4. Update UI: Ensure the UI reflects the new order immediately after a successful drop.

UI/UX expectations

  • List Presentation: Display stock symbols as a clear, vertical list. Each symbol should be distinct.
  • Draggable Items: Each list item should visually indicate that it is draggable (e.g., cursor changes to grab or grabbing on hover/drag).
  • Drag Feedback: When an item is actively being dragged, it should provide visual feedback (e.g., a semi-transparent appearance of the dragged item, or a visual "lift" effect).
  • Insertion Indicator: While dragging an item over the list, provide a clear visual cue (e.g., a horizontal line or a background highlight) to indicate where the dragged item will be inserted if dropped at that position.
  • Smooth Reordering: The list should visually reorder smoothly and instantly once an item is dropped.

Acceptance criteria

  • The initial list of predefined stock symbols is rendered in the correct order.
  • Users can click and drag any stock symbol from its current position.
  • While dragging, a visual indicator (e.g., a "ghost" element or styled original) for the dragged item is present.
  • Dragging an item over other items provides a visual cue for the potential drop position.
  • Dropping an item successfully reorders the list, and the updated order is reflected in the UI.
  • Dragging an item to the very beginning or end of the list correctly places it there.
  • No external drag-and-drop libraries (e.g., react-beautiful-dnd, dnd-kit) are used; the solution should leverage native browser APIs or basic mouse/touch events.

Constraints

Constraints & assumptions

  • Data Structure: The watchlist data will be a simple array of objects, each with an id and symbol (e.g., [{ id: '1', symbol: 'NSE:RELIANCE' }]).
  • State Management: Use React's local state (useState) for managing the list order. No global state management is required.
  • Environment: Modern web browser, focus on desktop interactions.
  • No Backend: Assume no backend integration; changes are purely client-side.
  • Performance: The list size will be small (e.g., 5-10 items), so extreme performance optimizations are not the primary focus, but a performant solution is expected.

Out of scope

  • Adding or deleting watchlist items.
  • Persisting watchlist order across sessions (e.g., using localStorage or a backend API).
  • Complex animations beyond basic drag feedback.
  • Full accessibility support (e.g., keyboard-only reordering) – focus on mouse interactions.

What interviewers evaluate

  • Core Drag & Drop Logic: Correct and robust implementation of the drag-and-drop mechanism using native browser capabilities.
  • React State Management: Effective use of React state to manage and update the list order efficiently.
  • UI/UX Implementation: Adherence to the specified visual and interactive requirements, ensuring a user-friendly experience.
  • Code Quality: Clean, readable, modular code with appropriate component structure and separation of concerns.

Loading editor...