-
Notifications
You must be signed in to change notification settings - Fork 6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add ucla-opensource page #125
base: main
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
import { GetStaticProps } from 'next'; | ||
import { NextSeo } from 'next-seo'; | ||
import React, { useState } from 'react'; | ||
import Layout from '../components/Layout'; | ||
import ProjectCard from '../components/ProjectCard'; | ||
import SearchFilter from '../components/SearchFilter/SearchFilter'; | ||
import { getUclaOpenSource, Project, GitHubColors, getGithubColors } from '../util'; | ||
|
||
|
||
interface ProjectsProps { | ||
projects: Project[]; | ||
githubColors: GitHubColors | ||
} | ||
|
||
function Projects({ projects, githubColors }: ProjectsProps): JSX.Element { | ||
|
||
// projects is a master list of all the projects that we fetched, filteredProjects is the one that we render | ||
// to the user | ||
const [filteredProjects, setFilteredProjects] = useState(projects); | ||
|
||
return ( | ||
<Layout> | ||
<div className="container"> | ||
<NextSeo | ||
title="ucla-opensource | open source at UCLA" | ||
description="a heads-up overview of open source projects at UCLA" | ||
openGraph={{ | ||
images: [{ | ||
url: 'https://opensource.uclaacm.com/logo.png', | ||
width: 1200, | ||
height: 1200, | ||
alt: 'The ACM at UCLA logo', | ||
}], | ||
site_name: 'open source at UCLA', | ||
}} | ||
/> | ||
<h1> | ||
ucla-opensource | ||
</h1> | ||
<p> | ||
a (work-in-progress) heads-up overview of open source projects at UCLA. | ||
</p> | ||
<hr /> | ||
<SearchFilter | ||
projects={projects} | ||
setFilteredProjects={setFilteredProjects} | ||
/> | ||
<hr/> | ||
<div className="row same-height-grid"> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This grid of projects is pretty much exactly the same as the projects page. Maybe we can export the grid as a React component which takes in an array of projects and shows them on the screen? That way, if we want to edit the layout of the ucla-opensource page or the projects page, it'll be easier to handle the differences between them! |
||
{filteredProjects.length > 0 | ||
? filteredProjects.map((project, i) => { | ||
return ( | ||
<div className="col-4" key={project.name}> | ||
<ProjectCard project={project} vertical preload={i < 3} githubColors={githubColors} /> | ||
</div> | ||
); | ||
}) | ||
: <h2>No results found</h2> | ||
} | ||
</div> | ||
</div> | ||
</Layout> | ||
); | ||
} | ||
|
||
export default Projects; | ||
|
||
export const getStaticProps: GetStaticProps<ProjectsProps> = async () => { | ||
const projects = await getUclaOpenSource(); | ||
const githubColors = await getGithubColors(); | ||
return { | ||
props: { | ||
projects, | ||
githubColors: githubColors, | ||
}, | ||
revalidate: 3600, | ||
}; | ||
}; |
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -3,6 +3,43 @@ import { paginateRest } from '@octokit/plugin-paginate-rest'; | |||||||||||||||||||||||
import githubColorsFixture from '../data/githubColors.json'; | ||||||||||||||||||||||||
import { Project, ACMCommitteeTopics, GitHubColors } from './types'; | ||||||||||||||||||||||||
|
||||||||||||||||||||||||
export async function getUclaOpenSource(): Promise<Project[]> { | ||||||||||||||||||||||||
const PaginatedOctokit = Octokit.plugin(paginateRest); | ||||||||||||||||||||||||
const octokit = new PaginatedOctokit(); | ||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Similar comment to this pr!
Suggested change
instead of
|
||||||||||||||||||||||||
const response = await octokit.paginate('GET /search/repositories', { | ||||||||||||||||||||||||
q: 'ucla-opensource+in:topics', | ||||||||||||||||||||||||
per_page: 100, | ||||||||||||||||||||||||
}); | ||||||||||||||||||||||||
|
||||||||||||||||||||||||
const filteredData = response.filter((repo) => !repo.archived); | ||||||||||||||||||||||||
const sortedData = filteredData.sort( | ||||||||||||||||||||||||
(a, b) => | ||||||||||||||||||||||||
new Date(b.updated_at as string).getTime() - new Date(a.updated_at as string).getTime(), | ||||||||||||||||||||||||
); | ||||||||||||||||||||||||
return sortedData.map((repo) => | ||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Similar issue to this pr! This entire function can be replaced by
Suggested change
|
||||||||||||||||||||||||
repo.homepage | ||||||||||||||||||||||||
? { | ||||||||||||||||||||||||
name: repo.name, | ||||||||||||||||||||||||
description: repo.description ?? '', | ||||||||||||||||||||||||
link: repo.homepage ?? '', | ||||||||||||||||||||||||
repo: repo.html_url, | ||||||||||||||||||||||||
lang: repo.language ?? '', | ||||||||||||||||||||||||
topics: repo.topics ?? [], | ||||||||||||||||||||||||
image: getImageFromTopics(repo.topics).image, | ||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For our placeholder image, maybe we can use the UCLA logo instead of the ACM logo as these are projects by UCLA students? down the line, we can do stuff like grabbing the social media preview image for each project and displaying that, but that can be a stretch goal for later |
||||||||||||||||||||||||
alt: getImageFromTopics(repo.topics).alt, | ||||||||||||||||||||||||
} | ||||||||||||||||||||||||
: { | ||||||||||||||||||||||||
name: repo.name, | ||||||||||||||||||||||||
description: repo.description ?? '', | ||||||||||||||||||||||||
repo: repo.html_url ?? '', | ||||||||||||||||||||||||
lang: repo.language ?? '', | ||||||||||||||||||||||||
topics: repo.topics ?? [], | ||||||||||||||||||||||||
image: getImageFromTopics(repo.topics).image, | ||||||||||||||||||||||||
alt: getImageFromTopics(repo.topics).alt, | ||||||||||||||||||||||||
}, | ||||||||||||||||||||||||
); | ||||||||||||||||||||||||
} | ||||||||||||||||||||||||
|
||||||||||||||||||||||||
export async function getProjects(): Promise<Project[]> { | ||||||||||||||||||||||||
const PaginatedOctokit = Octokit.plugin(paginateRest); | ||||||||||||||||||||||||
const octokit = new PaginatedOctokit(); | ||||||||||||||||||||||||
|
@@ -39,6 +76,7 @@ export async function getProjects(): Promise<Project[]> { | |||||||||||||||||||||||
}, | ||||||||||||||||||||||||
); | ||||||||||||||||||||||||
} | ||||||||||||||||||||||||
|
||||||||||||||||||||||||
export async function getGithubColors(): Promise<GitHubColors> { | ||||||||||||||||||||||||
const githubColorsResponse = await fetch( | ||||||||||||||||||||||||
'https://raw.githubusercontent.com/ozh/github-colors/master/colors.json', | ||||||||||||||||||||||||
|
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.
maybe call it a collection of open source projects at UCLA instead of an overview?