diff --git a/public/data.json b/public/data.json index 6e23b47..6baa7e0 100644 --- a/public/data.json +++ b/public/data.json @@ -111,7 +111,7 @@ }, { "id": 15, - "title": "Pull request body generation in WebUI", + "title": "PR body generation in WebUI", "videoUrl": "", "description": "Automatically generate detailed pull request bodies with Copilot in the webUI.", "ghes_support": false diff --git a/src/pages/Skus.jsx b/src/pages/Skus.jsx index eaab1bf..4af3aa5 100644 --- a/src/pages/Skus.jsx +++ b/src/pages/Skus.jsx @@ -1,34 +1,57 @@ -import React, { useEffect, useState } from 'react'; +import React, { useEffect, useState, Component } from 'react'; import { useNavigate } from 'react-router-dom'; import '../styles.css'; import getData from '../utils/getData'; import Header from './title-header'; const Skus = () => { - const [features, setFeatures] = useState({ business: [], enterprise: [] }); + const [features, setFeatures] = useState({ business: [], enterprise: [], ghesFiltered: true }); const navigate = useNavigate(); - const isOn = false; const handleClick = (id) => { // navigate to the video with the given id navigate(`/detail?videoId=${id}`); }; - const handleGHESToggle = () => { - // hide the videos that do not have the ghes_support tag - const ghesToggle = document.getElementById('ghes-toggle'); - const ghesSupport = document.getElementsByClassName('ghes-support'); + const getElementByKey = (key) => { + const element = document.querySelector(`[data-key="${key}"]`); + return element; + } - if (ghesToggle.checked) { - for (let i = 0; i < ghesSupport.length; i++) { - ghesSupport[i].style.display = 'block'; + const toggleFeature = (item, style) => { + if (!item.ghes_support) { + const feature = getElementByKey(item.id); + if (feature) { + feature.style.display = style; } } + } + + const handleGHESToggle = () => { + // show/hide the videos that do not have the ghes_support tag + if (features.ghesFiltered) { + features.ghesFiltered = false; + features.business.forEach(item => { + toggleFeature(item, 'block'); + }); + + features.enterprise.forEach(item => { + toggleFeature(item, 'block'); + }); + + document.getElementById('ghesToggle').classList.remove('on'); + } else { - for (let i = 0; i < ghesSupport.length; i++) { - ghesSupport[i].style.display = 'none'; - } + features.ghesFiltered = true; + features.business.forEach(item => { + toggleFeature(item, 'none'); + }); + + features.enterprise.forEach(item => { + toggleFeature(item, 'none'); + }); + document.getElementById('ghesToggle').classList.add('on'); } } @@ -37,7 +60,8 @@ const Skus = () => { .then(data => { const business = data.features.videos.find(feature => feature.sku === "GitHub Copilot Business"); const enterprise = data.features.videos.find(feature => feature.sku === "GitHub Copilot Enterprise"); - setFeatures({ business: business.items, enterprise: enterprise.items }); + setFeatures({ business: business.items, enterprise: enterprise.items, ghesFiltered: false }); + handleGHESToggle(); }) .catch(error => console.error('Error loading SKU data:', error)); }, []); @@ -45,9 +69,12 @@ const Skus = () => { return (