Filter out expiring ads
This commit is contained in:
parent
c29bf4040a
commit
f4af1687bf
|
@ -20,6 +20,8 @@ interface Ad {
|
||||||
card: Card,
|
card: Card,
|
||||||
/** Impression URL to fetch when displaying the ad. */
|
/** Impression URL to fetch when displaying the ad. */
|
||||||
impression?: string,
|
impression?: string,
|
||||||
|
/** Time when the ad expires and should no longer be displayed. */
|
||||||
|
expires?: Date,
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Gets the current provider based on config. */
|
/** Gets the current provider based on config. */
|
||||||
|
|
|
@ -43,6 +43,7 @@ const RumbleAdProvider: AdProvider = {
|
||||||
image: item.asset,
|
image: item.asset,
|
||||||
url: item.click,
|
url: item.click,
|
||||||
}),
|
}),
|
||||||
|
expires: new Date(item.expires * 1000),
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,7 +17,19 @@ export default function useAds() {
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
return useQuery<Ad[]>(['ads'], getAds, {
|
const result = useQuery<Ad[]>(['ads'], getAds, {
|
||||||
placeholderData: [],
|
placeholderData: [],
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Filter out expired ads.
|
||||||
|
const data = result.data?.filter(ad => {
|
||||||
|
const now = new Date();
|
||||||
|
const isExpired = ad.expires && (now.getTime() > ad.expires.getTime());
|
||||||
|
return !isExpired;
|
||||||
|
});
|
||||||
|
|
||||||
|
return {
|
||||||
|
...result,
|
||||||
|
data,
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue