Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
T
thecybernanny-webapp
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
asranov0003
thecybernanny-webapp
Commits
51e31a1b
Commit
51e31a1b
authored
Aug 07, 2025
by
asranov0003
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
refactor: cache devices
parent
e1d03153
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
32 additions
and
40 deletions
+32
-40
App.tsx
src/App.tsx
+1
-12
deviceSlice.ts
src/stores/slices/deviceSlice.ts
+13
-28
device.types.ts
src/types/device.types.ts
+18
-0
No files found.
src/App.tsx
View file @
51e31a1b
import
React
,
{
useEffect
}
from
"react"
;
import
React
from
"react"
;
import
Router
from
"./routes/Router"
;
import
useTelegramExpand
from
"./hooks/useTelegramExpand"
;
import
{
TG_USER_ID
}
from
"./constants/constants"
;
import
{
useAppDispatch
}
from
"./stores/store"
;
import
{
fetchDevices
}
from
"./stores/slices/deviceSlice"
;
const
App
:
React
.
FC
=
()
=>
{
const
dispatch
=
useAppDispatch
();
useTelegramExpand
();
useEffect
(()
=>
{
if
(
localStorage
.
getItem
(
`token-
${
TG_USER_ID
}
`
))
{
dispatch
(
fetchDevices
());
}
},
[
dispatch
]);
return
<
Router
/>;
};
...
...
src/stores/slices/deviceSlice.ts
View file @
51e31a1b
import
{
createAsyncThunk
,
createSlice
}
from
"@reduxjs/toolkit"
;
import
{
sendRpcRequest
}
from
"../../services/apiClient"
;
import
type
{
IDevice
}
from
"../../types/device.types"
;
interface
IDeviceData
{
bat_level
:
string
;
location
:
{
lat
:
string
;
lon
:
string
;
speed
:
string
;
};
}
interface
IAudioList
{
path
:
string
;
url
:
string
;
file_exists
:
boolean
;
file_ext
:
string
;
file_size
:
string
;
date
:
string
;
}
import
type
{
IAudioList
,
IDevice
,
IDeviceData
,
}
from
"../../types/device.types"
;
interface
IDeviceState
{
devices
:
IDevice
[];
...
...
@@ -28,7 +14,6 @@ interface IDeviceState {
isAudioListLoading
:
boolean
;
loadingDevices
:
boolean
;
errorDevices
:
string
;
isFetched
:
boolean
;
isDeletingDevice
:
boolean
;
}
...
...
@@ -40,7 +25,6 @@ const initialState: IDeviceState = {
isAudioListLoading
:
false
,
loadingDevices
:
false
,
errorDevices
:
""
,
isFetched
:
false
,
isDeletingDevice
:
false
,
};
...
...
@@ -60,6 +44,13 @@ export const fetchDevices = createAsyncThunk(
return
rejectWithValue
(
"Unknown error occurred"
);
}
},
{
condition
:
(
_
,
{
getState
})
=>
{
const
state
=
getState
()
as
{
device
:
IDeviceState
};
return
state
.
device
.
devices
.
length
===
0
;
},
}
);
...
...
@@ -161,18 +152,15 @@ const deviceSlice = createSlice({
builder
.
addCase
(
fetchDevices
.
pending
,
(
state
)
=>
{
state
.
loadingDevices
=
true
;
state
.
isFetched
=
false
;
})
.
addCase
(
fetchDevices
.
fulfilled
,
(
state
,
action
)
=>
{
state
.
loadingDevices
=
false
;
state
.
devices
=
action
.
payload
;
state
.
selectedDevice
=
action
.
payload
[
0
]
??
null
;
state
.
isFetched
=
true
;
})
.
addCase
(
fetchDevices
.
rejected
,
(
state
,
action
)
=>
{
state
.
loadingDevices
=
false
;
state
.
errorDevices
=
action
.
payload
as
string
;
state
.
isFetched
=
false
;
})
.
addCase
(
fetchDeviceData
.
fulfilled
,
(
state
,
action
)
=>
{
...
...
@@ -182,11 +170,8 @@ const deviceSlice = createSlice({
.
addCase
(
deleteDevice
.
pending
,
(
state
)
=>
{
state
.
isDeletingDevice
=
true
;
})
.
addCase
(
deleteDevice
.
fulfilled
,
(
state
,
action
)
=>
{
.
addCase
(
deleteDevice
.
fulfilled
,
(
state
)
=>
{
state
.
isDeletingDevice
=
false
;
if
(
action
.
payload
.
success
)
{
state
.
isFetched
=
false
;
}
})
.
addCase
(
deleteDevice
.
rejected
,
(
state
,
action
)
=>
{
state
.
isDeletingDevice
=
false
;
...
...
src/types/device.types.ts
View file @
51e31a1b
...
...
@@ -12,3 +12,21 @@ export interface IDevice {
}[];
};
}
export
interface
IDeviceData
{
bat_level
:
string
;
location
:
{
lat
:
string
;
lon
:
string
;
speed
:
string
;
};
}
export
interface
IAudioList
{
path
:
string
;
url
:
string
;
file_exists
:
boolean
;
file_ext
:
string
;
file_size
:
string
;
date
:
string
;
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment