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

Added Filter Progress #250

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
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
8 changes: 8 additions & 0 deletions locales/en_US.json
Original file line number Diff line number Diff line change
Expand Up @@ -391,5 +391,13 @@
"cancel": "Cancel",
"confirm": "Confirm",
"close": "Close"
},
"filter": {
"none": "All",
"wiiu": "Wii U",
"3ds": "3DS",
"web": "Web",
"game": "Game",
"service": "Service"
}
}
1 change: 1 addition & 0 deletions public/assets/css/main.css
Original file line number Diff line number Diff line change
Expand Up @@ -766,6 +766,7 @@ section.update-signup div.circle {
}

.feature-progress-chart {
width: 100px;
position: relative;
}
.feature-progress-chart p {
Expand Down
34 changes: 34 additions & 0 deletions public/assets/css/progress.css
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,38 @@ MOVE PROGRESS CSS HERE
#quick-nav a:hover {
color: var(--text-shade-3);
text-decoration: underline;
}

.progress-filter {
padding: 8px 72px;
border-radius: 10px;
background: var(--bg-shade-0);
grid-column: span 2;
}

.progress-filter .container {
display: grid;
grid-template-columns: repeat(6, 1fr);
grid-gap: 20px;
}

.progress-filter .container button {
padding: 0px;
}

.off {
display: none;
}

@media screen and (max-width: 900px) {

.progress-filter {
grid-column: span 1;
padding: 10px;
}

.progress-filter .container {
grid-template-columns: repeat(3, 1fr);
grid-template-rows: repeat(2, 1fr);
}
}
24 changes: 24 additions & 0 deletions public/assets/js/filter-progress.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
const progressCards = document.getElementsByClassName('purple-card')

function showWithFilter(filter){
for (const card of progressCards){
const type = card.getAttribute('type')
if (filter === "none" || type.toLowerCase().includes(filter)){
card.classList.remove('off')
}
else {
card.classList.add('off')
}
}
}

const buttons = document.getElementById('filter-container').children
let selectedButton = buttons[0]
for (const button of buttons){
button.addEventListener('click',(event) => {
selectedButton.classList.remove('primary')
selectedButton = event.target
selectedButton.classList.add('primary')
showWithFilter(event.target.id);
})
}
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
const progressCards = document.getElementsByClassName('purple-card')
function showWithFilter(filter){
for (const card of progressCards){
const type = card.getAttribute('type')
if (filter === "none" || type.toLowerCase().includes(filter)){
card.classList.remove('off')
}
else {
card.classList.add('off')
}
}
}
const buttons = document.getElementById('filter-container').children
let selectedButton = buttons[0]
for (const button of buttons){
button.addEventListener('click',(event) => {
selectedButton.classList.remove('primary')
selectedButton = event.target
selectedButton.classList.add('primary')
showWithFilter(event.target.id);
})
}
const progressCards = document.getElementsByClassName('purple-card');
function showWithFilter(filter) {
for (const card of progressCards) {
const type = card.getAttribute('type');
if (filter === "none" || type.toLowerCase().includes(filter)) {
card.classList.remove('off');
} else {
card.classList.add('off');
}
}
}
const buttons = document.getElementById('filter-container').children;
let selectedButton = buttons[0];
for (const button of buttons) {
button.addEventListener('click', (event) => {
selectedButton.classList.remove('primary');
selectedButton = event.target;
selectedButton.classList.add('primary');
showWithFilter(event.target.id);
})
}

Copy link
Member

Choose a reason for hiding this comment

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

I can't make multiple suggestions over the same lines in one review, but I would also prefer to not use the children property on filter-container. Instead using querySelectorAll targeting the buttons would be safer in the event that we need to restructure the HTML and not worry about updating the JS

88 changes: 87 additions & 1 deletion src/cache.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,25 @@ query getProjectsV2Fields($id: ID!, $cursor: String!) {
}
}
`;
const GetRepositoryDescription = gql`
query GetRepositoryDescription($orgName: String!, $repoName: String!){
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
const GetRepositoryDescription = gql`
query GetRepositoryDescription($orgName: String!, $repoName: String!){
const getRepositoryDescription = gql`
query getRepositoryDescription($orgName: String!, $repoName: String!){

repository(owner: $orgName, name: $repoName) {
description
main: object(expression: "main:README.md") {
... on Blob {
text
}
}
master: object(expression: "master:README.md") {
... on Blob {
text
}
}
Copy link
Member

Choose a reason for hiding this comment

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

You don't have to do this in 2 steps. Target HEAD rather than a branch and it gives you the repositories default branch

Suggested change
main: object(expression: "main:README.md") {
... on Blob {
text
}
}
master: object(expression: "master:README.md") {
... on Blob {
text
}
}
readme: object(expression: "HEAD:README.md") {
... on Blob {
text
}
}

}
}
`; //Loophole to get the ReadMe No Matter the branch name
Copy link
Member

Choose a reason for hiding this comment

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

The website is behind on this, but we've been moving to the comment format made by better comments

Suggested change
`; //Loophole to get the ReadMe No Matter the branch name
`; // * Loophole to get the ReadMe No Matter the branch name


const serviceApps = ["account","nex","friends","wii u chat", "juxt", "website"]
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
const serviceApps = ["account","nex","friends","wii u chat", "juxt", "website"]
const serviceApps = ["account", "nex", "friends", "wii u chat", "juxt", "website"];

This could also probably go on multiple lines, but I won't require it


let githubProjectsCache = {
update_time: 0,
Expand Down Expand Up @@ -133,6 +152,69 @@ async function getGitHubProjectsV2Fields(id, after='') {
return fields;
}

async function getRepoType(name, title){
const data = await github.request(GetRepositoryDescription, {
orgName: 'PretendoNetwork',
repoName: name
})
let readMe = ""
if (data.repository.main != null)
readMe = data.repository.main.text
else
readMe = data.repository.master.text

readMe = readMe.split('\n')[0].toLowerCase()
let description = data.repository.description
if (description != null)
description = description.toLowerCase()
else
description = ""
return await setRepoType(title.toLowerCase(),description,readMe)
}


async function setRepoType(title, description, readMe){
let types = []
let isGame = true
for (let app of serviceApps)
if (title.includes(app)){
types.push("Service")
isGame = false
break
}

if (isGame) {
types.push("Game")
}

if (title.includes('(') && isGame){
if (title.includes('3ds'))
types.push("3DS")
else
types.push("Wii U")
return types
}


if (title === 'nex' || title.includes('juxt') || title.includes('account')){
types.push('3DS')
types.push('Wii U')
if (title.includes('juxt'))
types.push("Website")
}
else if (title.includes('web')){
types.push("Website")
}
else if (description.includes('3ds') || readMe.includes('3ds') || title.includes('3ds')){
types.push('3DS')
}
else{
types.push('Wii U')
}

return types
}
Copy link
Member

@jonbarrow jonbarrow Feb 20, 2024

Choose a reason for hiding this comment

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

Suggested change
async function getRepoType(name, title){
const data = await github.request(GetRepositoryDescription, {
orgName: 'PretendoNetwork',
repoName: name
})
let readMe = ""
if (data.repository.main != null)
readMe = data.repository.main.text
else
readMe = data.repository.master.text
readMe = readMe.split('\n')[0].toLowerCase()
let description = data.repository.description
if (description != null)
description = description.toLowerCase()
else
description = ""
return await setRepoType(title.toLowerCase(),description,readMe)
}
async function setRepoType(title, description, readMe){
let types = []
let isGame = true
for (let app of serviceApps)
if (title.includes(app)){
types.push("Service")
isGame = false
break
}
if (isGame) {
types.push("Game")
}
if (title.includes('(') && isGame){
if (title.includes('3ds'))
types.push("3DS")
else
types.push("Wii U")
return types
}
if (title === 'nex' || title.includes('juxt') || title.includes('account')){
types.push('3DS')
types.push('Wii U')
if (title.includes('juxt'))
types.push("Website")
}
else if (title.includes('web')){
types.push("Website")
}
else if (description.includes('3ds') || readMe.includes('3ds') || title.includes('3ds')){
types.push('3DS')
}
else{
types.push('Wii U')
}
return types
}
async function getRepoType(name, title) {
const data = await github.request(getRepositoryDescription, {
orgName: 'PretendoNetwork',
repoName: name
});
const readme = data.repository.readme.text.split('\n')[0].toLowerCase();
const description = data.repository.description?.toLowerCase() || '';
return setRepoType(title.toLowerCase(), description, readme);
}
function setRepoType(title, description, readMe) {
const types = [];
let isGame = true;
for (const app of serviceApps) {
if (title.includes(app)) {
types.push('Service');
isGame = false;
break;
}
}
if (isGame) {
types.push('Game');
}
if (title.includes('(') && isGame) {
if (title.includes('3ds')) {
types.push('3DS');
} else {
types.push('Wii U');
}
return types;
}
if (title === 'nex' || title.includes('juxt') || title.includes('account')) {
types.push('3DS');
types.push('Wii U');
if (title.includes('juxt')) {
types.push('Website');
}
} else if (title.includes('web')) {
types.push('Website');
} else if (description.includes('3ds') || readMe.includes('3ds') || title.includes('3ds')) {
types.push('3DS');
} else {
types.push('Wii U');
}
return types;
}


async function getGithubProjectsCache() {
if (githubCacheBeingFetched) {
return githubProjectsCache;
Expand Down Expand Up @@ -172,7 +254,8 @@ async function updateGithubProjectsCache() {
done: [],
in_progress: [],
todo: []
}
},
type: []
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
type: []
types: []

};

const fields = await getGitHubProjectsV2Fields(project.id);
Expand All @@ -181,6 +264,9 @@ async function updateGithubProjectsCache() {
extractedData.cards[field.column.toLowerCase().replace(' ', '_')]?.push(field.title);
}

const types = await getRepoType(project.url.split("/")[4], project.title)
extractedData.type = types
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
const types = await getRepoType(project.url.split("/")[4], project.title)
extractedData.type = types
extractedData.types = await getRepoType(project.url.split("/")[4], project.title);

Or just set this directly on the object rather than reassigning it here


projectsCacheData.sections.push(extractedData);
}

Expand Down
24 changes: 12 additions & 12 deletions views/progress.handlebars
Original file line number Diff line number Diff line change
Expand Up @@ -24,24 +24,24 @@
<p class="localeReplace">{{{ locale.donation.progress }}} {{{ locale.donation.upgradePush }}}</p>
</div>

<div id="quick-nav">
<h1 class="title dot">Quick Nav</h1>
<ul>
{{#each progressLists.sections}}
<li>
<a href="#{{slug this.title}}">{{this.title}}</a>
</li>
{{/each}}
</ul>
<div class="progress-filter">
<div class="container" id="filter-container">
<button class="filter primary" id="none"> {{locale.filter.none}} </button>
<button class="filter" id="wii u"> {{locale.filter.wiiu}} </button>
<button class="filter" id="3ds"> {{locale.filter.3ds}} </button>
<button class="filter" id="web"> {{locale.filter.web}} </button>
<button class="filter" id="game"> {{locale.filter.game}} </button>
<button class="filter" id="service"> {{locale.filter.service}} </button>
</div>
</div>
<br>

{{#each progressLists.sections}}
<div class="purple-card" id="{{slug this.title}}">
<div class="purple-card" id="{{slug this.title}}" type="{{this.type}}">
{{> progress-list data=this }}
</div>
{{/each}}
</div>

<script src="/assets/js/filter-progress.js"></script>
{{> footer }}

</div>
Expand Down