Skip to content
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
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions components/Navbar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ function Navbar(): JSX.Element {
<Link href="/projects">
<a>projects</a>
</Link>
<Link href="/ucla-opensource">
<a>ucla-opensource</a>
</Link>
<Link href="/contribute">
<a>contribute</a>
</Link>
Expand Down
78 changes: 78 additions & 0 deletions pages/ucla-opensource.tsx
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.
Copy link
Member

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?

</p>
<hr />
<SearchFilter
projects={projects}
setFilteredProjects={setFilteredProjects}
/>
<hr/>
<div className="row same-height-grid">
Copy link
Member

Choose a reason for hiding this comment

The 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,
};
};
38 changes: 38 additions & 0 deletions util/projectRequest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similar comment to this pr!

Suggested change
const octokit = new PaginatedOctokit();
const octokit = new Octokit.plugin(paginateRest);

instead of

  const PaginatedOctokit = Octokit.plugin(paginateRest);
  const octokit = new PaginatedOctokit();

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) =>
Copy link
Member

Choose a reason for hiding this comment

The 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
return sortedData.map((repo) =>
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).image,
alt: getImageFromTopics(repo.topics).alt,
})

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,
Copy link
Member

Choose a reason for hiding this comment

The 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();
Expand Down Expand Up @@ -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',
Expand Down