11import { selectInactiveOrganization , selectIsDemo , selectIsManaged , selectUser , setComments } from "@/src/reduxStore/states/general"
22import { selectAllProjects , setAllProjects } from "@/src/reduxStore/states/project" ;
3- import { GET_OVERVIEW_STATS , GET_PROJECT_LIST } from "@/src/services/gql/queries/projects" ;
43import { Project , ProjectStatistics } from "@/src/types/components/projects/projects-list" ;
54import { CurrentPage } from "@/src/types/shared/general" ;
65import { percentRoundString } from "@/submodules/javascript-functions/general" ;
7- import { useLazyQuery , useMutation } from "@apollo/client" ;
86import { useCallback , useEffect , useState } from "react" ;
97import { useDispatch , useSelector } from "react-redux" ;
108import YoutubeIntroduction from "./YoutubeIntroduction" ;
119import ButtonsContainer from "./ButtonsContainer" ;
1210import ProjectCard from "./ProjectCard" ;
13- import { GET_CAN_CREATE_LOCAL_ORG } from "@/src/services/gql/queries/organizations" ;
14- import { ADD_USER_TO_ORGANIZATION , CREATE_ORGANIZATION } from "@/src/services/gql/mutations/organizations" ;
1511import style from "@/src/styles/components/projects/projects-list.module.css" ;
1612import AdminDeleteProjectModal from "./AdminDeleteProjectModal" ;
1713import { setAllAttributes , setAllEmbeddings , setLabelingTasksAll } from "@/src/reduxStore/states/pages/settings" ;
1814import { setOverviewFilters } from "@/src/reduxStore/states/tmp" ;
1915import { setDataSlices , setFullSearchStore , setSearchGroupsStore } from "@/src/reduxStore/states/pages/data-browser" ;
2016import { SearchGroup } from "@/submodules/javascript-functions/enums/enums" ;
2117import { useWebsocket } from "@/src/services/base/web-sockets/useWebsocket" ;
18+ import { getAllProjects } from "@/src/services/base/project" ;
19+ import { addUserToOrganization , createOrganization , getCanCreateLocalOrg , getOverviewStats } from "@/src/services/base/organization" ;
2220
2321export default function ProjectsList ( ) {
2422 const dispatch = useDispatch ( ) ;
@@ -33,12 +31,6 @@ export default function ProjectsList() {
3331 const [ canCreateOrg , setCanCreateOrg ] = useState ( false ) ;
3432 const [ dataLoaded , setDataLoaded ] = useState ( false ) ;
3533
36- const [ refetchProjects ] = useLazyQuery ( GET_PROJECT_LIST , { fetchPolicy : "no-cache" } ) ;
37- const [ refetchStats ] = useLazyQuery ( GET_OVERVIEW_STATS , { fetchPolicy : "cache-and-network" } ) ;
38- const [ refetchCanCreateOrg ] = useLazyQuery ( GET_CAN_CREATE_LOCAL_ORG , { fetchPolicy : "no-cache" } ) ;
39- const [ createOrgMut ] = useMutation ( CREATE_ORGANIZATION ) ;
40- const [ addUserToOrgMut ] = useMutation ( ADD_USER_TO_ORGANIZATION ) ;
41-
4234 useEffect ( ( ) => {
4335 dispatch ( setLabelingTasksAll ( null ) ) ;
4436 dispatch ( setOverviewFilters ( null ) ) ;
@@ -61,16 +53,16 @@ export default function ProjectsList() {
6153 } , [ organizationInactive , user ] ) ;
6254
6355 function refetchProjectsAndPostProcess ( ) {
64- refetchProjects ( ) . then ( ( res ) => {
56+ getAllProjects ( ( res ) => {
6557 const projects = res . data [ "allProjects" ] . edges . map ( ( edge : any ) => edge . node ) ;
6658 dispatch ( setAllProjects ( projects ) ) ;
6759 setDataLoaded ( true ) ;
6860 } ) ;
6961 }
7062
7163 function refetchStatsAndPostProcess ( ) {
72- refetchStats ( ) . then ( ( res ) => {
73- const stats = JSON . parse ( res . data [ "overviewStats" ] ) ;
64+ getOverviewStats ( ( res ) => {
65+ const stats = res . data [ "overviewStats" ] ;
7466 const statsDict = { } ;
7567 if ( stats == null ) return ;
7668 stats . forEach ( ( stat : ProjectStatistics ) => {
@@ -88,17 +80,17 @@ export default function ProjectsList() {
8880 setDataLoaded ( true ) ;
8981 return ;
9082 }
91- refetchCanCreateOrg ( ) . then ( ( res ) => {
83+ getCanCreateLocalOrg ( res => {
9284 const canCreate = res . data [ "canCreateLocalOrg" ]
9385 setCanCreateOrg ( canCreate ) ;
9486 if ( ! canCreate ) return ;
9587 const localhostOrg = "localhost" ;
96- createOrgMut ( { variables : { name : localhostOrg } } ) . then ( ( res ) => {
97- addUserToOrgMut ( { variables : { userMail : user . mail , organizationName : localhostOrg } } ) . then ( ( res ) => {
88+ createOrganization ( localhostOrg , ( ) => {
89+ addUserToOrganization ( user . mail , localhostOrg , ( ) => {
9890 location . reload ( ) ;
9991 setDataLoaded ( true ) ;
10092 } ) ;
101- } ) ;
93+ } )
10294 } ) ;
10395 }
10496
0 commit comments