From 2f6b7f0ba6bf69e788919490708448fee62922f3 Mon Sep 17 00:00:00 2001 From: infinite-persistence Date: Fri, 15 Apr 2022 20:50:15 +0800 Subject: [PATCH] Update app to use v2 homepage api --- ui/redux/actions/settings.js | 20 +++++++++++++++++--- ui/redux/selectors/settings.js | 2 +- web/component/meme.jsx | 10 +++++++--- 3 files changed, 25 insertions(+), 7 deletions(-) diff --git a/ui/redux/actions/settings.js b/ui/redux/actions/settings.js index 235b822ad..24e6625d0 100644 --- a/ui/redux/actions/settings.js +++ b/ui/redux/actions/settings.js @@ -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) { diff --git a/ui/redux/selectors/settings.js b/ui/redux/selectors/settings.js index d81089d53..2494dda8e 100644 --- a/ui/redux/selectors/settings.js +++ b/ui/redux/selectors/settings.js @@ -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) => { diff --git a/web/component/meme.jsx b/web/component/meme.jsx index 77fc8d2ba..7d491887c 100644 --- a/web/component/meme.jsx +++ b/web/component/meme.jsx @@ -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 (

-

);