|
|
@ -1,5 +1,5 @@ |
|
|
|
/* eslint-disable no-debugger */ |
|
|
|
/* eslint-disable no-debugger */ |
|
|
|
import React, { Fragment, useEffect, useState } from 'react' |
|
|
|
import React, { Fragment, useCallback, useEffect, useState } from 'react' |
|
|
|
import ModuleHeading from './moduleHeading' |
|
|
|
import ModuleHeading from './moduleHeading' |
|
|
|
import { ModalDialog } from '@remix-ui/modal-dialog' |
|
|
|
import { ModalDialog } from '@remix-ui/modal-dialog' |
|
|
|
import { FormStateProps, PluginManagerComponent } from '../../types' |
|
|
|
import { FormStateProps, PluginManagerComponent } from '../../types' |
|
|
@ -8,7 +8,7 @@ import PermisssionsSettings from './permissions/permissionsSettings' |
|
|
|
import { Profile } from '@remixproject/plugin-utils' |
|
|
|
import { Profile } from '@remixproject/plugin-utils' |
|
|
|
import ActivePluginCard from './ActivePluginCard' |
|
|
|
import ActivePluginCard from './ActivePluginCard' |
|
|
|
import InactivePluginCard from './InactivePluginCard' |
|
|
|
import InactivePluginCard from './InactivePluginCard' |
|
|
|
import { GetNewlyActivatedPlugins, PersistNewInactivesState } from '../../pluginManagerStateMachine' |
|
|
|
import { PersistNewInactivesState, RemoveActivatedPlugin } from '../../pluginManagerStateMachine' |
|
|
|
|
|
|
|
|
|
|
|
const initialState: FormStateProps = { |
|
|
|
const initialState: FormStateProps = { |
|
|
|
pname: 'test', |
|
|
|
pname: 'test', |
|
|
@ -33,7 +33,10 @@ function RootView ({ pluginComponent }: RootViewProps) { |
|
|
|
const [filterPlugins, setFilterPlugin] = useState('') |
|
|
|
const [filterPlugins, setFilterPlugin] = useState('') |
|
|
|
const [activeP, setActiveP] = useState<Profile[]>([]) |
|
|
|
const [activeP, setActiveP] = useState<Profile[]>([]) |
|
|
|
const [inactiveP, setInactiveP] = useState<Profile[]>([]) |
|
|
|
const [inactiveP, setInactiveP] = useState<Profile[]>([]) |
|
|
|
const [triggerRefresh, setTriggerRefresh] = useState(false) |
|
|
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
|
|
|
|
|
|
const [_, setTriggerRefresh] = useState(false) |
|
|
|
|
|
|
|
const [validInactiveProfiles] = useState<Profile[]>(JSON.parse(window.localStorage.getItem('updatedInactives'))) |
|
|
|
|
|
|
|
const [validActiveProfiles] = useState<Profile[]>(JSON.parse(window.localStorage.getItem('newActivePlugins'))) |
|
|
|
function pluginChangeHandler<P extends keyof FormStateProps> (formProps: P, value: FormStateProps[P]) { |
|
|
|
function pluginChangeHandler<P extends keyof FormStateProps> (formProps: P, value: FormStateProps[P]) { |
|
|
|
setPlugin({ ...plugin, [formProps]: value }) |
|
|
|
setPlugin({ ...plugin, [formProps]: value }) |
|
|
|
} |
|
|
|
} |
|
|
@ -52,52 +55,90 @@ function RootView ({ pluginComponent }: RootViewProps) { |
|
|
|
setTriggerRefresh(true) |
|
|
|
setTriggerRefresh(true) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
useEffect(() => { |
|
|
|
const GetNewlyActivatedPlugins = useCallback((pluginComponent: PluginManagerComponent) => { |
|
|
|
pluginComponent.getAndFilterPlugins(filterPlugins) |
|
|
|
// const profiles: Profile[] = JSON.parse(window.localStorage.getItem('newActivePlugins'))
|
|
|
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
|
|
let isValid: boolean = false |
|
|
|
}, [filterPlugins]) |
|
|
|
// eslint-disable-next-line no-debugger
|
|
|
|
|
|
|
|
debugger |
|
|
|
useEffect(() => { |
|
|
|
pluginComponent.activeProfiles.forEach(profileName => { |
|
|
|
if (pluginComponent.activePlugins && pluginComponent.activePlugins.length) { |
|
|
|
isValid = validActiveProfiles.some(profile => profile.name === profileName) |
|
|
|
setActiveP(pluginComponent.activePlugins) |
|
|
|
}) |
|
|
|
} |
|
|
|
if (isValid) { |
|
|
|
// if (pluginComponent.inactivePlugins && pluginComponent.inactivePlugins.length) {
|
|
|
|
return validActiveProfiles |
|
|
|
// setInactiveP(pluginComponent.inactivePlugins)
|
|
|
|
} else { |
|
|
|
// }
|
|
|
|
const profiles = validActiveProfiles // make a copy of state and don't mutate state directly
|
|
|
|
const validInactiveProfiles: Profile[] = JSON.parse(window.localStorage.getItem('updatedInactives')) |
|
|
|
profiles.forEach(profile => { |
|
|
|
if (validInactiveProfiles && validInactiveProfiles.length) { |
|
|
|
if (!pluginComponent.activeProfiles.includes(profile.name)) { |
|
|
|
if (inactiveP.length > validInactiveProfiles.length) { |
|
|
|
RemoveActivatedPlugin(profile.name) |
|
|
|
setInactiveP(validInactiveProfiles) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
if (pluginComponent.inactivePlugins && pluginComponent.inactivePlugins.length) { |
|
|
|
}) |
|
|
|
setInactiveP(pluginComponent.inactivePlugins) |
|
|
|
const newProfiles = JSON.parse(window.localStorage.getItem('newActivePlugins')) |
|
|
|
|
|
|
|
return newProfiles |
|
|
|
} |
|
|
|
} |
|
|
|
}, [pluginComponent.activePlugins, pluginComponent.inactivePlugins, activeP, inactiveP, pluginComponent.activeProfiles, pluginComponent]) |
|
|
|
}, [validActiveProfiles]) |
|
|
|
|
|
|
|
|
|
|
|
useEffect(() => { |
|
|
|
useEffect(() => { |
|
|
|
if (activeP.length === 0) { |
|
|
|
if (activeP.length === 0) { |
|
|
|
const activeProfiles = GetNewlyActivatedPlugins() |
|
|
|
const activeProfiles = GetNewlyActivatedPlugins(pluginComponent) |
|
|
|
if (activeProfiles !== null && activeProfiles.length) { |
|
|
|
if (activeProfiles !== null && activeProfiles.length) { |
|
|
|
setActiveP(activeProfiles) |
|
|
|
setActiveP(activeProfiles) |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
setActiveP(pluginComponent.activePlugins) |
|
|
|
setActiveP(pluginComponent.activePlugins) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
}, [activeP, pluginComponent.activePlugins, syncInactiveProfiles]) |
|
|
|
}, [GetNewlyActivatedPlugins, activeP, pluginComponent, pluginComponent.activePlugins, syncInactiveProfiles]) |
|
|
|
|
|
|
|
|
|
|
|
useEffect(() => { |
|
|
|
useEffect(() => { |
|
|
|
syncInactiveProfiles() |
|
|
|
pluginComponent.getAndFilterPlugins(filterPlugins) |
|
|
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
|
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
|
|
}, [inactiveP, triggerRefresh]) |
|
|
|
}, [filterPlugins]) |
|
|
|
|
|
|
|
|
|
|
|
useEffect(() => { |
|
|
|
useEffect(() => { |
|
|
|
const validInactiveProfiles: Profile[] = JSON.parse(window.localStorage.getItem('updatedInactives')) |
|
|
|
if (pluginComponent.activePlugins && pluginComponent.activePlugins.length) { |
|
|
|
if (validInactiveProfiles && validInactiveProfiles.length && |
|
|
|
setActiveP(pluginComponent.activePlugins) |
|
|
|
inactiveP.length > validInactiveProfiles.length) { |
|
|
|
} |
|
|
|
setInactiveP(validInactiveProfiles) |
|
|
|
|
|
|
|
|
|
|
|
if (pluginComponent.inactivePlugins && pluginComponent.inactivePlugins.length) { |
|
|
|
|
|
|
|
setInactiveP(pluginComponent.inactivePlugins) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
let inactivesCopy = [] |
|
|
|
|
|
|
|
if (validInactiveProfiles && validInactiveProfiles.length) { |
|
|
|
|
|
|
|
if (validActiveProfiles && validActiveProfiles.length) { |
|
|
|
|
|
|
|
validActiveProfiles.forEach(active => { |
|
|
|
|
|
|
|
inactivesCopy = validInactiveProfiles.filter(inactive => inactive.name !== active.name) |
|
|
|
|
|
|
|
.filter(inactive => inactive.displayName !== active.displayName) |
|
|
|
|
|
|
|
}) |
|
|
|
} |
|
|
|
} |
|
|
|
}, [inactiveP, triggerRefresh]) |
|
|
|
console.log('inactivescopy length', validInactiveProfiles.length) |
|
|
|
|
|
|
|
if (inactivesCopy.length) setInactiveP(validInactiveProfiles) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}, [pluginComponent.activePlugins, pluginComponent.inactivePlugins, pluginComponent.activeProfiles, pluginComponent, validInactiveProfiles, inactiveP.length, validActiveProfiles]) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// useEffect(() => {
|
|
|
|
|
|
|
|
// if (validInactiveProfiles && validInactiveProfiles.length &&
|
|
|
|
|
|
|
|
// inactiveP.length > validInactiveProfiles.length) {
|
|
|
|
|
|
|
|
// setInactiveP(validInactiveProfiles)
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// let inactivesCopy = []
|
|
|
|
|
|
|
|
// if (validInactiveProfiles && validInactiveProfiles.length) {
|
|
|
|
|
|
|
|
// if (inactiveP.length > validInactiveProfiles.length) {
|
|
|
|
|
|
|
|
// if (validActiveProfiles && validActiveProfiles.length) {
|
|
|
|
|
|
|
|
// validActiveProfiles.forEach(active => {
|
|
|
|
|
|
|
|
// inactivesCopy = validInactiveProfiles.filter(inactive => inactive !== active)
|
|
|
|
|
|
|
|
// .filter(inactive => inactive.displayName !== active.displayName)
|
|
|
|
|
|
|
|
// })
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
// console.log('inactivescopy length', validInactiveProfiles.length)
|
|
|
|
|
|
|
|
// if (inactivesCopy.length) setInactiveP(validInactiveProfiles)
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
// }, [inactiveP, triggerRefresh, validActiveProfiles, validInactiveProfiles])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// useEffect(() => {
|
|
|
|
|
|
|
|
// syncInactiveProfiles()
|
|
|
|
|
|
|
|
// // eslint-disable-next-line react-hooks/exhaustive-deps
|
|
|
|
|
|
|
|
// }, [inactiveP, triggerRefresh])
|
|
|
|
|
|
|
|
|
|
|
|
return ( |
|
|
|
return ( |
|
|
|
<Fragment> |
|
|
|
<Fragment> |
|
|
|