Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
O
openfing-web
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Santiago Rafael Gonzalez Pereyra
openfing-web
Commits
c427006f
Commit
c427006f
authored
5 years ago
by
Santiago Rafael Gonzalez Pereyra
Browse files
Options
Downloads
Patches
Plain Diff
Course api request refactor
parent
41d65106
No related branches found
No related tags found
1 merge request
!1
WIP: API requests refactor
Changes
4
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
src/components/BreakpointManager.ts
+2
-1
2 additions, 1 deletion
src/components/BreakpointManager.ts
src/helper.ts
+1
-1
1 addition, 1 deletion
src/helper.ts
src/screens/course/Course.tsx
+87
-11
87 additions, 11 deletions
src/screens/course/Course.tsx
src/style/Mixins.ts
+2
-1
2 additions, 1 deletion
src/style/Mixins.ts
with
92 additions
and
14 deletions
src/components/BreakpointManager.ts
+
2
−
1
View file @
c427006f
import
{
useContext
,
useEffect
}
from
"
react
"
;
import
{
getBreakpointForWidth
}
from
"
src/helper
"
;
import
{
AppStoreContext
}
from
"
./AppStoreContext
"
;
import
{
getBreakpointForWidth
}
from
"
src/helper
"
;
export
const
BreakpointManager
=
()
=>
{
const
appStore
=
useContext
(
AppStoreContext
);
...
...
This diff is collapsed.
Click to expand it.
src/helper.ts
+
1
−
1
View file @
c427006f
...
...
@@ -4,7 +4,7 @@ export const getBreakpointForWidth = (width: number): number => {
const
breakpoints
=
Object
.
keys
(
Breakpoint
);
let
result
=
breakpoints
[
0
];
for
(
let
i
=
0
;
i
<
breakpoints
.
length
&&
width
>
Breakpoint
[
breakpoints
[
i
]];
i
++
)
result
=
breakpoints
[
i
];
for
(
let
i
=
0
;
i
<
breakpoints
.
length
&&
width
>
=
Breakpoint
[
breakpoints
[
i
]];
i
++
)
result
=
breakpoints
[
i
];
return
Breakpoint
[
result
];
};
...
...
This diff is collapsed.
Click to expand it.
src/screens/course/Course.tsx
+
87
−
11
View file @
c427006f
import
{
CourseContext
,
CourseProvider
}
from
"
./useCourse
"
;
import
React
,
{
useContext
,
useEffect
,
useMemo
}
from
"
react
"
;
import
{
observer
,
useComputed
}
from
"
mobx-react-lite
"
;
import
{
useContext
,
useEffect
,
useMemo
}
from
"
react
"
;
import
{
AppStoreContext
}
from
"
src/components/AppStoreContext
"
;
import
{
Breakpoint
}
from
"
src/style
"
;
import
{
LayoutContext
}
from
"
../../layout/Layout
"
;
import
{
Loading
}
from
"
src/components/loading/Loading
"
;
import
{
NavigationComponentProps
}
from
"
../../navigation/Navigator
"
;
import
React
from
"
react
"
;
import
{
courseFromJSON
}
from
"
openfing-core/lib/factories
"
;
import
gql
from
"
graphql-tag
"
;
import
queryString
from
"
query-string
"
;
import
{
styles
}
from
"
./Course.styles
"
;
import
{
toJS
}
from
"
mobx
"
;
import
{
useDocumentTitle
}
from
"
../../components/useDocumentTitle
"
;
import
{
useFetchCourseByCode
}
from
"
openfing-core/lib/hooks/useFetchCourse
"
;
import
{
useHistory
}
from
"
src/hooks/useHistory
"
;
import
{
useQuery
}
from
"
react-apollo-hooks
"
;
import
{
useRootStore
}
from
"
openfing-core/lib/hooks/useRootStore
"
;
type
CourseData
=
{
courseByCode
:
{
id
:
number
;
code
:
string
;
name
?:
string
;
eva
?:
string
;
iconURL
?:
string
;
};
};
const
COURSE_QUERY
=
gql
`
query courseByCode($code: String!) {
courseByCode(code: $code) {
id
code
name
eva
semester
year
iconURL
classLists {
id
name
classes {
id
title
number
videos {
id
name
position
qualities {
id
height
width
formats {
id
name
url
}
}
}
}
}
}
}
`
;
// TODO: custom useQuery with parseData callback?
const
useForceUpdate
=
()
=>
{
const
[,
setB
]
=
React
.
useState
(
false
);
return
React
.
useCallback
(()
=>
{
setB
(
b
=>
!
b
);
},
[]);
};
export
const
Course
:
React
.
FunctionComponent
<
NavigationComponentProps
<
{
courseCode
:
string
}
>>
=
observer
(
props
=>
{
const
{
courseCode
}
=
props
.
match
.
params
;
const
forceUpdate
=
useForceUpdate
();
const
{
history
}
=
useHistory
();
const
queryParams
=
useMemo
<
{
t
?:
string
;
cci
?:
string
;
ccn
?:
string
;
ccl
?:
string
}
>
(
...
...
@@ -26,9 +89,20 @@ export const Course: React.FunctionComponent<NavigationComponentProps<{ courseCo
[
history
.
location
.
search
]
);
const
appStore
=
useContext
(
AppStoreContext
);
const
[
fetchCourseByCodeState
]
=
useFetchCourseByCode
({
courseCode
,
autoFetch
:
true
,
forceFetch
:
false
});
const
{
courseStore
}
=
useRootStore
();
const
course
=
courseStore
.
coursesByCode
.
get
(
courseCode
)
||
undefined
;
const
{
loading
,
data
,
...
rest
}
=
useQuery
<
CourseData
>
(
COURSE_QUERY
,
{
skip
:
!!
course
&&
!!
course
.
classLists
,
variables
:
{
code
:
courseCode
},
});
React
.
useEffect
(()
=>
{
if
(
!
data
||
!
data
.
courseByCode
)
return
;
courseStore
.
saveCourse
(
courseFromJSON
(
data
.
courseByCode
));
forceUpdate
();
},
[
data
]);
const
course
=
fetchCourseByCodeState
.
success
?
fetchCourseByCodeState
.
course
:
undefined
;
const
courseName
=
course
?
course
.
name
:
undefined
;
const
setLayoutOptions
=
useContext
(
LayoutContext
);
const
contextRef
=
React
.
useRef
<
CourseContext
>
();
...
...
@@ -65,11 +139,15 @@ export const Course: React.FunctionComponent<NavigationComponentProps<{ courseCo
if
(
!
current
)
return
;
current
.
fetchCourseByCodeState
=
fetchCourseByCodeState
;
current
.
fetchCourseByCodeState
=
loading
?
{
isLoading
:
loading
}
:
course
?
{
isLoading
:
false
,
success
:
true
,
course
}
:
{
isLoading
:
false
,
success
:
undefined
};
current
.
course
=
course
;
current
.
courseClassList
=
courseClassList
;
current
.
courseClass
=
courseClass
;
},
[
fetchCourseByCodeState
,
course
,
courseClassList
,
courseClass
]);
},
[
loading
,
course
,
courseClassList
,
courseClass
]);
useEffect
(()
=>
{
if
(
!
contextRef
.
current
)
return
;
...
...
@@ -99,8 +177,6 @@ export const Course: React.FunctionComponent<NavigationComponentProps<{ courseCo
);
return
(
<
CourseProvider
contextRef
=
{
contextRef
}
>
{
fetchCourseByCodeState
.
isLoading
?
<
Loading
/>
:
fetchCourseByCodeState
.
success
?
content
:
null
}
</
CourseProvider
>
<
CourseProvider
contextRef
=
{
contextRef
}
>
{
loading
?
<
Loading
/>
:
course
?
content
:
<
div
/>
}
</
CourseProvider
>
);
});
This diff is collapsed.
Click to expand it.
src/style/Mixins.ts
+
2
−
1
View file @
c427006f
import
darken
from
"
polished/lib/color/darken
"
;
import
{
FlattenSimpleInterpolation
,
css
}
from
"
styled-components
"
;
import
{
Breakpoint
}
from
"
./Breakpoint
"
;
import
darken
from
"
polished/lib/color/darken
"
;
export
const
EllipsisText
=
(
maxHeight
?:
string
)
=>
css
`
overflow: hidden;
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment