@@ -82,6 +82,7 @@ type View =
8282 | "audit"
8383 | "configuration"
8484type SortDirection = "asc" | "desc"
85+ type GigTab = "gigs" | "leads"
8586
8687type User = {
8788 subject : string
@@ -666,6 +667,19 @@ function detailIdFromPath(expectedView: "gigs" | "projects" = "gigs") {
666667 }
667668}
668669
670+ function gigTabFromHash ( hash = window . location . hash ) : GigTab {
671+ return hash . replace ( / ^ # / , "" ) === "leads" ? "leads" : "gigs"
672+ }
673+
674+ function updateGigTabHash ( tab : GigTab ) {
675+ const hash = tab === "leads" ? "#leads" : "#gigs"
676+ window . history . replaceState (
677+ window . history . state ,
678+ "" ,
679+ `${ window . location . pathname } ${ window . location . search } ${ hash } ` ,
680+ )
681+ }
682+
669683async function requestJson < T > ( url : string , options : RequestInit = { } ) : Promise < T > {
670684 const method = String ( options . method || "GET" ) . toUpperCase ( )
671685 const headers = new Headers ( options . headers )
@@ -908,7 +922,7 @@ function App() {
908922 const [ gigQuery , setGigQuery ] = useState ( "" )
909923 const [ gigIncludeHistorical , setGigIncludeHistorical ] = useState ( false )
910924 const [ gigLimit , setGigLimit ] = useState ( 100 )
911- const [ activeGigTab , setActiveGigTab ] = useState < "gigs" | "leads" > ( "gigs" )
925+ const [ activeGigTab , setActiveGigTab ] = useState < GigTab > ( gigTabFromHash )
912926 const [ gigLeadStatus , setGigLeadStatus ] = useState ( "pending" )
913927 const [ projectQuery , setProjectQuery ] = useState ( "" )
914928 const [ projectStatus , setProjectStatus ] = useState ( initialProjectDetailId ? "" : "Open" )
@@ -984,6 +998,11 @@ function App() {
984998 }
985999 navigateRef . current = navigate
9861000
1001+ function selectGigTab ( tab : GigTab ) {
1002+ setActiveGigTab ( tab )
1003+ updateGigTabHash ( tab )
1004+ }
1005+
9871006 function crmContactUrl ( contactId ?: string ) {
9881007 if ( ! crmBaseUrl || ! contactId ) return ""
9891008 return `${ crmBaseUrl } /#Contact/view/${ encodeURIComponent ( contactId ) } `
@@ -1717,7 +1736,7 @@ function App() {
17171736 } ,
17181737 )
17191738 showToast ( "Posted lead to Discord" , "ok" )
1720- setActiveGigTab ( "gigs" )
1739+ selectGigTab ( "gigs" )
17211740 setGigStatus ( "" )
17221741 setGigQuery ( "" )
17231742 await loadGigLeads ( )
@@ -2344,6 +2363,12 @@ function App() {
23442363 return ( ) => window . removeEventListener ( "popstate" , onPopState )
23452364 } , [ ] )
23462365
2366+ useEffect ( ( ) => {
2367+ const onHashChange = ( ) => setActiveGigTab ( gigTabFromHash ( ) )
2368+ window . addEventListener ( "hashchange" , onHashChange )
2369+ return ( ) => window . removeEventListener ( "hashchange" , onHashChange )
2370+ } , [ ] )
2371+
23472372 useEffect ( ( ) => {
23482373 if ( ! toast . message ) return undefined
23492374 const timeout = window . setTimeout ( ( ) => setToast ( { message : "" } ) , 4500 )
@@ -2776,7 +2801,7 @@ function App() {
27762801 canIncludeHistorical = { can ( "people:read" ) }
27772802 crmContactUrl = { crmContactUrl }
27782803 crmAttachmentUrl = { crmAttachmentUrl }
2779- setActiveTab = { setActiveGigTab }
2804+ setActiveTab = { selectGigTab }
27802805 setStatus = { setGigStatus }
27812806 setQuery = { setGigQuery }
27822807 setLeadStatus = { setGigLeadStatus }
0 commit comments