Skip to content

Commit

Permalink
work
Browse files Browse the repository at this point in the history
  • Loading branch information
yornaath committed Jan 11, 2024
1 parent 888faf0 commit 93a91e5
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 46 deletions.
19 changes: 19 additions & 0 deletions lib/cms/featured-markets.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import groq from "groq";
import { sanity } from "./sanity";

export type CmsFeaturedMarkets = {
marketIds: number[];
};

const fields = groq`{
"marketIds": markets[].marketId,
}`;

export const getCmsFeaturedMarkets = async () => {
// Short circuit to use default if NOTION_API_KEY doesn't exist.
const data = await sanity.fetch<CmsFeaturedMarkets[]>(
groq`*[_type == "featuredMarkets"]${fields}`,
);

return data?.[0];
};
39 changes: 0 additions & 39 deletions lib/cms/get-featured-marketids.ts

This file was deleted.

2 changes: 0 additions & 2 deletions lib/cms/news.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,5 @@ export const getCmsNews = async (): Promise<CmsNews[]> => {
groq`*[_type == "news"] | order(_createdAt desc) ${fields}`,
);

console.log(data);

return data;
};
15 changes: 11 additions & 4 deletions lib/gql/featured-markets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,23 @@ import {
} from "components/markets/market-card/index";
import { ZTG } from "lib/constants";
import { MarketOutcome, MarketOutcomes } from "lib/types/markets";
import { getFeaturedMarketIds } from "lib/cms/get-featured-marketids";
import { getCmsFeaturedMarkets } from "lib/cms/featured-markets";
import { isPresent } from "lib/types";
import { getCurrentPrediction } from "lib/util/assets";

const getFeaturedMarkets = async (
client: GraphQLClient,
sdk: Sdk<FullContext>,
): Promise<IndexedMarketCardData[]> => {
const ids = await getFeaturedMarketIds();
const cmsFeaturedMarkets = await getCmsFeaturedMarkets();

const { markets } = await sdk.indexer.markets({
where: {
marketId_in: ids,
marketId_in: cmsFeaturedMarkets.marketIds ?? [],
},
});

const featuredMarkets: IndexedMarketCardData[] = markets.map((market) => {
let featuredMarkets: IndexedMarketCardData[] = markets.map((market) => {
const marketCategories: MarketOutcomes =
market.categories?.map((category, index) => {
const asset = market.assets[index];
Expand Down Expand Up @@ -59,6 +59,13 @@ const getFeaturedMarkets = async (
return cardMarket;
});

featuredMarkets.sort((a, b) => {
return (
cmsFeaturedMarkets.marketIds?.findIndex((m) => m === a.marketId) -
cmsFeaturedMarkets.marketIds?.findIndex((m) => m === b.marketId)
);
});

return featuredMarkets;
};

Expand Down
2 changes: 1 addition & 1 deletion pages/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ const IndexPage: NextPage<{
{featuredMarkets.length > 0 && (
<div className="mb-12">
<MarketScroll
title="Promoted Markets"
title="Featured Markets"
cta="Go to Markets"
markets={featuredMarkets}
link="markets"
Expand Down

0 comments on commit 93a91e5

Please sign in to comment.