File size: 1,317 Bytes
b59aa07
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import { cn } from "#/utils/utils";

const VALID_WIDTHS = ["w-1/4", "w-1/2", "w-3/4"];

const getRandomWidth = () =>
  VALID_WIDTHS[Math.floor(Math.random() * VALID_WIDTHS.length)];

const getRandomNumber = (from = 3, to = 5) =>
  Math.floor(Math.random() * (to - from + 1)) + from;

function TaskCardSkeleton() {
  return (
    <li className="py-3 border-b border-[#717888] flex items-center pr-6">
      <div className="h-5 w-8 skeleton" />

      <div className="w-full pl-8">
        <div className="h-5 w-24 skeleton mb-2" />
        <div className={cn("h-5 skeleton", getRandomWidth())} />
      </div>

      <div className="h-5 w-16 skeleton" />
    </li>
  );
}

interface TaskGroupSkeletonProps {
  items?: number;
}

function TaskGroupSkeleton({ items = 3 }: TaskGroupSkeletonProps) {
  return (
    <div data-testid="task-group-skeleton">
      <div className="py-3 border-b border-[#717888]">
        <div className="h-6 w-40 skeleton" />
      </div>

      <ul>
        {Array.from({ length: items }).map((_, index) => (
          <TaskCardSkeleton key={index} />
        ))}
      </ul>
    </div>
  );
}

export function TaskSuggestionsSkeleton() {
  return Array.from({ length: getRandomNumber(2, 3) }).map((_, index) => (
    <TaskGroupSkeleton key={index} items={getRandomNumber(3, 5)} />
  ));
}