• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

EcrituresNumeriques / stylo / 13141758304

04 Feb 2025 05:55PM UTC coverage: 26.581% (+0.8%) from 25.809%
13141758304

push

github

web-flow
Merge pull request #1188 from ggrossetie/fix-1171-hooks-usegraphql

342 of 546 branches covered (62.64%)

Branch coverage included in aggregate %.

54 of 303 new or added lines in 10 files covered. (17.82%)

2 existing lines in 2 files now uncovered.

3567 of 14160 relevant lines covered (25.19%)

1.66 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/front/src/components/workspace/Workspaces.jsx
NEW
1
import { Button, useModal } from '@geist-ui/core'
×
NEW
2
import React, { useEffect, useState } from 'react'
×
NEW
3
import { Search } from 'react-feather'
×
4
import { useTranslation } from 'react-i18next'
×
5
import { shallowEqual, useSelector } from 'react-redux'
×
6
import Field from '../../components/Field.jsx'
×
7

8
import WorkspaceItem from '../../components/workspace/WorkspaceItem.jsx'
×
9

NEW
10
import { CurrentUserContext } from '../../contexts/CurrentUser'
×
11
import { useGraphQL } from '../../helpers/graphQL.js'
×
NEW
12
import { useWorkspaces } from '../../hooks/workspace.js'
×
NEW
13
import Loading from '../Loading.jsx'
×
NEW
14
import CreateWorkspaceModal from './CreateWorkspaceModal.jsx'
×
NEW
15
import { getUserStats } from './Workspaces.graphql'
×
16

NEW
17
import styles from './workspaces.module.scss'
×
18

19
export default function Workspaces() {
×
20
  const { t } = useTranslation()
×
21
  const activeUser = useSelector((state) => state.activeUser, shallowEqual)
×
22
  const [filter, setFilter] = useState('')
×
NEW
23
  const { workspaces, error, isLoading } = useWorkspaces()
×
NEW
24
  const workspaceCreateModal = useModal()
×
25

26
  const [personalWorkspace, setPersonalWorkspace] = useState({
×
27
    _id: activeUser._id,
×
28
    personal: true,
×
29
    members: [],
×
30
  })
×
31
  const runQuery = useGraphQL()
×
32

33
  useEffect(() => {
×
34
    ;(async () => {
×
35
      try {
×
36
        const getUserStatsResponse = await runQuery({ query: getUserStats })
×
37
        const userStats = getUserStatsResponse.user.stats
×
38
        setPersonalWorkspace({
×
39
          _id: activeUser._id,
×
40
          personal: true,
×
41
          name: t('workspace.myspace'),
×
42
          description: '',
×
43
          color: '#D9D9D9',
×
44
          createdAt: activeUser.createdAt,
×
45
          updatedAt: activeUser.updatedAt,
×
46
          members: [],
×
47
          articlesCount:
×
48
            userStats.myArticlesCount + userStats.contributedArticlesCount,
×
49
        })
×
50
      } catch (err) {
×
51
        alert(err)
×
52
      }
×
53
    })()
×
54
  }, [activeUser._id, t])
×
55

NEW
56
  if (error) {
×
NEW
57
    return <div>Unable to load the workspaces</div>
×
NEW
58
  }
×
NEW
59
  if (isLoading) {
×
NEW
60
    return <Loading />
×
NEW
61
  }
×
62

63
  return (
×
64
    <CurrentUserContext.Provider value={activeUser}>
×
65
      <section className={styles.section}>
×
66
        <h1>{t('workspace.title')}</h1>
×
67
        <div>
×
68
          <Field
×
69
            className={styles.searchField}
×
70
            type="text"
×
71
            icon={Search}
×
72
            value={filter}
×
73
            placeholder={t('search.placeholder')}
×
74
            onChange={(e) => setFilter(e.target.value)}
×
75
          />
×
76
        </div>
×
77
        <Button
×
78
          type="secondary"
×
79
          className={styles.button}
×
NEW
80
          onClick={() => workspaceCreateModal.setVisible(true)}
×
81
        >
82
          {t('workspace.createNew.button')}
×
83
        </Button>
×
84

NEW
85
        <CreateWorkspaceModal {...workspaceCreateModal} />
×
86

87
        <ul className={styles.workspacesList}>
×
88
          {[personalWorkspace, ...workspaces].map((workspace) => (
×
89
            <li key={`workspace-${workspace._id}`}>
×
90
              <WorkspaceItem workspace={workspace} />
×
91
            </li>
×
92
          ))}
×
93
        </ul>
×
94
      </section>
×
95
    </CurrentUserContext.Provider>
×
96
  )
97
}
×
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc