Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
I_Helmet
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
21_22-J 62
I_Helmet
Commits
9c42371e
Commit
9c42371e
authored
May 07, 2022
by
Balasuriya D.A.M.
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Creating Context/Use ContextHook Frontend
parent
5bb926e8
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
50 additions
and
2 deletions
+50
-2
IT18021080/Telemedicine-Chat-App/frontend/src/Context/ChatProvider.js
...elemedicine-Chat-App/frontend/src/Context/ChatProvider.js
+33
-0
IT18021080/Telemedicine-Chat-App/frontend/src/Pages/Homepage.js
...1080/Telemedicine-Chat-App/frontend/src/Pages/Homepage.js
+14
-0
IT18021080/Telemedicine-Chat-App/frontend/src/index.js
IT18021080/Telemedicine-Chat-App/frontend/src/index.js
+3
-2
No files found.
IT18021080/Telemedicine-Chat-App/frontend/src/Context/ChatProvider.js
0 → 100644
View file @
9c42371e
import
{
createContext
,
useContext
,
useEffect
,
useState
}
from
"
react
"
;
import
{
useHistory
}
from
"
react-router-dom
"
;
const
ChatContext
=
createContext
();
const
ChatProvider
=
({
children
})
=>
{
const
[
user
,
setUser
]
=
useState
();
const
history
=
useHistory
();
useEffect
(()
=>
{
const
userInfo
=
JSON
.
parse
(
localStorage
.
getItem
(
"
userInfo
"
));
setUser
(
userInfo
);
//check if user is loged in
if
(
!
userInfo
)
{
history
.
pushState
(
"
/
"
);
}
},
[
history
]);
return
(
<
ChatContext
.
Provider
value
=
{{
user
,
setUser
}}
>
{
children
}
<
/ChatContext.Provider
>
);
};
export
const
ChatState
=
()
=>
{
return
useContext
(
ChatContext
);
};
export
default
ChatProvider
;
IT18021080/Telemedicine-Chat-App/frontend/src/Pages/Homepage.js
View file @
9c42371e
import
React
from
"
react
"
;
import
React
from
"
react
"
;
import
{
useEffect
}
from
"
react
"
;
import
{
import
{
Container
,
Container
,
Box
,
Box
,
...
@@ -11,8 +12,21 @@ import {
...
@@ -11,8 +12,21 @@ import {
}
from
"
@chakra-ui/react
"
;
}
from
"
@chakra-ui/react
"
;
import
Login
from
"
../components/Authentication/Login
"
;
import
Login
from
"
../components/Authentication/Login
"
;
import
Signup
from
"
../components/Authentication/Signup
"
;
import
Signup
from
"
../components/Authentication/Signup
"
;
import
{
useHistory
}
from
"
react-router-dom
"
;
const
Homepage
=
()
=>
{
const
Homepage
=
()
=>
{
const
history
=
useHistory
();
useEffect
(()
=>
{
const
user
=
JSON
.
parse
(
localStorage
.
getItem
(
"
userInfo
"
));
//check if user is loged in
if
(
user
)
history
.
push
(
"
/chats
"
);
},
[
history
]);
return
(
return
(
//use container from chakra ui and remove div
//use container from chakra ui and remove div
<
Container
maxW
=
"
xl
"
centerContent
>
<
Container
maxW
=
"
xl
"
centerContent
>
...
...
IT18021080/Telemedicine-Chat-App/frontend/src/index.js
View file @
9c42371e
...
@@ -4,16 +4,17 @@ import "./index.css";
...
@@ -4,16 +4,17 @@ import "./index.css";
import
App
from
"
./App
"
;
import
App
from
"
./App
"
;
import
{
ChakraProvider
}
from
"
@chakra-ui/react
"
;
import
{
ChakraProvider
}
from
"
@chakra-ui/react
"
;
import
{
BrowserRouter
}
from
"
react-router-dom
"
;
import
{
BrowserRouter
}
from
"
react-router-dom
"
;
import
ChatProvider
from
"
./Context/ChatProvider
"
;
ReactDOM
.
render
(
ReactDOM
.
render
(
<
React
.
StrictMode
>
<
ChatProvider
>
<
BrowserRouter
>
<
BrowserRouter
>
<
ChakraProvider
>
<
ChakraProvider
>
<
App
/>
<
App
/>
<
/ChakraProvider
>
<
/ChakraProvider
>
<
/BrowserRouter
>
<
/BrowserRouter
>
<
/
React.StrictMode
>
,
<
/
ChatProvider
>
,
document
.
getElementById
(
"
root
"
)
document
.
getElementById
(
"
root
"
)
//rendering everything on root tag
//rendering everything on root tag
);
);
...
...
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