Skip to content

Commit

Permalink
#1799 :: fix;
Browse files Browse the repository at this point in the history
  • Loading branch information
migbash committed Oct 24, 2023
1 parent 269cfbf commit fa8e5a6
Show file tree
Hide file tree
Showing 5 changed files with 137 additions and 12 deletions.
14 changes: 7 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
"coverage": "vitest run --coverage"
},
"dependencies": {
"@betarena/scores-lib": "^1.9.0",
"@betarena/scores-lib": "^1.9.1",
"@lukeed/uuid": "^2.0.1",
"@metamask/sdk": "^0.1.0",
"@moralisweb3/client-firebase-auth-utils": "^2.18.4",
Expand Down
3 changes: 0 additions & 3 deletions src/lib/components/page/fixture/Layout.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
import { onMount } from 'svelte';
import { createFixtureOddsPath, onceTargetLivescoreNowFixtureGet, targetLivescoreNowFixtureListen, targetLivescoreNowFixtureOddsListen } from '$lib/firebase/common.js';
import { subscribeCompetitionsAllListen } from '$lib/graphql/graphql.common.js';
import sessionStore from '$lib/store/session.js';
import userBetarenaSettings from '$lib/store/user-settings.js';
import { dlog } from '$lib/utils/debug';
Expand Down Expand Up @@ -280,8 +279,6 @@
await kickstartLivescore();
await kickstartLiveOdds();
subscribeCompetitionsAllListen();
resizeAction();
addEventListeners();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import { onMount } from 'svelte';
import { get } from '$lib/api/utils.js';
import { subscribeCompetitionsTargetListen } from '$lib/graphql/graphql.common.js';
import sessionStore from '$lib/store/session.js';
import { langPrefix } from '$lib/utils/platform-functions.js';
Expand Down Expand Up @@ -148,6 +149,11 @@
widgetNoData = false;
$sessionStore.showFixtureCompetition = true;
subscribeCompetitionsTargetListen
(
widgetDataMain?.competition?.id
);
return;
}
Expand Down
124 changes: 123 additions & 1 deletion src/lib/graphql/graphql.common.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// #region ➤ 📦 Package Imports

import sessionStore from '$lib/store/session.js';
import { B_C_COMP_M_Q_D_S } from "@betarena/scores-lib/dist/graphql/query.competitions.js";
import { B_C_COMP_M_Q_D_S, B_C_COMP_M_Q_D_ST } from "@betarena/scores-lib/dist/graphql/query.competitions.js";
import { SubscriptionClient } from "graphql-subscriptions-client";

import type { B_H_COMP_DATA } from "@betarena/scores-lib/types/_HASURA_.js";
Expand Down Expand Up @@ -141,4 +141,126 @@ export async function subscribeCompetitionsAllListen
);
}

/**
* @summary
* 🔹 HELPER | IMPORTANT
*
* @description
* 📌 Listens/Subsribes to changes in competitions data.
*
* @returns
* `void`
*/
export async function subscribeCompetitionsTargetListen
(
competitionId: number
): Promise < void >
{
// get ready
const GRAPHQL_ENDPOINT = import.meta.env?.VITE_HASURA_DB_WSS ?? '';

const query: string = B_C_COMP_M_Q_D_ST;

// ### NOTE:
// ### set up the client, which can be reused
const client = new SubscriptionClient
(
GRAPHQL_ENDPOINT,
{
reconnect: true,
// ### NOTE:
// ### per-authors-documentation:
// ### only connect when there is a query
lazy: true,
connectionParams:
{
// ### IMPORTANT
headers:
{
'x-hasura-admin-secret': import.meta.env?.VITE_HASURA_DB_TOKEN ?? ''
},
},
connectionCallback:
(
error
): void =>
{
error && console.error(error);
},
}
);

// ### NOTE:
// ### per-authors-documentation:
// ### make the actual request.
client.request
(
{
query
}
);

// ### NOTE:
// ### per-authors-documentation:
// ### the above doesn't do much though.

// ### NOTE:
// ### per-authors-documentation:
// ### call subscription.unsubscribe() later to clean up
const subscription = client
.request
(
{
query,
variables:
{
competitionId
}
}
)
// ### NOTE:
// ### so lets actually do something with the response
.subscribe
(
{
next
(
{
data
}: { data: B_H_COMP_HIGH_Q; }
): void
{
if (data)
{
console.log("We got something! 🟥", data);

const competitionMap = new Map < number, B_H_COMP_DATA >();

// ### NOTE:
// ### loop over competitions data.
for (const competition of data?.competitions_data ?? [])
{

// ### NOTE:
// ### generate map.
// ### TODO:
// ### can be added to 'sessionStore.competition_map' data prop.
competitionMap.set
(
competition?.id,
competition
);
}

sessionStore.updateCompetitionsLatestMap
(
competitionMap
);

}
},
}
);
}

// #endregion ➤ 🛠️ METHODS

0 comments on commit fa8e5a6

Please sign in to comment.