mirror of
https://github.com/Stremio/stremio-web.git
synced 2026-03-11 21:27:05 +00:00
AddonDetailsModal adapted to changes in core
This commit is contained in:
parent
92b15a5cbb
commit
d32fe5123a
2 changed files with 23 additions and 45 deletions
|
|
@ -12,7 +12,7 @@ const AddonDetailsModal = ({ transportUrl, onCloseRequest }) => {
|
|||
const { core } = useServices();
|
||||
const addonDetails = useAddonDetails(transportUrl);
|
||||
const modalButtons = React.useMemo(() => {
|
||||
if (addonDetails.remote_addon === null || addonDetails.remote_addon.content.type !== 'Ready') {
|
||||
if (addonDetails.remoteAddon === null || addonDetails.remoteAddon.content.type !== 'Ready') {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
|
@ -30,7 +30,7 @@ const AddonDetailsModal = ({ transportUrl, onCloseRequest }) => {
|
|||
action: 'Ctx',
|
||||
args: {
|
||||
action: 'InstallAddon',
|
||||
args: addonDetails.remote_addon.content.content
|
||||
args: addonDetails.remoteAddon.content.content
|
||||
}
|
||||
});
|
||||
if (typeof onCloseRequest === 'function') {
|
||||
|
|
@ -46,7 +46,7 @@ const AddonDetailsModal = ({ transportUrl, onCloseRequest }) => {
|
|||
action: 'Ctx',
|
||||
args: {
|
||||
action: 'UninstallAddon',
|
||||
args: addonDetails.remote_addon.content.content.transportUrl
|
||||
args: addonDetails.remoteAddon.content.content.transportUrl
|
||||
}
|
||||
});
|
||||
if (typeof onCloseRequest === 'function') {
|
||||
|
|
@ -65,7 +65,7 @@ const AddonDetailsModal = ({ transportUrl, onCloseRequest }) => {
|
|||
onClick: cancelOnClick
|
||||
}
|
||||
},
|
||||
addonDetails.remote_addon.content.content.installed ?
|
||||
addonDetails.localAddon !== null ?
|
||||
{
|
||||
className: styles['uninstall-button'],
|
||||
label: 'Uninstall',
|
||||
|
|
@ -92,27 +92,27 @@ const AddonDetailsModal = ({ transportUrl, onCloseRequest }) => {
|
|||
Loading addon manifest
|
||||
</div>
|
||||
:
|
||||
addonDetails.remote_addon === null || addonDetails.remote_addon.content.type === 'Loading' ?
|
||||
addonDetails.remoteAddon === null || addonDetails.remoteAddon.content.type === 'Loading' ?
|
||||
<div className={styles['addon-details-message-container']}>
|
||||
Loading addon manifest from {addonDetails.selected.transport_url}
|
||||
Loading addon manifest from {addonDetails.selected.transportUrl}
|
||||
</div>
|
||||
:
|
||||
addonDetails.remote_addon.content.type === 'Err' ?
|
||||
addonDetails.remoteAddon.content.type === 'Err' ?
|
||||
<div className={styles['addon-details-message-container']}>
|
||||
Failed to get addon manifest from {addonDetails.selected.transport_url}.
|
||||
{addonDetails.remote_addon.content.content}
|
||||
Failed to get addon manifest from {addonDetails.selected.transportUrl}
|
||||
<div>{addonDetails.remoteAddon.content.content.message}</div>
|
||||
</div>
|
||||
:
|
||||
<AddonDetails
|
||||
className={styles['addon-details-container']}
|
||||
id={addonDetails.remote_addon.content.content.manifest.id}
|
||||
name={addonDetails.remote_addon.content.content.manifest.name}
|
||||
version={addonDetails.remote_addon.content.content.manifest.version}
|
||||
logo={addonDetails.remote_addon.content.content.manifest.logo}
|
||||
description={addonDetails.remote_addon.content.content.manifest.description}
|
||||
types={addonDetails.remote_addon.content.content.manifest.types}
|
||||
transportUrl={addonDetails.remote_addon.content.content.transportUrl}
|
||||
official={addonDetails.remote_addon.content.content.flags.official}
|
||||
id={addonDetails.remoteAddon.content.content.manifest.id}
|
||||
name={addonDetails.remoteAddon.content.content.manifest.name}
|
||||
version={addonDetails.remoteAddon.content.content.manifest.version}
|
||||
logo={addonDetails.remoteAddon.content.content.manifest.logo}
|
||||
description={addonDetails.remoteAddon.content.content.manifest.description}
|
||||
types={addonDetails.remoteAddon.content.content.manifest.types}
|
||||
transportUrl={addonDetails.remoteAddon.content.content.transportUrl}
|
||||
official={addonDetails.remoteAddon.content.content.flags.official}
|
||||
/>
|
||||
}
|
||||
</ModalDialog>
|
||||
|
|
|
|||
|
|
@ -3,38 +3,21 @@
|
|||
const React = require('react');
|
||||
const useModelState = require('stremio/common/useModelState');
|
||||
|
||||
const initAddonDetailsState = () => ({
|
||||
const init = () => ({
|
||||
selected: null,
|
||||
remote_addon: null
|
||||
localAddon: null,
|
||||
remoteAddon: null
|
||||
});
|
||||
|
||||
const mapAddonDetailsStateWithCtx = (addonDetails, ctx) => {
|
||||
const selected = addonDetails.selected;
|
||||
const remote_addon = addonDetails.remote_addon !== null && addonDetails.remote_addon.content.type === 'Ready' ?
|
||||
{
|
||||
transport_url: addonDetails.remote_addon.transport_url,
|
||||
content: {
|
||||
type: addonDetails.remote_addon.content.type,
|
||||
content: {
|
||||
...addonDetails.remote_addon.content.content,
|
||||
installed: ctx.profile.addons.some(({ transportUrl }) => transportUrl === addonDetails.remote_addon.transport_url),
|
||||
}
|
||||
}
|
||||
}
|
||||
:
|
||||
addonDetails.remote_addon;
|
||||
return { selected, remote_addon };
|
||||
};
|
||||
|
||||
const useAddonDetails = (transportUrl) => {
|
||||
const loadAddonDetailsAction = React.useMemo(() => {
|
||||
const action = React.useMemo(() => {
|
||||
if (typeof transportUrl === 'string') {
|
||||
return {
|
||||
action: 'Load',
|
||||
args: {
|
||||
model: 'AddonDetails',
|
||||
args: {
|
||||
transport_url: transportUrl
|
||||
transportUrl
|
||||
}
|
||||
}
|
||||
};
|
||||
|
|
@ -44,12 +27,7 @@ const useAddonDetails = (transportUrl) => {
|
|||
};
|
||||
}
|
||||
}, [transportUrl]);
|
||||
return useModelState({
|
||||
model: 'addon_details',
|
||||
action: loadAddonDetailsAction,
|
||||
mapWithCtx: mapAddonDetailsStateWithCtx,
|
||||
init: initAddonDetailsState,
|
||||
});
|
||||
return useModelState({ model: 'addon_details', action, init });
|
||||
};
|
||||
|
||||
module.exports = useAddonDetails;
|
||||
|
|
|
|||
Loading…
Reference in a new issue