Toggle navigation
Toggle navigation
This project
Loading...
Sign in
2020-1-capstone-design1
/
Triz_Project1
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
1
Merge Requests
0
Wiki
Snippets
Network
Create a new issue
Builds
Commits
Issue Boards
Authored by
sdy
2020-06-16 20:22:55 +0900
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
1f7abe18f4822f12eb057b1246d9521041031f31
1f7abe18
1 parent
92a25497
update CategoryContainer
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
50 additions
and
9 deletions
front/src/Routes/Category/CategoryContainer.js
front/src/Routes/Category/CategoryContainer.js
View file @
1f7abe1
import
React
from
"react"
;
import
React
,
{
useEffect
,
useState
}
from
"react"
;
import
CategoryPresenter
from
"./CategoryPresenter"
;
import
{
withRouter
}
from
"react-router-dom"
;
import
{
useQuery
}
from
"@apollo/react-hooks"
;
import
{
GET_CATEGORIRES
}
from
"./CategoryQueries"
;
import
{
GET_CATEGORIRES
,
ADD_CATEGORY
,
SUBSCRIPTION_CATEGORY
,
}
from
"./CategoryQueries"
;
export
default
withRouter
(({
location
})
=>
{
const
{
data
}
=
useQuery
(
GET_CATEGORIRES
);
//const [addCategory] = useMutation(ADD_CATEGORY);
//const [editCategory] = useMutation(EDIT_CATEGORY);
//const [deleteCategory] = useMutation(DELETE_CATEGORY);
const
[
categoryArr
,
setCategoryArr
]
=
useState
([]);
const
{
subscribeToMore
,
data
:
categoryList
,
error
:
categoryQueryError
,
loading
:
categoryQueryLoading
,
}
=
useQuery
(
GET_CATEGORIRES
);
const
[
addCategory
]
=
useMutation
(
ADD_CATEGORY
);
let
categories
;
if
(
data
!==
undefined
)
{
const
{
getCategories
}
=
data
;
if
(
categoryList
!==
undefined
)
{
const
{
getCategories
}
=
categoryList
;
categories
=
getCategories
;
}
return
<
CategoryPresenter
location
=
{
location
}
categories
=
{
categories
}
/>
;
useEffect
(()
=>
{
if
(
categoryQueryError
)
{
console
.
error
(
categoryQueryError
);
}
if
(
categoryArr
)
{
setCategoryArr
(
categoryArr
.
getCategories
,
[
categoryQueryError
,
categoryArr
,
]);
}
},
[
categoryQueryLoading
]);
const
subscribeToNewCategory
=
()
=>
{
subscribeToMore
({
document
:
SUBSCRIPTION_CATEGORY
,
updateQuery
:
(
currentCategories
,
{
subscriptionData
})
=>
{
if
(
!
subscriptionData
.
data
)
return
currentCategories
;
const
newCategory
=
subscriptionData
.
data
.
subCategory
;
const
updateCategory
=
currentCategories
.
getCategories
.
concat
(
newCategory
);
setCategoryArr
(
updateCategory
);
return
{
getCategories
:
updateCategory
};
},
});
};
return
(
<
CategoryPresenter
location
=
{
location
}
categories
=
{
categories
}
subscribeToNewCategory
=
{
subscribeToNewCategory
}
/
>
);
});
...
...
Please
register
or
login
to post a comment