All files / app/features/search/utils constants.ts

45.83% Statements 11/24
36.36% Branches 4/11
50% Functions 2/4
45.83% Lines 11/24

Press n or j to go to the next uncovered block, b, p or k for the previous block.

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 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85    77x   77x                     77x     77x                 77x                                       77x 77x 77x       77x             77x 77x                                              
import { TFunction } from "i18n";
import { HostingStatus, SleepingArrangement, User } from "proto/api_pb";
import { firstName } from "utils/names";
 
const aboutText = (user: User.AsObject, t: TFunction) => {
  const missingAbout = user.aboutMe.length === 0;
  return missingAbout
    ? t("search:search_result.missing_about_description", {
        name: firstName(user?.name),
      })
    : user.aboutMe.length < 300
      ? user.aboutMe
      : user.aboutMe.substring(0, 300) + "...";
};
 
const truncateWithEllipsis = (str: string, maxLength = 40): string =>
  str.length > maxLength ? str.slice(0, maxLength) + "…" : str;
 
enum lastActiveOptions {
  LAST_ACTIVE_ANY = 0,
  LAST_ACTIVE_LAST_DAY = 1,
  LAST_ACTIVE_LAST_WEEK = 7,
  LAST_ACTIVE_LAST_2_WEEKS = 14,
  LAST_ACTIVE_LAST_MONTH = 31,
  LAST_ACTIVE_LAST_3_MONTHS = 93,
}
 
const selectedUserZoom = 10;
 
type Coordinates = [number, number, number, number];
 
type HostingStatusType = Exclude<
  HostingStatus,
  | HostingStatus.HOSTING_STATUS_UNKNOWN
  | HostingStatus.HOSTING_STATUS_UNSPECIFIED
>[];
 
type HostingStatusOptions =
  | HostingStatus.HOSTING_STATUS_CANT_HOST
  | HostingStatus.HOSTING_STATUS_MAYBE
  | HostingStatus.HOSTING_STATUS_CAN_HOST;
 
type SleepingArrangementOptions =
  | SleepingArrangement.SLEEPING_ARRANGEMENT_COMMON
  | SleepingArrangement.SLEEPING_ARRANGEMENT_PRIVATE
  | SleepingArrangement.SLEEPING_ARRANGEMENT_SHARED_ROOM;
 
const DEFAULT_AGE_MIN = 18;
const DEFAULT_AGE_MAX = 120;
const MAX_MAP_ZOOM_LEVEL_FOR_SEARCH = 7;
 
type MapSearchTypes = "location" | "keyword";
 
enum MapViews {
  MAP_AND_LIST = "MAP_AND_LIST",
  LIST_ONLY = "LIST_ONLY",
}
 
type MapViewOptions = MapViews.MAP_AND_LIST | MapViews.LIST_ONLY;
 
const MAX_ZOOM_LEVEL = 15;
const MIN_ZOOM_LEVEL = 0;
 
export {
  aboutText,
  DEFAULT_AGE_MAX,
  DEFAULT_AGE_MIN,
  lastActiveOptions,
  MapViews,
  MAX_MAP_ZOOM_LEVEL_FOR_SEARCH,
  MAX_ZOOM_LEVEL,
  MIN_ZOOM_LEVEL,
  selectedUserZoom,
  truncateWithEllipsis,
};
 
export type {
  Coordinates,
  HostingStatusOptions,
  HostingStatusType,
  MapSearchTypes,
  MapViewOptions,
  SleepingArrangementOptions,
};