@@ -11,6 +11,7 @@ import { useState, useEffect, useContext } from 'react';
1111import HeightLimit from '../height_limit_scrollable/heightLimit' ;
1212import { useRouter } from 'next/navigation' ;
1313import { RefreshContext } from '@/app/_contexts/refresh' ;
14+ import { useNotifications } from '@/app/_contexts/notification' ;
1415
1516export default function Data ( ) {
1617 const [ hw , setHw ] = useState ( '50vh' ) ;
@@ -23,6 +24,7 @@ export default function Data() {
2324 const [ threshold , setThreshold ] = useState ( 0 ) ;
2425 const { refreshCont } = useContext ( RefreshContext ) ;
2526 const router = useRouter ( ) ;
27+ const { addNotification } = useNotifications ( ) ;
2628 const header = {
2729 Authorization :
2830 'Token ' + JSON . parse ( localStorage . getItem ( ACCESS_TOKEN_NAME ) ) ,
@@ -31,15 +33,27 @@ export default function Data() {
3133 useEffect ( ( ) => {
3234 axios
3335 . get ( API_BASE_URL + '/statquery' , { headers : header } )
34- . then ( function ( response ) {
36+ . then ( ( response ) => {
3537 if ( response . status === 200 ) {
3638 setStatData ( response . data ) ;
39+ } else {
40+ addNotification ( 'Unexpected server response.' ) ;
3741 }
3842 } )
39- . catch ( function ( error ) {
40- console . error ( 'Error fetching data:' , error ) ;
41- if ( error . response . status == 401 ) {
42- router . push ( '/login' ) ;
43+ . catch ( ( error ) => {
44+ if ( error . response ) {
45+ if ( error . response . status === 401 ) {
46+ addNotification ( 'Session expired. Redirecting to login...' ) ;
47+ router . push ( '/login' ) ;
48+ } else {
49+ addNotification ( 'Server error while fetching stats.' ) ;
50+ }
51+ } else if ( error . request ) {
52+ addNotification (
53+ 'No response from server. Check your connection.'
54+ ) ;
55+ } else {
56+ addNotification ( 'Request setup failed. Please try again.' ) ;
4357 }
4458 } ) ;
4559 } , [ refreshCont ] ) ;
@@ -73,14 +87,29 @@ export default function Data() {
7387 setName ( list ) ;
7488 setThreshold ( response . data . threshold ) ;
7589 } else {
76- //console.log( response.data,'hhhhhh')
90+ addNotification ( 'Unexpected response from server.' ) ;
7791 }
7892 } )
79- . catch ( function ( error ) {
80- if ( error . response . status == 401 ) {
81- router . push ( '/login' ) ;
93+ . catch ( ( error ) => {
94+ if ( error . response ) {
95+ if ( error . response . status === 401 ) {
96+ addNotification ( 'Session expired. Redirecting to login...' ) ;
97+ router . push ( '/login' ) ;
98+ } else {
99+ addNotification (
100+ 'Server error. Error status:' ,
101+ error . response . status
102+ ) ;
103+ }
104+ } else if ( error . request ) {
105+ addNotification (
106+ 'No response from server. Please check your connection.'
107+ ) ;
108+ } else {
109+ addNotification (
110+ 'Failed to send request. Please contact support.'
111+ ) ;
82112 }
83- //console.log((error),'mmmmmm');
84113 } ) ;
85114 } , [ ] ) ;
86115
@@ -99,9 +128,9 @@ export default function Data() {
99128 >
100129 < div className = "sticky top-0 bg-[#1c1c1c]" >
101130 < div className = "mb-0 max-sm:mb-2" >
102- < p className = "text-[6vw] max-sm:text-6xl" >
131+ < div className = "text-[6vw] max-sm:text-6xl" >
103132 < ExpandableName name = { name } />
104- </ p >
133+ </ div >
105134 </ div >
106135 < div className = "flex" >
107136 < div className = "flex flex-[2] items-center" >
@@ -154,49 +183,21 @@ export default function Data() {
154183
155184function ExpandableName ( { name } ) {
156185 const [ expanded , setExpanded ] = useState ( false ) ;
157- const [ isWrapped , setIsWrapped ] = useState ( false ) ;
158-
159- useEffect ( ( ) => {
160- if ( ( name [ 0 ] + name [ 1 ] ) . length > 20 ) {
161- setIsWrapped ( true ) ;
162- setExpanded ( false ) ;
163- } else {
164- setExpanded ( true ) ;
165- }
166- } , [ name ] ) ;
167186
168187 return (
169188 < div
170- className = "w-full cursor-pointer break-words text-[6vw] max-sm:text-6xl"
171- onClick = { ( ) => {
172- isWrapped && setExpanded ( ! expanded ) ;
173- } }
189+ className = "w-full cursor-pointer text-[6vw] max-sm:text-6xl"
190+ onClick = { ( ) => setExpanded ( ! expanded ) }
174191 >
175- < p className = "max-sm:hidden" >
176- { expanded ? (
177- < >
178- < span > { name [ 0 ] } </ span >
179-
180- < span className = "font-thin" > { name [ 1 ] } </ span >
181- </ >
182- ) : name [ 0 ] ?. length > 20 ? (
183- < >
184- < span > { name [ 0 ] . slice ( 0 , 20 ) } </ span >
185- </ >
186- ) : (
187- < >
188- < span > { name [ 0 ] } </ span >
189-
190- < span className = "font-thin" >
191- { name [ 1 ] ?. slice ( 0 , 20 - name [ 0 ] . length ) + '...' }
192- </ span >
193- </ >
194- ) }
195- </ p >
196- < p className = "sm:hidden" >
197- < span > { name [ 0 ] } </ span >
198-
199- < span className = "font-thin" > { name [ 1 ] } </ span >
192+ < p
193+ className = { `w-full max-w-[90vw] overflow-hidden text-ellipsis ${
194+ expanded
195+ ? 'whitespace-normal'
196+ : 'min-h-[67px] overflow-x-hidden whitespace-nowrap'
197+ } `}
198+ title = { name [ 0 ] + ' ' + name [ 1 ] }
199+ >
200+ < span > { name [ 0 ] } </ span > < span className = "font-thin" > { name [ 1 ] } </ span >
200201 </ p >
201202 </ div >
202203 ) ;
0 commit comments