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

Make commits count as default for preview #255

Merged
merged 2 commits into from
Aug 17, 2023
Merged
Changes from all commits
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
31 changes: 20 additions & 11 deletions aiida-registry-app/src/Components/MainIndex.jsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useState } from 'react';
import { useState, useEffect } from 'react';
import { Link, Route, Routes } from 'react-router-dom';
import jsonData from '../plugins_metadata.json'
import base64Icon from '../base64Icon';
Expand All @@ -16,9 +16,24 @@ const length = Object.keys(plugins).length;
const currentPath = import.meta.env.VITE_PR_PREVIEW_PATH || "/aiida-registry/";

function MainIndex() {
const [sortOption, setSortOption] = useState('alpha');
const [sortOption, setSortOption] = useState('commits');
const [sortedData, setSortedData] = useState(plugins);
document.documentElement.style.scrollBehavior = 'auto';

useEffect(() => {
document.documentElement.style.scrollBehavior = 'auto';
setSortedData(sortByCommits(plugins));
setupScrollBehavior();
}, [plugins, setSortedData]);

function sortByCommits(plugins) {
const pluginsArray = Object.entries(plugins);

// Sort the array based on the commit_count value
pluginsArray.sort(([, pluginA], [, pluginB]) => pluginB.commits_count - pluginA.commits_count);

// Return a new object with the sorted entries
return Object.fromEntries(pluginsArray);
}

function setupScrollBehavior() {
var prevScrollpos = window.scrollY;
Expand All @@ -42,13 +57,7 @@ function MainIndex() {

let sortedPlugins;
if (option === 'commits') {
const pluginsArray = Object.entries(plugins);

// Sort the array based on the commit_count value
pluginsArray.sort(([, pluginA], [, pluginB]) => pluginB.commits_count - pluginA.commits_count);

// Create a new object with the sorted entries
sortedPlugins = Object.fromEntries(pluginsArray);
sortedPlugins = sortByCommits(plugins);
}
else if (option == 'alpha') {
sortedPlugins = plugins;
Expand Down Expand Up @@ -89,8 +98,8 @@ function MainIndex() {
<Select
value={sortOption} label = "Sort" onChange={(e) => handleSort(e.target.value)}
>
<MenuItem value= 'alpha'>Alphabetical</MenuItem>
<MenuItem value='commits'>Commits Count</MenuItem>
<MenuItem value= 'alpha'>Alphabetical</MenuItem>
</Select>
</FormControl>
</Box>
Expand Down