Update app to use v2 homepage api

This commit is contained in:
infinite-persistence 2022-04-15 20:50:15 +08:00 committed by Thomas Zarebczan
parent 45bb9ad0fa
commit 2f6b7f0ba6
3 changed files with 25 additions and 7 deletions

View file

@ -310,17 +310,31 @@ export function doFetchLanguage(language) {
export function doFetchHomepages() {
return (dispatch) => {
// -- Use this env flag to use local homepage data. Otherwise, it will grab from `/$/api/content/v1/get`.
// -- Use this env flag to use local homepage data. Otherwise, it will grab from `/$/api/content/v*/get`.
// @if USE_LOCAL_HOMEPAGE_DATA='true'
const homepages = require('homepages');
if (homepages) {
window.homepages = homepages;
const v2 = {};
const homepageKeys = Object.keys(homepages);
homepageKeys.forEach((hp) => {
v2[hp] = {
categories: homepages[hp],
};
});
const meme = require('memes');
if (meme && v2['en']) {
v2['en'].meme = meme;
}
window.homepages = v2;
dispatch({ type: ACTIONS.FETCH_HOMEPAGES_DONE });
return;
}
// @endif
fetch('https://odysee.com/$/api/content/v1/get')
fetch('https://odysee.com/$/api/content/v2/get')
.then((response) => response.json())
.then((json) => {
if (json?.status === 'success' && json?.data) {

View file

@ -66,7 +66,7 @@ export const selectLanguage = (state) => {
export const selectHomepageData = (state) => {
const homepageCode = selectHomepageCode(state);
const homepages = window.homepages;
return homepages ? homepages[homepageCode] || homepages['en'] || {} : {};
return homepages ? homepages[homepageCode].categories || homepages['en'].categories || {} : {};
};
export const selectInRegionByCode = (state, code) => {

View file

@ -1,12 +1,16 @@
import React from 'react';
import Button from 'component/button';
const memes = require('memes');
export default function Meme() {
const meme = window?.homepages?.en?.meme;
if (!meme) {
return null;
}
return (
<h1 className="home__meme">
<Button button="link" navigate={memes.url}>
{memes.text}
<Button button="link" navigate={meme.url}>
{meme.text}
</Button>
</h1>
);