Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Khalid Ali
schedules
Commits
de1a4c32
Commit
de1a4c32
authored
May 12, 2018
by
Zac Wood
Browse files
Small refactors
parent
49b66f05
Changes
2
Hide whitespace changes
Inline
Side-by-side
schedules_web/src/components/App.tsx
View file @
de1a4c32
import
*
as
FileSaver
from
'
file-saver
'
;
import
*
as
React
from
'
react
'
;
import
Section
from
'
../section
'
;
import
{
ENDPOINTS
,
downloadCalendar
,
postData
}
from
'
../utilities
'
;
import
Search
from
'
./Search
'
;
import
SectionList
from
'
./SectionList
'
;
...
...
@@ -33,29 +33,19 @@ class App extends React.Component<any, State> {
addSectionToCurrentScheduleIfUnique
=
(
section
:
Section
)
=>
{
if
(
!
this
.
isSectionInSchedule
(
section
))
{
this
.
setState
({
currentSchedule
:
[...
this
.
state
.
currentSchedule
,
section
],
});
this
.
setState
({
currentSchedule
:
[...
this
.
state
.
currentSchedule
,
section
]
});
}
};
isSectionInSchedule
=
(
section
:
Section
)
=>
this
.
state
.
currentSchedule
.
find
(
sectionInSchedule
=>
section
==
=
sectionInSchedule
);
this
.
state
.
currentSchedule
.
find
(
sectionInSchedule
=>
section
==
sectionInSchedule
);
generateSchedule
=
()
=>
{
const
crns
=
this
.
state
.
currentSchedule
.
map
(
section
=>
section
.
crn
);
fetch
(
'
http://localhost:3000/api/generate
'
,
{
method
:
'
POST
'
,
body
:
JSON
.
stringify
(
crns
),
headers
:
{
'
Content-Type
'
:
'
application/json
'
,
},
})
postData
(
ENDPOINTS
.
generateCalendar
,
crns
)
.
then
(
response
=>
response
.
text
())
.
then
(
text
=>
{
const
blob
=
new
Blob
([
text
],
{
type
:
'
text/plain;charset=utf-8
'
});
FileSaver
.
saveAs
(
blob
,
'
GMU Fall 2018.ics
'
);
});
.
then
(
icalText
=>
downloadCalendar
(
icalText
));
};
removeFromSchedule
=
(
section
:
Section
)
=>
{
...
...
@@ -64,4 +54,5 @@ class App extends React.Component<any, State> {
});
};
}
export
default
App
;
schedules_web/src/utilities.ts
0 → 100644
View file @
de1a4c32
import
*
as
FileSaver
from
'
file-saver
'
;
export
const
ENDPOINTS
=
{
generateCalendar
:
'
http:localhost:3000/api/generate
'
,
};
export
function
postData
(
endpoint
:
string
,
data
:
any
):
Promise
<
Response
>
{
return
fetch
(
endpoint
,
{
method
:
'
POST
'
,
body
:
JSON
.
stringify
(
data
),
headers
:
{
'
Content-Type
'
:
'
application/json
'
,
},
});
}
export
function
downloadCalendar
(
calendarText
:
string
)
{
const
blob
=
new
Blob
([
calendarText
],
{
type
:
'
text/plain;charset=utf-8
'
});
FileSaver
.
saveAs
(
blob
,
'
GMU Fall 2018.ics
'
);
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment