Skip to content

Commit

Permalink
refactor: Use triggers from appEntry and don't make the request twice
Browse files Browse the repository at this point in the history
  • Loading branch information
Crash-- committed Aug 21, 2023
1 parent 0915a10 commit 3470f3b
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
8 changes: 5 additions & 3 deletions src/components/KonnectorTile.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ function getTriggersBySlug(triggers, slug) {
}
function getErrorsForTriggers(triggers, jobs) {
const triggersInError = triggers.filter(
t => t.current_state.status === 'errored'
t => t.current_state?.status === 'errored'
)
if (triggersInError?.length > 0) {
const job = Object.values(jobs).find(
Expand All @@ -75,8 +75,10 @@ const getAccountsFromTrigger = (accounts, triggers) => {
return matchingAccounts
}
export const KonnectorTile = props => {
const test = useSelector(state => state.cozy.documents['io.cozy.triggers'])
const triggers = getTriggersBySlug(test, props.konnector.slug)
const allTriggers = useSelector(
state => state.cozy.documents['io.cozy.triggers']
)
const triggers = getTriggersBySlug(allTriggers, props.konnector.slug)
const jobs = useSelector(state => state.cozy.documents['io.cozy.jobs'])
const accounts = useSelector(
state => state.cozy.documents['io.cozy.accounts']
Expand Down
12 changes: 6 additions & 6 deletions src/containers/App.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ const FETCHING_CONTEXT = 'FETCHING_CONTEXT'
window.flag = window.flag || flag
window.minilog = minilog

const App = ({ accounts, konnectors }) => {
const App = ({ accounts, konnectors, triggers }) => {
const client = useClient()
const { isMobile } = useBreakpoints()
const [status, setStatus] = useState(IDLE)
Expand All @@ -55,21 +55,21 @@ const App = ({ accounts, konnectors }) => {

useEffect(() => {
setIsFetching(
[accounts, konnectors].some(collection =>
[accounts, konnectors, triggers].some(collection =>
['pending', 'loading'].includes(collection.fetchStatus)
)
)
setHasError(
[accounts, konnectors].find(
[accounts, konnectors, triggers].find(
collection => collection.fetchStatus === 'failed'
)
)
}, [accounts, konnectors])
useEffect(() => {
}, [accounts, konnectors, triggers])
/* useEffect(() => {
client.query(Q('io.cozy.triggers'))
client.query(Q('io.cozy.jobs'))
client.query(Q('io.cozy.accounts'))
}, [])
}, []) */
useEffect(() => {
// if we already have the query, let's refresh in "background"
// aka without loading state
Expand Down

0 comments on commit 3470f3b

Please sign in to comment.