@@ -212,12 +212,11 @@ if (role === 'Volunteer' && userHaveTask.length > 0) {
212212 return tab ;
213213 } ;
214214
215- useEffect ( ( ) => {
216- const tab = tabMapping [ location . hash ] ;
217- if ( tab !== undefined ) {
218- changeTab ( tab ) ;
219- }
220- } , [ location . hash ] ) ; // This effect will run whenever the hash changes
215+ useEffect ( ( ) => {
216+ if ( initialTab != null && ! location . hash ) {
217+ changeTab ( initialTab ) ;
218+ }
219+ } , [ initialTab , location . hash ] ) ; // This effect will run whenever the hash changes
221220
222221/* ---------------- methods -------------- */
223222const updateTimeEntryItems = ( ) => {
@@ -286,9 +285,21 @@ const generateAllTimeEntryItems = () => {
286285 const res = await axios . get ( url ) ;
287286
288287 const data = res . data . length > 0 ? res . data : [ ] ;
289- const defaultTabValue = defaultTab ( data ) ;
290- setTimeLogState ( { ...timeLogState , isTimeEntriesLoading : false } ) ;
291- setInitialTab ( defaultTabValue ) ;
288+ const mappedHash = tabMapping [ location . hash ] ;
289+
290+ if ( mappedHash !== undefined ) {
291+ // If the URL has a known hash, open that tab immediately
292+ setTimeLogState ( s => ( {
293+ ...s ,
294+ isTimeEntriesLoading : false ,
295+ activeTab : mappedHash ,
296+ } ) ) ;
297+ setInitialTab ( null ) ; // so the initialTab effect won’t override
298+ } else {
299+ // No hash → fall back to your existing default logic
300+ setTimeLogState ( s => ( { ...s , isTimeEntriesLoading : false } ) ) ;
301+ setInitialTab ( defaultTab ( data ) ) ;
302+ }
292303 } catch ( e ) {
293304 console . log ( e ) ;
294305 }
@@ -345,23 +356,16 @@ const generateAllTimeEntryItems = () => {
345356 }
346357
347358 // Clear the hash to trigger the useEffect on hash change
348- if ( location . hash ) {
349- window . location . hash = '' ;
350- }
359+ // if (location.hash) {
360+ // window.location.hash = '';
361+ // }
351362
352363 setTimeLogState ( {
353364 ...timeLogState ,
354365 activeTab : tab ,
355366 } ) ;
356367 } ;
357368
358- useEffect ( ( ) => {
359- const tab = tabMapping [ location . hash ] ;
360- if ( tab !== undefined ) {
361- changeTab ( tab ) ;
362- }
363- } , [ location . hash ] ) ; // This effect will run whenever the hash changes
364-
365369 const handleInputChange = e => {
366370 setTimeLogState ( { ...timeLogState , [ e . target . name ] : e . target . value } ) ;
367371 } ;
@@ -518,6 +522,13 @@ const generateAllTimeEntryItems = () => {
518522
519523 /* ---------------- useEffects -------------- */
520524
525+ useEffect ( ( ) => {
526+ const mapped = tabMapping [ location . hash ] ;
527+ if ( mapped !== undefined ) {
528+ setTimeLogState ( s => ( { ...s , activeTab : mapped } ) ) ;
529+ }
530+ } , [ location . hash ] ) ;
531+
521532 // Update user ID if it changes in the URL
522533 useEffect ( ( ) => {
523534 if ( urlId ) {
@@ -543,9 +554,6 @@ const generateAllTimeEntryItems = () => {
543554 props . getBadgeCount ( displayUserId ) ;
544555 } , [ displayUserId , props ] ) ;
545556
546- useEffect ( ( ) => {
547- changeTab ( initialTab ) ;
548- } , [ initialTab ] ) ;
549557
550558 useEffect ( ( ) => {
551559 // Build the time log after new data is loaded
0 commit comments