@@ -6,7 +6,8 @@ import Problem from '../components/problem'
66import NotStarted from '../components/not-started'
77import { useToast } from '../components/toast'
88
9- import { getChallenges , getPrivateSolves } from '../api/challenges'
9+ import { privateProfile } from '../api/profile'
10+ import { getChallenges } from '../api/challenges'
1011
1112const loadStates = {
1213 pending : 0 ,
@@ -84,25 +85,30 @@ const Challenges = ({ classes }) => {
8485 }
8586 } )
8687
87- setProblems ( data )
88- setCategories ( newCategories )
89- }
90- action ( )
91- } , [ toast , categories , problems ] )
92-
93- useEffect ( ( ) => {
94- const action = async ( ) => {
95- const { solves, bloods, error } = await getPrivateSolves ( )
96- if ( error ) {
97- toast ( { body : error , type : 'error' } )
88+ const { data : profileData , error : profileError } = await privateProfile ( )
89+ if ( profileError ) {
90+ toast ( { body : profileError , type : 'error' } )
9891 return
9992 }
10093
101- setSolveIDs ( solves . map ( solve => solve . id ) )
102- setBloods ( new Map ( bloods . map ( x => [ x . id , x . rank ] ) ) )
94+ setSolveIDs ( profileData . solves . map ( solve => solve . id ) )
95+ setBloods ( new Map ( profileData . bloods . map ( x => [ x . id , x . rank ] ) ) )
96+
97+ const instancerPlaceholderRegex = / \{ i n s t a n c e r : ( [ a - z A - Z 0 - 9 - ] + ) \} / g
98+ if ( config . instancerUrl !== '' ) {
99+ data . forEach ( problem => {
100+ problem . description = problem . description . replaceAll ( '{instancer}' , `[Deploy challenge](${ encodeURI ( config . instancerUrl ) } /chall/${ problem . id } ?token=${ encodeURIComponent ( profileData . instancerToken ) } )` )
101+ problem . description = problem . description . replaceAll ( '{instancer_token}' , encodeURIComponent ( profileData . instancerToken ) )
102+ problem . description = problem . description . replaceAll ( '{instancer_url}' , encodeURI ( config . instancerUrl ) )
103+ problem . description = problem . description . replaceAll ( instancerPlaceholderRegex , `${ encodeURI ( config . instancerUrl ) } /chall/$1?token=${ encodeURIComponent ( profileData . instancerToken ) } ` )
104+ } )
105+ }
106+
107+ setProblems ( data )
108+ setCategories ( newCategories )
103109 }
104110 action ( )
105- } , [ toast ] )
111+ } , [ toast , categories , problems ] )
106112
107113 useEffect ( ( ) => {
108114 localStorage . challPageState = JSON . stringify ( { categories, showSolved } )
0 commit comments