this is not working for high to low using sort

useEffect(() => {
  //for duration
  if (
    filtering?.durationInMinutes &&
    selectedFilterItems.find((item) => item.type === 'durationInMinutes')
      ?.code !==
      `${filtering?.durationInMinutes?.from || '-'}${
        filtering?.durationInMinutes?.to
      }`
  ) {
    setSelectedFilterItems((prev) => {
      prev = prev.filter((items) => items.type !== 'durationInMinutes');
      return [
        ...prev,
        {
          displayItem: (
            <span className="flex items-center gap-2">
              {!!filtering?.durationInMinutes?.from && (
                <span className="flex items-center gap-2">
                  from{' '}
                  <strong>
                    {convertDuration(filtering?.durationInMinutes?.from)}
                  </strong>
                </span>
              )}{' '}
              {!!filtering?.durationInMinutes?.to && (
                <span className="flex items-center gap-2">
                  {!!filtering?.durationInMinutes?.from ? 'to ' : 'upto '}
                  <strong>
                    {convertDuration(filtering?.durationInMinutes?.to)}
                  </strong>
                </span>
              )}
            </span>
          ),
          type: 'durationInMinutes',
          code: `${filtering?.durationInMinutes?.from || '-'}${
            filtering?.durationInMinutes?.to
          }`,
        },
      ];
    });
  } else if (!filtering?.durationInMinutes) {
    setSelectedFilterItems(
      (prev) =>
        (prev = prev.filter((items) => items.type !== 'durationInMinutes'))
    );
  }

  if (
    (sortType.sort !== 'DEFAULT' &&
      selectedFilterItems.find((item) => item.type === 'sort')?.code !==
        sortType.sort) ||
    selectedFilterItems.find((item) => item.type === 'sort')?.code ===
      sortType.sort
  ) {
    setSelectedFilterItems((prev) => {
      prev = prev.filter((items) => items.type !== 'sort');
      return [
        ...prev,
        {
          displayItem: (
            <span className="flex items-center gap-2">
              Sort by <strong>{sortType.name}</strong>
            </span>
          ),
          type: 'sort',
          code: sortType.sort,
        },
      ];
    });
  } else if (sortType.sort === 'DEFAULT') {
    setSelectedFilterItems(
      (prev) => (prev = prev.filter((items) => items.type !== 'sort'))
    );
  }

i expected this to works both on low to high and high and low