From 6883f2708330f60525fbcc16355346b8af974ec5 Mon Sep 17 00:00:00 2001 From: Jason Lee <123986245+sleeper-jasonl@users.noreply.github.com> Date: Thu, 7 Dec 2023 10:12:26 -0800 Subject: [PATCH] Adding avatars & per sport league lists (#26) --- bin/build_mini.js | 0 bin/preload_packages.js | 0 declarations/avatar/index.d.ts | 23 +++++ declarations/index.d.ts | 5 +- declarations/jersey/index.d.ts | 2 +- declarations/navigation/index.d.ts | 2 +- declarations/sleeper_actions.d.ts | 2 +- declarations/sleeper_context.d.ts | 6 +- declarations/sleeper_message.d.ts | 3 +- declarations/switch/index.d.ts | 4 +- .../types/components/app_icon_switch.d.ts | 24 ++++++ declarations/types/components/jersey.d.ts | 3 + .../components/ui_2/app_icon_switch.d.ts | 18 ---- declarations/types/index.d.ts | 83 ++----------------- declarations/types/minis/index.d.ts | 71 ++++++++++++++++ declarations/types/shared/graphql.d.ts | 57 ++++++------- declarations/types/utils/toast_helper.d.ts | 2 +- package.json | 4 +- src/components/index.tsx | 35 +++++++- 19 files changed, 209 insertions(+), 135 deletions(-) mode change 100644 => 100755 bin/build_mini.js mode change 100644 => 100755 bin/preload_packages.js create mode 100644 declarations/avatar/index.d.ts create mode 100644 declarations/types/components/app_icon_switch.d.ts create mode 100644 declarations/types/components/jersey.d.ts delete mode 100644 declarations/types/components/ui_2/app_icon_switch.d.ts create mode 100644 declarations/types/minis/index.d.ts diff --git a/bin/build_mini.js b/bin/build_mini.js old mode 100644 new mode 100755 diff --git a/bin/preload_packages.js b/bin/preload_packages.js old mode 100644 new mode 100755 diff --git a/declarations/avatar/index.d.ts b/declarations/avatar/index.d.ts new file mode 100644 index 0000000..b8899bb --- /dev/null +++ b/declarations/avatar/index.d.ts @@ -0,0 +1,23 @@ +import React from "react"; +import { League, Player, User } from "@sleeperhq/mini-core/declarations/types/shared/graphql.d"; +export interface AvatarProps { + user: User; + width?: number; +} +export declare const Avatar: React.MemoExoticComponent<(props: AvatarProps) => JSX.Element>; +export interface AvatarPlayerProps { + player: Player; + width?: number; +} +export declare const AvatarPlayer: React.MemoExoticComponent<(props: AvatarPlayerProps) => JSX.Element>; +export interface AvatarTeamProps { + team: string; + sport: string; + width?: number; +} +export declare const AvatarTeam: React.MemoExoticComponent<(props: AvatarTeamProps) => JSX.Element>; +export interface AvatarLeagueProps { + league: League; + width?: number; +} +export declare const AvatarLeague: React.MemoExoticComponent<(props: AvatarLeagueProps) => JSX.Element>; diff --git a/declarations/index.d.ts b/declarations/index.d.ts index e8d2bcf..07664c0 100644 --- a/declarations/index.d.ts +++ b/declarations/index.d.ts @@ -1,4 +1,3 @@ -export * from './types'; -export * from './sleeper_message'; -declare const _default: any; +/// +declare const _default: (props: any) => JSX.Element; export default _default; diff --git a/declarations/jersey/index.d.ts b/declarations/jersey/index.d.ts index 4a2f4b3..1ad6e61 100644 --- a/declarations/jersey/index.d.ts +++ b/declarations/jersey/index.d.ts @@ -1,5 +1,5 @@ import { ColorValue, ViewStyle } from 'react-native'; -import SleeperJersey from 'components/ui/jersey'; +import SleeperJersey from '@sleeperhq/mini-core/declarations/types/components/jersey.d'; export interface JerseyProps { style: ViewStyle; sport: 'nfl' | 'nba' | 'cbb' | 'cfb' | 'mlb'; diff --git a/declarations/navigation/index.d.ts b/declarations/navigation/index.d.ts index 88284c4..0eca57e 100644 --- a/declarations/navigation/index.d.ts +++ b/declarations/navigation/index.d.ts @@ -1,4 +1,4 @@ -import type { LeagueId, PlayerId, RosterId, SportType, TransactionId } from '..'; +import type { LeagueId, PlayerId, RosterId, SportType, TransactionId } from '@sleeperhq/mini-core/declarations/types'; export type NavigationParams = { LeaguesIndexScreen: undefined; LeaguesDetailScreen: LeaguesDetailScreenParams; diff --git a/declarations/sleeper_actions.d.ts b/declarations/sleeper_actions.d.ts index 18c2db6..bf49522 100644 --- a/declarations/sleeper_actions.d.ts +++ b/declarations/sleeper_actions.d.ts @@ -1,4 +1,4 @@ -import { NavigationParams, NavigationScreen, ToastConfig, Notification } from './types'; +import { NavigationParams, NavigationScreen, ToastConfig, Notification } from '@sleeperhq/mini-core/declarations/types'; export type SleeperActions = { navigate?: (screen: T, params?: NavigationParams[T]) => void; requestLocation?: () => void; diff --git a/declarations/sleeper_context.d.ts b/declarations/sleeper_context.d.ts index d271d5a..c714d90 100644 --- a/declarations/sleeper_context.d.ts +++ b/declarations/sleeper_context.d.ts @@ -1,11 +1,13 @@ -import { User, League, LeaguesMap, RostersInLeagueMap, UserMap, MatchupsInLeagueMap, UsersInLeagueMap, PlayoffsInLeagueMap, TransactionsInLeagueMap, TransactionsMap, SportInfoMap, DraftsInLeagueMap, DraftPickTradesInLeagueMap, DraftPicksInDraftMap, PlayersInSportMap, Topic, Location } from './types'; -import type { SleeperActions } from './sleeper_actions'; +import { User, League, LeaguesMap, RostersInLeagueMap, UserMap, MatchupsInLeagueMap, UsersInLeagueMap, PlayoffsInLeagueMap, TransactionsInLeagueMap, TransactionsMap, SportInfoMap, DraftsInLeagueMap, DraftPickTradesInLeagueMap, DraftPicksInDraftMap, PlayersInSportMap, Topic, Location, SportType } from '@sleeperhq/mini-core/declarations/types'; +import type { SleeperActions } from '@sleeperhq/mini-core/declarations/sleeper_actions'; declare class SleeperContext { static apiLevel: string; user: User; league: League; leaguesMap: LeaguesMap; + leaguesMapBySport: Record; userLeagueList: string[]; + userLeagueListBySport: Record; rostersInLeagueMap: RostersInLeagueMap; userMap: UserMap; matchupsInLeagueMap: MatchupsInLeagueMap; diff --git a/declarations/sleeper_message.d.ts b/declarations/sleeper_message.d.ts index 5899347..e00867c 100644 --- a/declarations/sleeper_message.d.ts +++ b/declarations/sleeper_message.d.ts @@ -1,4 +1,4 @@ -import type { Entitlement, HeaderOptions } from './types'; +import type { Entitlement, HeaderOptions, Metadata } from '@sleeperhq/mini-core/declarations/types'; type SocketMessage = { _ip?: string; _name?: string; @@ -7,5 +7,6 @@ type SocketMessage = { _description?: string; _entitlements?: Entitlement[]; _headerOptions?: HeaderOptions; + _metadata?: Metadata; }; export default SocketMessage; diff --git a/declarations/switch/index.d.ts b/declarations/switch/index.d.ts index c94bf5d..b193757 100644 --- a/declarations/switch/index.d.ts +++ b/declarations/switch/index.d.ts @@ -1,3 +1,3 @@ -import { AppIconSwitch } from '../types/components/ui_2/app_icon_switch'; -export type { SwitchOption, Props as SwitchProps } from '../types/components/ui_2/app_icon_switch'; +import { AppIconSwitch } from '@sleeperhq/mini-core/declarations/types/components/app_icon_switch.d'; +export type { SwitchOption, Props as SwitchProps } from '@sleeperhq/mini-core/declarations/types/components/app_icon_switch.d'; export default AppIconSwitch; diff --git a/declarations/types/components/app_icon_switch.d.ts b/declarations/types/components/app_icon_switch.d.ts new file mode 100644 index 0000000..58e7d0c --- /dev/null +++ b/declarations/types/components/app_icon_switch.d.ts @@ -0,0 +1,24 @@ +import React from 'react'; +import { StyleProp, ViewStyle } from 'react-native'; +export type SwitchOption = { + colorToggleActive: string; + colorIconActive: string; + colorIconInactive?: string; + iconStyle?: any; + icon: any; + iconInactive?: any; + text?: string; + hideIconInactive?: boolean; +}; +export type Props = { + options: [SwitchOption, SwitchOption]; + value?: number; + onChange?: (value: number) => void; + height?: number; + width?: number; + containerStyle?: StyleProp; + toggleStyle?: StyleProp; + aspectRatio?: number; + confirmationFunction?: (nextSelection: 'on' | 'off', continueAction: () => void) => void; +}; +export declare const AppIconSwitch: React.MemoExoticComponent<({ height, options, value, width, onChange, containerStyle, toggleStyle, aspectRatio, confirmationFunction }: Props) => JSX.Element>; diff --git a/declarations/types/components/jersey.d.ts b/declarations/types/components/jersey.d.ts new file mode 100644 index 0000000..aeba3fe --- /dev/null +++ b/declarations/types/components/jersey.d.ts @@ -0,0 +1,3 @@ +export default Jersey; +declare const Jersey: React.NamedExoticComponent; +import React from 'react'; diff --git a/declarations/types/components/ui_2/app_icon_switch.d.ts b/declarations/types/components/ui_2/app_icon_switch.d.ts deleted file mode 100644 index 86bdcfa..0000000 --- a/declarations/types/components/ui_2/app_icon_switch.d.ts +++ /dev/null @@ -1,18 +0,0 @@ -import { StyleProp, ViewStyle } from 'react-native'; -export type SwitchOption = { - colorToggleActive: string; - colorIconActive: string; - colorIconInactive: string; - iconStyle?: any; - icon: any; -}; -export type Props = { - options: [SwitchOption, SwitchOption]; - value?: number; - onChange?: (value: number) => void; - height?: number; - width?: number; - containerStyle?: StyleProp; - toggleStyle?: StyleProp; -}; -export declare const AppIconSwitch: any; diff --git a/declarations/types/index.d.ts b/declarations/types/index.d.ts index 84f7453..42e162d 100644 --- a/declarations/types/index.d.ts +++ b/declarations/types/index.d.ts @@ -1,83 +1,17 @@ -import { League, Roster, User, MatchupLeg, LeagueTransaction, Draft, DraftPick, RosterDraftPick, Player, Topic } from './shared/graphql.d'; -import type { ToastConfig as ToastConfigOriginal } from './utils/toast_helper'; -export * from './shared/graphql.d'; -export * from '../navigation/index.d'; -export type LeagueId = string; -export type RosterId = string; -export type UserId = string; -export type MatchupWeek = number; -export type MatchId = string; -export type TransactionId = string; -export type SportType = string; -export type DraftId = string; -export type PlayerId = string; -export type TopicId = 'podcasts' | 'videos'; -export type { Topic }; -export type BracketFrom = { - w?: RosterId; - l?: RosterId; -}; -export type Bracket = { - round: number; - matchId: MatchId; - t1: RosterId; - t2: RosterId; - w: RosterId; - l: RosterId; - t1_from: BracketFrom; - t2_from: BracketFrom; -}; -export type BracketSet = { - bracket: Bracket[]; - loserBracket: Bracket[]; -}; -export type SportInfo = { - season_type: string; - season: string; - week?: number; - display_week?: number; - leg?: number; - league_season?: string; - league_create_season?: string; - previous_season?: string; - season_start_date?: string; - season_end_date?: string; -}; -export type LeaguesMap = Record; -export type RostersMap = Record; -export type RostersInLeagueMap = Record; -export type UserMap = Record; -export type MathchupWeekMap = Record; -export type MatchupsInLeagueMap = Record; -export type UsersInLeagueMap = Record; -export type PlayoffsInLeagueMap = Record; -export type TransactionsInLeagueMap = Record; -export type TransactionsMap = Record; -export type SportInfoMap = Record; -export type DraftsInLeagueMap = Record; -export type DraftPickTradesInLeagueMap = Record; -export type DraftPicksInDraftMap = Record; -export type PlayersMap = Record; -export type PlayersInSportMap = Record; +import type { ToastConfig as ToastConfigOriginal } from '@sleeperhq/mini-core/declarations/types/utils/toast_helper.d'; +import { SportType } from '@sleeperhq/mini-core/declarations/types/minis/index.d'; +export * from '@sleeperhq/mini-core/declarations/navigation/index.d'; +export * from '@sleeperhq/mini-core/declarations/types/shared/graphql.d'; +export * from '@sleeperhq/mini-core/declarations/types/minis/index.d'; export type Entitlement = 'user:email' | 'user:phone' | 'wallet:date_of_birth' | 'wallet:first_name' | 'wallet:last_name' | 'wallet:country_code' | 'wallet:city' | 'location:longitude' | 'location:latitude' | 'location:state' | 'location:country' | 'location:postalCode' | 'action:push_notification'; export type Entitlements = Partial>; export declare const EntitlementDisplayText: Record; -export type Notification = { - title?: string | undefined; - body?: string | undefined; - timestamp?: number; -}; -export declare const EventHandlerResult: { - readonly CONSUMED: "CONSUMED"; - readonly PROPAGATE: "PROPAGATE"; -}; -export type EventHandlerResultType = typeof EventHandlerResult[keyof typeof EventHandlerResult]; -export type Events = { - onBackButtonPressed?: () => EventHandlerResultType; -}; export type HeaderOptions = { useLeagueSelector?: boolean; }; +export type Metadata = { + sports?: SportType[]; +}; export type Mini = { name: string; description: string; @@ -86,6 +20,7 @@ export type Mini = { email?: string; entitlements?: Entitlement[]; headerOptions?: HeaderOptions; + metadata?: Metadata; }; export type Location = { state: string; diff --git a/declarations/types/minis/index.d.ts b/declarations/types/minis/index.d.ts new file mode 100644 index 0000000..1716112 --- /dev/null +++ b/declarations/types/minis/index.d.ts @@ -0,0 +1,71 @@ +import type { League, Roster, User, MatchupLeg, LeagueTransaction, Draft, DraftPick, RosterDraftPick, Player, Topic } from '@sleeperhq/mini-core/declarations/types/shared/graphql.d'; +export type LeagueId = string; +export type RosterId = string; +export type UserId = string; +export type MatchupWeek = number; +export type MatchId = string; +export type TransactionId = string; +export type SportType = string; +export type DraftId = string; +export type PlayerId = string; +export type TopicId = 'podcasts' | 'videos'; +export type { Topic }; +export type BracketFrom = { + w?: RosterId; + l?: RosterId; +}; +export type Bracket = { + round: number; + matchId: MatchId; + t1: RosterId; + t2: RosterId; + w: RosterId; + l: RosterId; + t1_from: BracketFrom; + t2_from: BracketFrom; +}; +export type BracketSet = { + bracket: Bracket[]; + loserBracket: Bracket[]; +}; +export type SportInfo = { + season_type: string; + season: string; + week?: number; + display_week?: number; + leg?: number; + league_season?: string; + league_create_season?: string; + previous_season?: string; + season_start_date?: string; + season_end_date?: string; +}; +export type LeaguesMap = Record; +export type RostersMap = Record; +export type RostersInLeagueMap = Record; +export type UserMap = Record; +export type MathchupWeekMap = Record; +export type MatchupsInLeagueMap = Record; +export type UsersInLeagueMap = Record; +export type PlayoffsInLeagueMap = Record; +export type TransactionsInLeagueMap = Record; +export type TransactionsMap = Record; +export type SportInfoMap = Record; +export type DraftsInLeagueMap = Record; +export type DraftPickTradesInLeagueMap = Record; +export type DraftPicksInDraftMap = Record; +export type PlayersMap = Record; +export type PlayersInSportMap = Record; +export type Notification = { + title?: string | undefined; + body?: string | undefined; + timestamp?: number; +}; +export declare const EventHandlerResult: { + readonly CONSUMED: "CONSUMED"; + readonly PROPAGATE: "PROPAGATE"; +}; +export type EventHandlerResultType = typeof EventHandlerResult[keyof typeof EventHandlerResult]; +export type Events = { + onBackButtonPressed?: () => EventHandlerResultType; +}; diff --git a/declarations/types/shared/graphql.d.ts b/declarations/types/shared/graphql.d.ts index f495f56..70110df 100644 --- a/declarations/types/shared/graphql.d.ts +++ b/declarations/types/shared/graphql.d.ts @@ -202,6 +202,35 @@ export type RosterDraftPick = { round?: Maybe; season?: Maybe; }; +export type Topic = { + __typename?: 'Topic'; + attachment?: Maybe; + author_avatar?: Maybe; + author_display_name?: Maybe; + author_id?: Maybe; + author_is_bot?: Maybe; + channel_id?: Maybe; + channel_tags?: Maybe; + client_id?: Maybe; + created?: Maybe; + hidden?: Maybe; + last_message_id?: Maybe; + last_pinned_message_id?: Maybe; + last_read_id?: Maybe; + num_messages?: Maybe; + num_viewers?: Maybe; + pinned?: Maybe; + player_tags?: Maybe; + pushed_by?: Maybe; + score?: Maybe; + shadowed?: Maybe; + shard_max?: Maybe; + shard_min?: Maybe; + title?: Maybe; + title_map?: Maybe; + topic_id?: Maybe; + upvotes?: Maybe; +}; export type User = { __typename?: 'User'; async_bundles?: Maybe; @@ -227,31 +256,3 @@ export type User = { username?: Maybe; verification?: Maybe; }; -export type Topic = { - __typename?: 'Topic'; - attachment?: Maybe; - author_avatar?: Maybe; - author_display_name?: Maybe; - author_id?: Maybe; - author_is_bot?: Maybe; - channel_id?: Maybe; - channel_tags?: Maybe; - client_id?: Maybe; - created?: Maybe; - hidden?: Maybe; - last_message_id?: Maybe; - last_pinned_message_id?: Maybe; - last_read_id?: Maybe; - num_messages?: Maybe; - num_viewers?: Maybe; - pinned?: Maybe; - player_tags?: Maybe; - pushed_by?: Maybe; - score?: Maybe; - shard_max?: Maybe; - shard_min?: Maybe; - title?: Maybe; - title_map?: Maybe; - topic_id?: Maybe; - upvotes?: Maybe; -}; diff --git a/declarations/types/utils/toast_helper.d.ts b/declarations/types/utils/toast_helper.d.ts index e941eeb..e5b6a9d 100644 --- a/declarations/types/utils/toast_helper.d.ts +++ b/declarations/types/utils/toast_helper.d.ts @@ -1,7 +1,7 @@ import { TextStyle, ViewStyle } from 'react-native'; export type ToastConfig = { text: string; - icon?: string; + icon?: 'success' | 'error' | 'trade' | 'voice'; time?: number; style?: ViewStyle; slideTop?: boolean; diff --git a/package.json b/package.json index 7f1bb43..7a3f0c7 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@sleeperhq/mini-core", - "version": "1.6.2", + "version": "1.7.3", "description": "Core library frameworks for developing Sleeper Mini Apps.", "main": "index.ts", "types": "index.d.ts", @@ -66,7 +66,7 @@ "@typescript-eslint/eslint-plugin": "^5.31.0", "@typescript-eslint/parser": "^5.31.0", "babel-jest": "^26.6.3", - "eslint": "7.14.0", + "eslint": "8.38.0", "jest": "^26.6.3", "lodash": "4.17.21", "metro-react-native-babel-preset": "^0.66.2", diff --git a/src/components/index.tsx b/src/components/index.tsx index a9153eb..842238d 100644 --- a/src/components/index.tsx +++ b/src/components/index.tsx @@ -4,6 +4,7 @@ import {Federated} from '@callstack/repack/client'; import type {ButtonProps} from '../../declarations/button'; import type {JerseyProps} from '../../declarations/jersey'; import type {SwitchProps} from '../../declarations/switch'; +import { AvatarProps, AvatarLeagueProps, AvatarPlayerProps, AvatarTeamProps } from '../../declarations/avatar'; const _SleeperModule = React.lazy(() => Federated.importModule('sleeper', 'index').catch(() => ({ @@ -16,6 +17,38 @@ const _SleeperModule = React.lazy(() => })), ); +const Avatar = (props: AvatarProps) => { + return ( + }> + <_SleeperModule component="Avatar" {...props} /> + + ); +}; + +const AvatarLeague = (props: AvatarLeagueProps) => { + return ( + }> + <_SleeperModule component="AvatarLeague" {...props} /> + + ); +}; + +const AvatarPlayer = (props: AvatarPlayerProps) => { + return ( + }> + <_SleeperModule component="AvatarPlayer" {...props} /> + + ); +}; + +const AvatarTeam = (props: AvatarTeamProps) => { + return ( + }> + <_SleeperModule component="AvatarTeam" {...props} /> + + ); +}; + const Button = (props: ButtonProps) => { return ( }> @@ -49,4 +82,4 @@ const Jersey = (props: JerseyProps) => { }; export type {ButtonProps, TextProps, JerseyProps, SwitchProps}; -export {Button, Text, Jersey, Switch}; +export {Button, Text, Jersey, Switch, Avatar, AvatarLeague, AvatarPlayer, AvatarTeam};