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