mirror of
https://github.com/Stremio/stremio-web.git
synced 2026-03-11 21:27:05 +00:00
ContinueWatching added to Board
This commit is contained in:
parent
fe71d5745c
commit
0fceb69e52
2 changed files with 48 additions and 2 deletions
|
|
@ -1,6 +1,7 @@
|
|||
const React = require('react');
|
||||
const { MainNavBar, MetaRow } = require('stremio/common');
|
||||
const useBoard = require('./useBoard');
|
||||
const useContinueWatching = require('./useContinueWatching');
|
||||
const styles = require('./styles');
|
||||
|
||||
const CONTINUE_WATCHING_MENU = [
|
||||
|
|
@ -15,12 +16,24 @@ const CONTINUE_WATCHING_MENU = [
|
|||
];
|
||||
|
||||
const Board = () => {
|
||||
const { catalog_resources } = useBoard();
|
||||
const board = useBoard();
|
||||
const continueWatching = useContinueWatching();
|
||||
return (
|
||||
<div className={styles['board-container']}>
|
||||
<MainNavBar className={styles['nav-bar']} />
|
||||
<div className={styles['board-content']}>
|
||||
{catalog_resources.map((catalog_resource, index) => {
|
||||
{
|
||||
continueWatching.lib_items.length > 0 ?
|
||||
<MetaRow
|
||||
className={styles['board-row']}
|
||||
title={'Continue Watching'}
|
||||
items={continueWatching.lib_items}
|
||||
limit={10}
|
||||
/>
|
||||
:
|
||||
null
|
||||
}
|
||||
{board.catalog_resources.map((catalog_resource, index) => {
|
||||
const title = `${catalog_resource.addon_name} - ${catalog_resource.request.path.id} ${catalog_resource.request.path.type_name}`;
|
||||
switch (catalog_resource.content.type) {
|
||||
case 'Ready':
|
||||
|
|
|
|||
33
src/routes/Board/useContinueWatching.js
Normal file
33
src/routes/Board/useContinueWatching.js
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
const React = require('react');
|
||||
const { useServices } = require('stremio/services');
|
||||
|
||||
const mapContinueWatchingState = (state) => {
|
||||
const lib_items = state.continue_watching.lib_items.map((lib_item) => {
|
||||
lib_item.href = `#/metadetails/${lib_item.type}/${lib_item._id}${lib_item.state.video_id !== null ? `/${lib_item.state.video_id}` : ''}`;
|
||||
return lib_item;
|
||||
});
|
||||
return { lib_items };
|
||||
};
|
||||
|
||||
const useContinueWatching = () => {
|
||||
const { core } = useServices();
|
||||
const [continueWatching, setContinueWatching] = React.useState(() => {
|
||||
const state = core.getState();
|
||||
const continueWatching = mapContinueWatchingState(state);
|
||||
return continueWatching;
|
||||
});
|
||||
React.useLayoutEffect(() => {
|
||||
const onNewState = () => {
|
||||
const state = core.getState();
|
||||
const continueWatching = mapContinueWatchingState(state);
|
||||
setContinueWatching(continueWatching);
|
||||
};
|
||||
core.on('NewModel', onNewState);
|
||||
return () => {
|
||||
core.off('NewModel', onNewState);
|
||||
};
|
||||
}, []);
|
||||
return continueWatching;
|
||||
};
|
||||
|
||||
module.exports = useContinueWatching;
|
||||
Loading…
Reference in a new issue