| 40 | }); |
| 41 | |
| 42 | export const useBoot = (): UseBoot => { |
| 43 | const router = useRouter(); |
| 44 | const client = useQueryClient(); |
| 45 | const { isAndroidApp } = useAuthContext(); |
| 46 | const getBootData = () => client.getQueryData<Boot>(BOOT_QUERY_KEY); |
| 47 | |
| 48 | const addSquad = (squad: Squad) => { |
| 49 | const bootData = getBootData(); |
| 50 | const currentSquads = bootData?.squads || []; |
| 51 | const squadExists = currentSquads.some((item) => item.id === squad.id); |
| 52 | |
| 53 | if (squadExists) { |
| 54 | return; |
| 55 | } |
| 56 | |
| 57 | const squads = sortSquads([...currentSquads, squad]); |
| 58 | client.setQueryData<Boot>(BOOT_QUERY_KEY, { ...bootData, squads }); |
| 59 | }; |
| 60 | |
| 61 | const deleteSquad = (squadId: string) => { |
| 62 | const bootData = getBootData(); |
| 63 | const squads = bootData.squads?.filter((squad) => squad.id !== squadId); |
| 64 | client.setQueryData<Boot>(BOOT_QUERY_KEY, { ...bootData, squads }); |
| 65 | }; |
| 66 | |
| 67 | const updateSquad = (squad: Squad) => { |
| 68 | const bootData = getBootData(); |
| 69 | const squads = bootData.squads?.map((bootSquad) => |
| 70 | squad.id !== bootSquad.id ? bootSquad : squad, |
| 71 | ); |
| 72 | client.setQueryData<Boot>(BOOT_QUERY_KEY, { |
| 73 | ...bootData, |
| 74 | squads: sortSquads(squads ?? []), |
| 75 | }); |
| 76 | }; |
| 77 | |
| 78 | const getMarketingCta = ( |
| 79 | variant: MarketingCtaVariant, |
| 80 | ): MarketingCta | null => { |
| 81 | const bootData = getBootData(); |
| 82 | |
| 83 | if ( |
| 84 | !bootData?.marketingCta || |
| 85 | bootData?.marketingCta?.variant !== variant |
| 86 | ) { |
| 87 | return null; |
| 88 | } |
| 89 | |
| 90 | if ( |
| 91 | isMarketingCtaTarget(bootData?.marketingCta?.targets, isAndroidApp) === |
| 92 | false |
| 93 | ) { |
| 94 | return null; |
| 95 | } |
| 96 | |
| 97 | return bootData?.marketingCta; |
| 98 | }; |
| 99 | |