-
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
Open
Amyh11325
wants to merge
3
commits into
main
Choose a base branch
from
uclaOpenSourceTopic
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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,27 @@ | ||
import React from 'react'; | ||
import ProjectCard from '../components/ProjectCard'; | ||
import {Project, GitHubColors} from '../util'; | ||
|
||
export interface ProjectsProps { | ||
projects: Project[]; | ||
githubColors: GitHubColors | ||
} | ||
|
||
function ProjectGrid({projects, githubColors}: ProjectsProps): JSX.Element { | ||
return ( | ||
<div className="row same-height-grid"> | ||
{projects.length > 0 | ||
? projects.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> | ||
); | ||
} | ||
|
||
export default ProjectGrid; |
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,67 @@ | ||
import { GetStaticProps } from 'next'; | ||
import { NextSeo } from 'next-seo'; | ||
import React, { useState } from 'react'; | ||
import Layout from '../components/Layout'; | ||
import ProjectGrid from '../components/ProjectGrid'; | ||
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/> | ||
<ProjectGrid projects={filteredProjects} githubColors = {githubColors}/> | ||
</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, | ||
}; | ||
}; |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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 | ||||
---|---|---|---|---|---|---|
@@ -1,44 +1,43 @@ | ||||||
import { Octokit } from '@octokit/core'; | ||||||
import { paginateRest } from '@octokit/plugin-paginate-rest'; | ||||||
// import {EndpointOptions} from '@octokit/types'; | ||||||
import githubColorsFixture from '../data/githubColors.json'; | ||||||
import { Project, ACMCommitteeTopics, GitHubColors } from './types'; | ||||||
import { Project, ACMCommitteeTopics, GitHubColors, GitHubRepo } from './types'; | ||||||
|
||||||
export async function getProjects(): Promise<Project[]> { | ||||||
async function getGithubRepos(request: string, defaultUseUclaLogo: boolean): 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 projectsResponse = await octokit.paginate('GET /orgs/{org}/repos', { | ||||||
org: 'uclaacm', | ||||||
|
||||||
const response: GitHubRepo[] = await octokit.paginate('GET /search/repositories?q=ucla-opensource+in:topics', { | ||||||
per_page: 100, | ||||||
}); | ||||||
|
||||||
const filteredData = projectsResponse.filter((repo) => !repo.archived); | ||||||
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) => | ||||||
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, | ||||||
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, | ||||||
}, | ||||||
return sortedData.map((repo) => ({ | ||||||
name: repo.name, | ||||||
description: repo.description ?? '', | ||||||
link: repo.homepage ?? '', | ||||||
repo: repo.html_url, | ||||||
lang: repo.language ?? '', | ||||||
topics: repo.topics ?? [], | ||||||
image: getImageFromTopics(repo.topics, defaultUseUclaLogo).image, | ||||||
alt: getImageFromTopics(repo.topics, defaultUseUclaLogo).alt, | ||||||
}), | ||||||
); | ||||||
} | ||||||
|
||||||
export async function getUclaOpenSource(): Promise<Project[]> { | ||||||
return getGithubRepos('GET /search/repositories?q=ucla-opensource+in:topics', true); | ||||||
} | ||||||
|
||||||
export async function getProjects(): Promise<Project[]> { | ||||||
return getGithubRepos('GET /orgs/uclaacm/repos', false); | ||||||
} | ||||||
|
||||||
export async function getGithubColors(): Promise<GitHubColors> { | ||||||
const githubColorsResponse = await fetch( | ||||||
'https://raw.githubusercontent.com/ozh/github-colors/master/colors.json', | ||||||
|
@@ -100,16 +99,19 @@ function topicToImg(topic: string): ImageInfo | false { | |||||
} | ||||||
} | ||||||
|
||||||
export function getImageFromTopics(topics: string[] | undefined): ImageInfo { | ||||||
export function getImageFromTopics(topics: string[] | undefined, defaultUseUclaLogo: boolean): ImageInfo { | ||||||
if (topics) { | ||||||
for (const topic of topics) { | ||||||
const committeeImg = topicToImg(topic); | ||||||
if (committeeImg) return committeeImg; | ||||||
} | ||||||
} | ||||||
//return acm logo if no committee topics | ||||||
return { | ||||||
image: '/logo.png', | ||||||
alt: "ACM @ UCLA's Logo", | ||||||
} as ImageInfo; | ||||||
return defaultUseUclaLogo ? { | ||||||
image: '/ucla-logo.jpeg', | ||||||
alt: 'UCLA Bruin Logo'} | ||||||
: { | ||||||
image: '/logo.png', | ||||||
alt: "ACM @ UCLA's Logo", | ||||||
}; | ||||||
} |
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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?