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
52fcdefa
Commit
52fcdefa
authored
Jul 08, 2025
by
asranov0003
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: add device slice
parent
0409f918
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
109 additions
and
0 deletions
+109
-0
deviceSlice.ts
src/stores/slices/deviceSlice.ts
+107
-0
store.ts
src/stores/store.ts
+2
-0
No files found.
src/stores/slices/deviceSlice.ts
0 → 100644
View file @
52fcdefa
import
{
createAsyncThunk
,
createSlice
}
from
"@reduxjs/toolkit"
;
import
{
sendRpcRequest
}
from
"../../services/apiClient"
;
interface
IDevice
{
id
:
string
;
name
:
string
;
created
:
string
;
lastOnline
:
string
;
osOver
:
string
;
deviceInfo
:
{
date_updated
:
string
;
permissions
:
{
isGranted
:
boolean
;
permission
:
string
;
}[];
};
}
interface
IDeviceState
{
device
:
IDevice
|
null
;
devices
:
IDevice
[];
loadingDevice
:
boolean
;
loadingDevices
:
boolean
;
errorDevice
:
string
;
errorDevices
:
string
;
}
const
initialState
:
IDeviceState
=
{
device
:
null
,
devices
:
[],
loadingDevice
:
false
,
loadingDevices
:
false
,
errorDevice
:
""
,
errorDevices
:
""
,
};
export
const
fetchDevice
=
createAsyncThunk
(
"device/fetchDevice"
,
async
(
deviceId
:
string
,
{
rejectWithValue
})
=>
{
try
{
const
response
=
await
sendRpcRequest
<
IDevice
>
(
"devices.getdevicedata"
,
{
deviceId
,
});
return
response
;
}
catch
(
error
:
unknown
)
{
if
(
typeof
error
===
"object"
&&
error
!==
null
&&
"message"
in
error
)
{
return
rejectWithValue
(
error
.
message
);
}
return
rejectWithValue
(
"Unknown error occurred"
);
}
}
);
export
const
fetchDevices
=
createAsyncThunk
(
"device/fetchDevices"
,
async
(
_
,
{
rejectWithValue
})
=>
{
try
{
const
response
=
await
sendRpcRequest
<
{
list
:
IDevice
[]
}
>
(
"devices.getlist"
);
return
response
.
list
;
}
catch
(
error
:
unknown
)
{
if
(
typeof
error
===
"object"
&&
error
!==
null
&&
"message"
in
error
)
{
return
rejectWithValue
(
error
.
message
);
}
return
rejectWithValue
(
"Unknown error occurred"
);
}
}
);
const
deviceSlice
=
createSlice
({
name
:
"device"
,
initialState
,
reducers
:
{},
extraReducers
:
(
builder
)
=>
{
builder
.
addCase
(
fetchDevice
.
pending
,
(
state
)
=>
{
state
.
loadingDevice
=
true
;
})
.
addCase
(
fetchDevice
.
fulfilled
,
(
state
,
action
)
=>
{
state
.
loadingDevice
=
false
;
state
.
device
=
action
.
payload
;
})
.
addCase
(
fetchDevice
.
rejected
,
(
state
,
action
)
=>
{
state
.
loadingDevice
=
false
;
state
.
errorDevice
=
action
.
payload
as
string
;
})
.
addCase
(
fetchDevices
.
pending
,
(
state
)
=>
{
state
.
loadingDevices
=
true
;
})
.
addCase
(
fetchDevices
.
fulfilled
,
(
state
,
action
)
=>
{
state
.
loadingDevices
=
false
;
state
.
devices
=
action
.
payload
;
})
.
addCase
(
fetchDevices
.
rejected
,
(
state
,
action
)
=>
{
state
.
loadingDevices
=
false
;
state
.
errorDevices
=
action
.
payload
as
string
;
});
},
});
export
default
deviceSlice
.
reducer
;
src/stores/store.ts
View file @
52fcdefa
...
...
@@ -2,6 +2,7 @@ import { configureStore } from "@reduxjs/toolkit";
import
authSlice
from
"./slices/authSlice"
;
import
accountSlice
from
"./slices/accountSlice"
;
import
notificationSlice
from
"./slices/notificationSlice"
;
import
deviceSlice
from
"./slices/deviceSlice"
;
import
{
useDispatch
,
useSelector
,
...
...
@@ -13,6 +14,7 @@ export const store = configureStore({
auth
:
authSlice
,
account
:
accountSlice
,
notification
:
notificationSlice
,
device
:
deviceSlice
,
},
});
...
...
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