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

DaniSomoza / galactic-commander / 11940541664

20 Nov 2024 07:39PM UTC coverage: 65.587% (-31.2%) from 96.824%
11940541664

push

github

web-flow
Frontend initial implementation and player perks feature (#10)

* added vite react-ts template

* Add register and login pages

* Add initial frontend implementation

* Add first iteration of research queue

* first version of the research page

* added assets

* Added pirate research assets

* Added translation support

* updated planet images

* added first version of the bonus

181 of 418 branches covered (43.3%)

Branch coverage included in aggregate %.

532 of 983 new or added lines in 110 files covered. (54.12%)

8 existing lines in 4 files now uncovered.

1176 of 1651 relevant lines covered (71.23%)

4.75 hits per line

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

0.0
/packages/frontend/src/hooks/useTaskTracking.ts
1
import { useCallback, useEffect, useState } from 'react'
2

3
import {
4
  TaskType,
5
  TaskTypesTypes,
6
  ERROR_TASK_STATUS,
7
  PENDING_TASK_STATUS,
8
  PROCESSED_TASK_STATUS,
9
  CANCELLED_TASK_STATUS
10
} from 'game-api-microservice/src/types/Task'
11

12
import usePolling from './usePolling'
13
import { getTask as getTaskEndpoint } from '../endpoints/game/taskEndpoints'
14

15
function useTaskTracking<T extends TaskTypesTypes>(taskId?: string, customIntervalTime = 1_000) {
×
NEW
16
  const [task, setTask] = useState<TaskType<T>>()
×
17

NEW
18
  const getTask = useCallback(async (taskId: string): Promise<TaskType<T>> => {
×
NEW
19
    const response = await getTaskEndpoint(taskId)
×
NEW
20
    const { task } = response.data
×
21

NEW
22
    setTask(task)
×
23

NEW
24
    return task
×
25
  }, [])
26

NEW
27
  const trackTask = useCallback(async () => {
×
NEW
28
    if (taskId) {
×
NEW
29
      getTask(taskId)
×
30
    }
31
  }, [getTask, taskId])
32

NEW
33
  const stopTaskPolling = usePolling(trackTask, customIntervalTime)
×
34

NEW
35
  const isTaskPending = task?.status === PENDING_TASK_STATUS
×
NEW
36
  const isTaskProcessed = task?.status === PROCESSED_TASK_STATUS
×
NEW
37
  const isTaskError = task?.status === ERROR_TASK_STATUS
×
NEW
38
  const isTaskCancelled = task?.status === CANCELLED_TASK_STATUS
×
39

NEW
40
  useEffect(() => {
×
41
    async function checkStopTaskPolling() {
NEW
42
      if (taskId) {
×
NEW
43
        const task = await getTask(taskId)
×
NEW
44
        const isTaskPending = task?.status === PENDING_TASK_STATUS
×
NEW
45
        if (!isTaskPending) {
×
NEW
46
          stopTaskPolling()
×
47
        }
48
      }
49
    }
50

NEW
51
    if (!isTaskPending) {
×
NEW
52
      checkStopTaskPolling()
×
53
    }
54
  }, [taskId, getTask, stopTaskPolling, isTaskPending])
55

NEW
56
  return {
×
57
    task,
58
    getTask,
59
    stopTaskPolling,
60
    isTaskPending,
61
    isTaskProcessed,
62
    isTaskError,
63
    isTaskCancelled
64
  }
65
}
66

67
export default useTaskTracking
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