-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
307 additions
and
87 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,6 +17,7 @@ | |
|
||
# misc | ||
.DS_Store | ||
.idea | ||
|
||
# debug | ||
npm-debug.log* | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { AxiosResponse } from "axios"; | ||
|
||
function isStatusOK(status: number) { | ||
return status >= 200 && status < 300; | ||
} | ||
|
||
export function checkStatusOK(resp: AxiosResponse) { | ||
if (!isStatusOK(resp.status)) { | ||
throw new Error(JSON.stringify(resp.data)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import React from "react"; | ||
import ContentLoader from "react-content-loader"; | ||
|
||
const Default = (props) => ( | ||
<ContentLoader | ||
speed={2} | ||
width={800} | ||
height={100} | ||
viewBox="0 0 800 100" | ||
backgroundColor="#f3f3f3" | ||
foregroundColor="#ecebeb" | ||
{...props} | ||
> | ||
<rect x="0" y="0" rx="3" ry="3" width="67" height="11" /> | ||
<rect x="76" y="0" rx="3" ry="3" width="140" height="11" /> | ||
<rect x="127" y="48" rx="3" ry="3" width="53" height="11" /> | ||
<rect x="187" y="48" rx="3" ry="3" width="72" height="11" /> | ||
<rect x="18" y="48" rx="3" ry="3" width="100" height="11" /> | ||
<rect x="0" y="71" rx="3" ry="3" width="37" height="11" /> | ||
<rect x="18" y="23" rx="3" ry="3" width="140" height="11" /> | ||
<rect x="166" y="23" rx="3" ry="3" width="173" height="11" /> | ||
</ContentLoader> | ||
); | ||
|
||
type Props = { | ||
[prop: string]: any; | ||
}; | ||
|
||
const Loader: React.FC<Props> = ({ ...props }) => { | ||
return <Default {...props} />; | ||
}; | ||
|
||
export default Loader; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import _ from "lodash"; | ||
import Link from "next/link"; | ||
import useSWR from "swr"; | ||
import { Box } from "@chakra-ui/react"; | ||
import { getFileGroups } from "uploadcare-api"; | ||
import ErrorView from "./ErrorView"; | ||
import Loader from "./Loader"; | ||
|
||
const UploadcareFileGroups = ({ apiConfig }) => { | ||
const { data, error } = useSWR("/uc/file-groups", () => | ||
getFileGroups(apiConfig) | ||
); | ||
return ( | ||
<> | ||
<ErrorView error={error} /> | ||
{!error && !data && <Loader />} | ||
{!error && data && _.isEmpty(data) ? ( | ||
<Box m={3}>You don't have file groups yet.</Box> | ||
) : null} | ||
{_.map(data?.results, (item, k) => { | ||
const id = item.id.replace("~1", ""); | ||
return ( | ||
<Box key={k}> | ||
<Link href={`/course/uploadcare/${id}`}> | ||
{item.title || id} | ||
</Link> | ||
</Box> | ||
); | ||
})} | ||
</> | ||
); | ||
}; | ||
|
||
export default UploadcareFileGroups; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import _ from "lodash"; | ||
import Link from "next/link"; | ||
import { Box } from "@chakra-ui/react"; | ||
import useSWR from "swr"; | ||
import { getPlaylists } from "youtube-api"; | ||
import { useAccessToken } from "components/GoogleAuth"; | ||
import ErrorView from "./ErrorView"; | ||
import Loader from "./Loader"; | ||
|
||
const YouTubePlaylists = () => { | ||
const accessToken = useAccessToken(); | ||
const { data, error } = useSWR( | ||
`/playlists?token=${accessToken}`, | ||
async () => { | ||
if (!accessToken) { | ||
return []; | ||
} | ||
const resp = await getPlaylists({ | ||
accessToken, | ||
}); | ||
return resp.items.map((t) => ({ | ||
id: t.id, | ||
title: t.snippet.title, | ||
description: t.snippet.description, | ||
})); | ||
} | ||
); | ||
return ( | ||
<> | ||
<ErrorView error={error} /> | ||
{!error && !data && <Loader />} | ||
{!error && data && _.isEmpty(data) ? ( | ||
<Box m={3}> | ||
No data. Please login into your google account to view your video | ||
courses | ||
</Box> | ||
) : null} | ||
{_.map(data, (item, k) => ( | ||
<Box key={k}> | ||
<Link href={`/course/youtube/${item.id}`}>{item.title}</Link> | ||
</Box> | ||
))} | ||
</> | ||
); | ||
}; | ||
|
||
export default YouTubePlaylists; |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import _ from "lodash"; | ||
import { useRouter } from "next/router"; | ||
import CourseView from "components/CourseView"; | ||
import ErrorView from "components/ErrorView"; | ||
import Page from "components/Layout"; | ||
import useSWR from "swr"; | ||
import { getFileGroup } from "uploadcare-api"; | ||
import { Course } from "types"; | ||
|
||
export async function getStaticPaths() { | ||
return { | ||
paths: ["/course/uploadcare/1"], | ||
fallback: true, | ||
}; | ||
} | ||
|
||
export async function getStaticProps() { | ||
return { | ||
props: { | ||
uploadcare: { | ||
publicKey: process.env.UC_PUBLIC_KEY, | ||
secretKey: process.env.UC_SECRET_KEY, | ||
}, | ||
}, | ||
}; | ||
} | ||
|
||
export default function CoursePage({ uploadcare }) { | ||
const router = useRouter(); | ||
const { id } = router.query; | ||
const { data, error } = useSWR(`/uploadcare/file-group/${id}`, async () => { | ||
const grp = await getFileGroup(String(id), uploadcare); | ||
return { | ||
title: grp.title || grp.id, | ||
description: grp.description || "", | ||
lessons: _.map(grp.items, (t) => ({ | ||
title: t.snippet.title, | ||
description: t.snippet.description, | ||
duration: 5, | ||
youtubeVideoId: t.contentDetails.videoId, | ||
})), | ||
} as Course; | ||
}); | ||
|
||
return ( | ||
<Page> | ||
<ErrorView error={error} /> | ||
{data ? <CourseView data={data} /> : null} | ||
</Page> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import _ from "lodash"; | ||
import { useRouter } from "next/router"; | ||
import CourseView from "components/CourseView"; | ||
import { useAccessToken } from "components/GoogleAuth"; | ||
import ErrorView from "components/ErrorView"; | ||
import Page from "components/Layout"; | ||
import useSWR from "swr"; | ||
import { getPlaylistItems, getPlaylists } from "youtube-api"; | ||
import { Course } from "types"; | ||
|
||
export default function CoursePage() { | ||
const router = useRouter(); | ||
const { pid } = router.query; | ||
const accessToken = useAccessToken(); | ||
const { data, error } = useSWR( | ||
`/youtube/course?token=${accessToken}`, | ||
async () => { | ||
if (!accessToken) { | ||
throw new Error("no access token"); | ||
} | ||
// TODO get playlist by id | ||
const list = await getPlaylists({ accessToken }); | ||
const playlist = _.find(list.items, (t) => t.id === pid); | ||
const resp = await getPlaylistItems({ | ||
playlistId: String(pid), | ||
accessToken, | ||
}); | ||
return { | ||
title: playlist?.snippet?.title || "", | ||
description: playlist?.snippet?.description || "", | ||
lessons: resp.items.map((t) => ({ | ||
title: t.snippet.title, | ||
description: t.snippet.description, | ||
duration: 5, | ||
youtubeVideoId: t.contentDetails.videoId, | ||
})), | ||
} as Course; | ||
} | ||
); | ||
|
||
return ( | ||
<Page> | ||
<ErrorView error={error} /> | ||
{data ? <CourseView data={data} /> : null} | ||
</Page> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
71a4a42
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs: