Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion src-ts/config/environments/environment.default.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ export const EnvironmentConfigDefault: GlobalConfig = {
V5: 'https://api.topcoder-dev.com/v5',
},
ENV: AppHostEnvironment.default,
LEARN_SRC: 'https://fcc.topcoder-dev.com:4431',
LOGGING: {
PUBLIC_TOKEN: 'puba0825671e469d16f940c5a30dc738f11',
SERVICE: 'platform-ui',
Expand Down
1 change: 0 additions & 1 deletion src-ts/config/environments/environment.dev.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ export const EnvironmentConfigDev: GlobalConfig = {
},
DISABLED_TOOLS: [],
ENV: AppHostEnvironment.dev,
LEARN_SRC: 'https://freecodecamp.topcoder-dev.com',
// TODO: Move stripe creds to .env file
STRIPE: {
ADMIN_TOKEN:
Expand Down
1 change: 0 additions & 1 deletion src-ts/config/environments/environment.prod.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ export const EnvironmentConfigProd: GlobalConfig = {
},
DISABLED_TOOLS: [ ],
ENV: AppHostEnvironment.prod,
LEARN_SRC: 'https://freecodecamp.topcoder.com',
// TODO: Move stripe creds to .env file
STRIPE: {
ADMIN_TOKEN:
Expand Down
1 change: 1 addition & 0 deletions src-ts/config/environments/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
export * from './app-host-environment.enum'
export { default as EnvironmentConfig } from './environment.config'
1 change: 0 additions & 1 deletion src-ts/lib/global-config.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ export interface GlobalConfig {
}
DISABLED_TOOLS?: Array<string>
ENV: string
LEARN_SRC: string,
LOGGING: {
PUBLIC_TOKEN: string
SERVICE: string
Expand Down
11 changes: 6 additions & 5 deletions src-ts/tools/learn/free-code-camp/FreeCodeCamp.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,15 @@ import { TitleNav } from './title-nav'
const FreeCodeCamp: FC<{}> = () => {

const {
profile,
initialized: profileReady,
isLoggedIn,
profile,
}: ProfileContextData = useContext(profileContext)
const isLoggedIn: boolean = !!profile

const navigate: NavigateFunction = useNavigate()
const routeParams: Params<string> = useParams()

const providerParam: string = routeParams.provider ?? ''

const [certificationParam, setCourseParam]: [string, Dispatch<SetStateAction<string>>] = useState(routeParams.certification ?? '')
const [moduleParam, setModuleParam]: [string, Dispatch<SetStateAction<string>>] = useState(routeParams.module ?? '')
const [lessonParam, setLessonParam]: [string, Dispatch<SetStateAction<string>>] = useState(routeParams.lesson ?? '')
Expand Down Expand Up @@ -178,7 +178,8 @@ const FreeCodeCamp: FC<{}> = () => {
lesson.course.certificationId,
lesson.course.id,
currentLesson
).then(setCertificateProgress)
)
.then(setCertificateProgress)
} else {
// TODO: remove this delay!!
// TEMP_FIX: delay this api call to allow for previous "completeLesson" call to write in the api
Expand Down Expand Up @@ -297,7 +298,7 @@ const FreeCodeCamp: FC<{}> = () => {
if (lessonPath !== lessonParam) {
setLessonParam(lessonPath)
}
// eslint-disable-next-line react-hooks/exhaustive-deps
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [
// DO NOT UPDATE THIS DEPS ARRAY!!
// we do not care about changes to the other deps
Expand Down
8 changes: 4 additions & 4 deletions src-ts/tools/learn/free-code-camp/fcc-frame/FccFrame.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { FC, memo, MutableRefObject, useEffect, useRef } from 'react'

import { EnvironmentConfig } from '../../../../config'
import { LearnConfig } from '../../learn-config'
import { LearnLessonMeta } from '../../learn-lib'

import styles from './FccFrame.module.scss'
Expand Down Expand Up @@ -33,14 +33,14 @@ const FccFrame: FC<FccFrameProps> = (props: FccFrameProps) => {
}

if (!frameIsReady.current) {
Object.assign(frameRef.current, { src: `${EnvironmentConfig.LEARN_SRC}/${props.lesson.lessonUrl}` })
Object.assign(frameRef.current, { src: `${LearnConfig.CLIENT}/${props.lesson.lessonUrl}` })
} else {
frameRef.current.contentWindow.postMessage(JSON.stringify({
data: { path: `/${lessonUrl}` },
event: 'fcc:url:update',
}), '*')
}
// eslint-disable-next-line react-hooks/exhaustive-deps
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [
lessonUrl,
])
Expand All @@ -52,7 +52,7 @@ const FccFrame: FC<FccFrameProps> = (props: FccFrameProps) => {
const handleEvent: (event: any) => void = (event: any) => {
const { data: jsonData, origin }: { data: string, origin: string } = event

if (origin.indexOf(EnvironmentConfig.LEARN_SRC) === -1) {
if (origin.indexOf(LearnConfig.CLIENT) === -1) {
return
}

Expand Down
1 change: 1 addition & 0 deletions src-ts/tools/learn/learn-config/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { default as LearnConfig } from './learn.config'
4 changes: 4 additions & 0 deletions src-ts/tools/learn/learn-config/learn-config.model.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export interface LearnConfigModel {
API: string
CLIENT: string
}
6 changes: 6 additions & 0 deletions src-ts/tools/learn/learn-config/learn.bsouza.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { LearnConfigModel } from './learn-config.model'
import { LearnConfigDefault } from './learn.default.config'

export const LearnConfigBsouza: LearnConfigModel = {
...LearnConfigDefault,
}
31 changes: 31 additions & 0 deletions src-ts/tools/learn/learn-config/learn.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { AppHostEnvironment } from '../../../config'

import { LearnConfigModel } from './learn-config.model'
import { LearnConfigBsouza } from './learn.bsouza.config'
import { LearnConfigDefault } from './learn.default.config'
import { LearnConfigDev } from './learn.dev.config'
import { LearnConfigProd } from './learn.prod.config'

function getConfig(): LearnConfigModel {

switch (process.env.REACT_APP_HOST_ENV) {

case AppHostEnvironment.bsouza:
return LearnConfigBsouza

case AppHostEnvironment.dev:
return LearnConfigDev

case AppHostEnvironment.prod:
return LearnConfigProd

default:
return LearnConfigDefault
}
}

const LearnConfig: LearnConfigModel = {
...getConfig(),
}

export default LearnConfig
6 changes: 6 additions & 0 deletions src-ts/tools/learn/learn-config/learn.default.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { LearnConfigModel } from './learn-config.model'

export const LearnConfigDefault: LearnConfigModel = {
API: 'http://localhost:3001/v5/learning-paths',
CLIENT: 'https://fcc.topcoder-dev.com:4431',
}
6 changes: 6 additions & 0 deletions src-ts/tools/learn/learn-config/learn.dev.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { LearnConfigModel } from './learn-config.model'

export const LearnConfigDev: LearnConfigModel = {
API: 'https://api.topcoder-dev.com/v5/learning-paths',
CLIENT: 'https://freecodecamp.topcoder-dev.com',
}
6 changes: 6 additions & 0 deletions src-ts/tools/learn/learn-config/learn.prod.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { LearnConfigModel } from './learn-config.model'

export const LearnConfigProd: LearnConfigModel = {
API: 'https://api.topcoder.com/v5/learning-paths',
CLIENT: 'https://freecodecamp.topcoder.com',
}
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
import { xhrGetAsync } from '../../../../../lib/functions'
import { getPath } from '../../learn-url.config'
import { learnUrlGet } from '../../functions'

import { LearnCertification } from './learn-certification.model'

export function getAsync(
providerName: string = 'freeCodeCamp',
certificationId?: string
): Promise<Array<LearnCertification>> {
return xhrGetAsync<Array<LearnCertification>>(getPath(

const url: string = learnUrlGet(
'certifications',
...(certificationId ? [certificationId] : []),
`?providerName=${providerName}`
))
)
return xhrGetAsync<Array<LearnCertification>>(url)
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import { xhrGetAsync } from '../../../../../lib/functions'
import { getPath } from '../../learn-url.config'
import { xhrGetAsync } from '../../../../../lib'
import { learnUrlGet } from '../../functions'

import { LearnCourse } from './learn-course.model'

export function getCourseAsync(provider: string, certification: string): Promise<LearnCourse|undefined> {
return xhrGetAsync<Array<LearnCourse>>(getPath(
'courses',
`?certification=${certification}&provider=${provider}`,
)).then(courses => courses[0])
export function getAsync(provider: string, certification: string):
Promise<LearnCourse | undefined> {

const url: string = learnUrlGet('courses', `?certification=${certification}&provider=${provider}`)

return xhrGetAsync<Array<LearnCourse>>(url)
.then(courses => courses[0])
}
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
export * from './course.store'
export { getAsync as courseGetAsync } from './course.store'
export * from './learn-course.model'
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Dispatch, SetStateAction, useEffect, useState } from 'react'

import { getCourseAsync } from './courses-functions'
import { courseGetAsync } from './courses-functions'
import { CoursesProviderData } from './courses-provider-data.model'

export function useCourses(provider: string, certification?: string): CoursesProviderData {
Expand Down Expand Up @@ -32,7 +32,7 @@ export function useCourses(provider: string, certification?: string): CoursesPro
loading: true,
}))

getCourseAsync(provider, certification)
courseGetAsync(provider, certification)
.then((course) => {
if (!mounted) {
return
Expand Down
1 change: 1 addition & 0 deletions src-ts/tools/learn/learn-lib/functions/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { get as learnUrlGet } from './learn-url.functions'
10 changes: 10 additions & 0 deletions src-ts/tools/learn/learn-lib/functions/learn-url.functions.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { LearnConfig } from '../../learn-config'

export function get(...parts: Array<string>): string {
return [
LearnConfig.API,
...parts,
]
.filter(Boolean)
.join('/')
}
7 changes: 0 additions & 7 deletions src-ts/tools/learn/learn-lib/learn-url.config.ts

This file was deleted.

68 changes: 35 additions & 33 deletions src-ts/tools/learn/learn-lib/lesson-provider/lesson.provider.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Dispatch, SetStateAction, useEffect, useState } from 'react'

import { getCourseAsync } from '../courses-provider/courses-functions'
import { courseGetAsync } from '../courses-provider'

import { LearnLesson } from './learn-lesson.model'
import { LearnModule } from './learn-module.model'
Expand Down Expand Up @@ -35,43 +35,45 @@ export function useLessonProvider(
loading: true,
}))

getCourseAsync(provider, course).then((courseData) => {
if (!mounted) {
return
}
courseGetAsync(provider, course)
.then((courseData) => {

const moduleData: LearnModule|undefined = courseData?.modules.find(m => m.key === module)
const lessonData: LearnLesson|undefined = moduleData?.lessons.find(l => l.dashedName === lesson)
if (!mounted) {
return
}

const lessonUrl: string = [
'learn',
courseData?.key ?? course,
module,
lesson,
].filter(Boolean).join('/')
const moduleData: LearnModule | undefined = courseData?.modules.find(m => m.key === module)
const lessonData: LearnLesson | undefined = moduleData?.lessons.find(l => l.dashedName === lesson)

setState((prevState) => ({
...prevState,
lesson: lessonData && {
...lessonData,
course: {
certification: courseData?.certification ?? '',
certificationId: courseData?.certificationId ?? '',
id: courseData?.id ?? '',
title: courseData?.title ?? '',
},
lessonUrl,
module: {
dashedName: moduleData?.meta.dashedName ?? '',
title: moduleData?.meta.name ?? '',
const lessonUrl: string = [
'learn',
courseData?.key ?? course,
module,
lesson,
].filter(Boolean).join('/')

setState((prevState) => ({
...prevState,
lesson: lessonData && {
...lessonData,
course: {
certification: courseData?.certification ?? '',
certificationId: courseData?.certificationId ?? '',
id: courseData?.id ?? '',
title: courseData?.title ?? '',
},
lessonUrl,
module: {
dashedName: moduleData?.meta.dashedName ?? '',
title: moduleData?.meta.name ?? '',
},
},
},
loading: false,
ready: true,
}))
})
loading: false,
ready: true,
}))
})

return () => {mounted = false}
return () => { mounted = false }
}, [provider, course, module, lesson])

return state
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { xhrGetAsync } from '../../../../../lib/functions'
import { getPath } from '../../learn-url.config'
import { learnUrlGet } from '../../functions'

import { ResourceProvider } from './resource-provider.model'

export function getResourceProvidersAsync(): Promise<Array<ResourceProvider>|undefined> {
return xhrGetAsync<Array<ResourceProvider>>(getPath(
'providers'
))
export function getResourceProvidersAsync(): Promise<Array<ResourceProvider> | undefined> {

const url: string = learnUrlGet('providers')
return xhrGetAsync<Array<ResourceProvider>>(url)
}
Loading