mirror of
https://github.com/Stremio/stremio-web.git
synced 2026-03-11 21:27:05 +00:00
useAddonDetails hook implemented
This commit is contained in:
parent
3e1ab699f5
commit
d78f2f6696
1 changed files with 48 additions and 0 deletions
48
src/routes/Addons/useAddonDetails.js
Normal file
48
src/routes/Addons/useAddonDetails.js
Normal file
|
|
@ -0,0 +1,48 @@
|
|||
const React = require('react');
|
||||
const { useModelState } = require('stremio/common');
|
||||
|
||||
const initAddonDetailsState = () => ({
|
||||
descriptor: null
|
||||
});
|
||||
|
||||
const mapAddonDetailsStateWithCtx = (addonDetails, ctx) => {
|
||||
const descriptor = addonDetails.descriptor !== null && addonDetails.descriptor.content.type === 'Ready' ?
|
||||
{
|
||||
...addonDetails.descriptor,
|
||||
content: {
|
||||
...addonDetails.descriptor.content,
|
||||
installed: ctx.content.addons.some((addon) => addon.transportUrl === addonDetails.descriptor.transport_url),
|
||||
}
|
||||
}
|
||||
:
|
||||
addonDetails.descriptor;
|
||||
return { descriptor };
|
||||
};
|
||||
|
||||
const useAddonDetails = (queryParams) => {
|
||||
const loadAddonDetailsAction = React.useMemo(() => {
|
||||
if (queryParams.has('addon')) {
|
||||
return {
|
||||
action: 'Load',
|
||||
args: {
|
||||
load: 'AddonDetails',
|
||||
args: {
|
||||
transport_url: queryParams.get('addon')
|
||||
}
|
||||
}
|
||||
};
|
||||
} else {
|
||||
return {
|
||||
action: 'Unload'
|
||||
};
|
||||
}
|
||||
}, [queryParams]);
|
||||
return useModelState({
|
||||
model: 'addon_details',
|
||||
action: loadAddonDetailsAction,
|
||||
mapWithCtx: mapAddonDetailsStateWithCtx,
|
||||
init: initAddonDetailsState,
|
||||
});
|
||||
};
|
||||
|
||||
module.exports = useAddonDetails;
|
||||
Loading…
Reference in a new issue