Skip to content

Commit 058dfd5

Browse files
Merge pull request #100 from MohamedAazil/feat/github-skills
feat: Implemented - Autofill skills using github
2 parents 63684b0 + 9d8db2a commit 058dfd5

3 files changed

Lines changed: 158 additions & 11 deletions

File tree

static/script.js

Lines changed: 70 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,12 @@
1515
var isIndexPage = !!document.getElementById("recommend-form");
1616
// PROJECT_ID is set by the server only on detail pages, so if it's missing we're elsewhere
1717
var isDetailPage = typeof PROJECT_ID !== "undefined";
18+
var modal = document.getElementById('github-modal-overlay');
19+
var openModalBtn = document.getElementById('btn-show-github'); // The trigger in your main form
20+
var closeModalBtn = document.getElementById('btn-close-github');
21+
var fetchBtn = document.getElementById('btn-fetch-github');
22+
var githubInput = document.getElementById('github-username');
23+
var errorMsg = document.getElementById('github-modal-error');
1824

1925

2026
// ============================================================
@@ -350,6 +356,9 @@ if (isIndexPage) {
350356
}
351357

352358
function syncSkillsHiddenInput() {
359+
if (!skillsHidden){
360+
var skillsHidden = document.getElementById("skills");
361+
}
353362
// Keep the hidden <input> in sync for form serialisation
354363
// The API expects a comma-separated string, so join the array that way
355364
skillsHidden.value = selectedSkills.join(", ");
@@ -715,6 +724,66 @@ if (isDetailPage) {
715724
}
716725
} // end isDetailPage
717726

727+
if (
728+
openModalBtn &&
729+
closeModalBtn &&
730+
modal &&
731+
githubInput &&
732+
fetchBtn &&
733+
errorMsg
734+
) {
735+
// 1. Open Github Input Modal
736+
openModalBtn.addEventListener('click', (e) => {
737+
e.preventDefault();
738+
modal.classList.add('active');
739+
githubInput.focus();
740+
});
741+
742+
// 2. Close Github Input Modal
743+
const closeGithubModal = () => {
744+
modal.classList.remove('active');
745+
githubInput.value = '';
746+
errorMsg.textContent = '';
747+
};
748+
749+
closeModalBtn.addEventListener('click', closeGithubModal);
750+
751+
// Close on clicking outside the card
752+
modal.addEventListener('click', (e) => {
753+
if (e.target === modal) closeGithubModal();
754+
});
755+
756+
// 3. Fetch Skills Logic
757+
fetchBtn.addEventListener('click', async () => {
758+
const username = githubInput.value.trim();
759+
if (!username) return;
760+
761+
fetchBtn.disabled = true;
762+
fetchBtn.textContent = 'Syncing...';
763+
764+
try {
765+
const response = await fetch(`https://api.github.com/users/${username}/repos`);
766+
if (!response.ok) throw new Error();
767+
768+
const repos = await response.json();
769+
const langs = [...new Set(repos.map(r => r.language).filter(Boolean))];
770+
771+
if (langs.length > 0) {
772+
langs.forEach(lang => {
773+
if (typeof addSkill === 'function') addSkill(lang);
774+
});
775+
closeGithubModal();
776+
} else {
777+
errorMsg.textContent = "No public languages found.";
778+
}
779+
} catch (err) {
780+
errorMsg.textContent = err.message ?? "Failed to fetch skills";
781+
} finally {
782+
fetchBtn.disabled = false;
783+
fetchBtn.textContent = 'Fetch Skills';
784+
}
785+
});
786+
}
718787

719788
/* ---- Scroll-to-top button ---- */
720789

@@ -743,4 +812,4 @@ function scrollToTop() {
743812
if (scrollTopBtn) {
744813
window.addEventListener('scroll', handleScroll);
745814
scrollTopBtn.addEventListener('click', scrollToTop);
746-
}
815+
}

static/style.css

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1831,6 +1831,49 @@ select:focus {
18311831
.section-sub { margin-bottom: 40px; }
18321832
}
18331833

1834+
.github-input-reveal input {
1835+
border: 1px solid var(--border);
1836+
border-radius: var(--r-xs);
1837+
font-family: var(--font-body);
1838+
}
1839+
1840+
.github-input-reveal input:focus {
1841+
border-color: var(--indigo-400);
1842+
outline: none;
1843+
background: var(--white);
1844+
}
1845+
1846+
#btn-show-github {
1847+
border: 1px solid transparent;
1848+
transition: all var(--t);
1849+
color: var(--indigo-600);
1850+
background: var(--indigo-50);
1851+
}
1852+
1853+
#btn-show-github:hover {
1854+
background: var(--indigo-100);
1855+
border-color: rgba(79, 110, 247, 0.2);
1856+
}
1857+
1858+
#github-modal-overlay.active {
1859+
display: flex !important; /* Overrides the 'none' display */
1860+
backdrop-filter: blur(4px);
1861+
animation: fadeIn 0.2s ease;
1862+
}
1863+
1864+
#github-modal-overlay .sidebar-card {
1865+
transform: scale(0.9);
1866+
transition: transform 0.2s cubic-bezier(0.34, 1.56, 0.64, 1);
1867+
}
1868+
1869+
#github-modal-overlay.active .sidebar-card {
1870+
transform: scale(1);
1871+
}
1872+
1873+
@keyframes fadeIn {
1874+
from { opacity: 0; }
1875+
to { opacity: 1; }
1876+
}
18341877

18351878
@media (max-width: 768px) {
18361879

templates/index.html

Lines changed: 45 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -337,16 +337,24 @@ <h2 class="section-title">Find Your Next Project</h2>
337337
<div class="form-card-outer">
338338
<div class="form-card" id="form-section">
339339
<form id="recommend-form" novalidate>
340-
341-
<!-- Skills input with chip selector -->
342340
<div class="form-group">
343-
<label for="skills-input">
344-
Your Skills
345-
<span class="tooltip"
346-
title="Add technologies, programming languages, or tools you know like Python, React, Git, SQL, etc.">
347-
348-
</span>
349-
</label>
341+
<div class="form-label-row" style="display: flex; justify-content: space-between; align-items: flex-end; margin-bottom: 8px;">
342+
<label for="skills-input">
343+
Your Skills
344+
<span class="tooltip"
345+
title="Add technologies, programming languages, or tools you know like Python, React, Git, SQL, etc.">
346+
347+
</span>
348+
</label>
349+
350+
<!-- Inline GitHub Trigger -->
351+
<div class="github-inline-trigger" id="github-trigger-wrap" style="line-height: 1.2;">
352+
<button type="button" id="btn-show-github" class="resource-link" style="padding: 4px 8px; border-radius: var(--r-xs); font-size: 0.75rem; gap: 6px;">
353+
<svg style="width:14px; fill:currentColor" viewBox="0 0 24 24"><path d="M12 0c-6.626 0-12 5.373-12 12 0 5.302 3.438 9.8 8.207 11.387.599.111.793-.261.793-.577v-2.234c-3.338.726-4.041-1.416-4.041-1.416-.546-1.387-1.333-1.756-1.333-1.756-1.089-.745.083-.729.083-.729 1.205.084 1.839 1.237 1.839 1.237 1.07 1.834 2.807 1.304 3.492.997.107-.775.418-1.305.762-1.604-2.665-.305-5.467-1.334-5.467-5.931 0-1.311.469-2.381 1.236-3.221-.124-.303-.535-1.524.117-3.176 0 0 1.008-.322 3.301 1.23.957-.266 1.983-.399 3.003-.404 1.02.005 2.047.138 3.006.404 2.291-1.552 3.297-1.23 3.297-1.23.653 1.653.242 2.874.118 3.176.77.84 1.235 1.911 1.235 3.221 0 4.609-2.807 5.624-5.479 5.921.43.372.823 1.102.823 2.222v3.293c0 .319.192.694.801.576 4.765-1.589 8.199-6.086 8.199-11.386 0-6.627-5.373-12-12-12z"/></svg>
354+
<span>Import from GitHub</span>
355+
</button>
356+
</div>
357+
</div>
350358
<div class="skill-input-wrap" id="skill-input-wrap">
351359
<div class="skill-chips-selected" id="skill-chips-selected"></div>
352360
<input type="text" id="skills-input" placeholder="Type a skill and press Enter..." autocomplete="off" />
@@ -598,7 +606,34 @@ <h4 class="footer-col-title">About Us</h4>
598606
</div>
599607
</footer>
600608

601-
<script src="/static/data/skills.js"></script>
609+
<!-- GitHub Modal Overlay -->
610+
<div class="code-panel-overlay" id="github-modal-overlay" style="align-items: center; justify-content: center; opacity: 1;">
611+
<div class="sidebar-card" style="width: 100%; max-width: 400px; margin: 20px; z-index: 400; box-shadow: 0 20px 50px rgba(0,0,0,0.3);">
612+
613+
<div class="sidebar-card-title">
614+
<svg style="width:18px; fill:var(--indigo-600)" viewBox="0 0 24 24"><path d="M12 0c-6.626 0-12 5.373-12 12 0 5.302 3.438 9.8 8.207 11.387.599.111.793-.261.793-.577v-2.234c-3.338.726-4.041-1.416-4.041-1.416-.546-1.387-1.333-1.756-1.333-1.756-1.089-.745.083-.729.083-.729 1.205.084 1.839 1.237 1.839 1.237 1.07 1.834 2.807 1.304 3.492.997.107-.775.418-1.305.762-1.604-2.665-.305-5.467-1.334-5.467-5.931 0-1.311.469-2.381 1.236-3.221-.124-.303-.535-1.524.117-3.176 0 0 1.008-.322 3.301 1.23.957-.266 1.983-.399 3.003-.404 1.02.005 2.047.138 3.006.404 2.291-1.552 3.297-1.23 3.297-1.23.653 1.653.242 2.874.118 3.176.77.84 1.235 1.911 1.235 3.221 0 4.609-2.807 5.624-5.479 5.921.43.372.823 1.102.823 2.222v3.293c0 .319.192.694.801.576 4.765-1.589 8.199-6.086 8.199-11.386 0-6.627-5.373-12-12-12z"/></svg>
615+
Sync with GitHub
616+
</div>
617+
618+
<p class="sidebar-card-desc" style="margin-bottom: 20px;">Enter your username to import coding languages from your top repositories into the skills list.<br/> Note: We use stars to determine top repositories</p>
619+
620+
<div class="form-group" style="margin-bottom: 20px;">
621+
<div class="skill-input-wrap">
622+
<span style="color:var(--gray-400); font-family:var(--font-mono); font-size:0.8rem; margin-left:8px;">@</span>
623+
<input type="text" id="github-username" placeholder="username" style="border:none; outline:none; flex:1; padding:10px;">
624+
</div>
625+
<div class="form-error-msg" id="github-modal-error"></div>
626+
</div>
627+
628+
<div style="display: flex; gap: 12px;">
629+
<button type="button" id="btn-fetch-github" class="btn-primary" style="flex: 2; padding: 10px; font-size: 0.85rem;">Fetch Skills</button>
630+
<button type="button" id="btn-close-github" class="btn-view-code-sm" style="flex: 1; border-color: var(--border); color: var(--text-body);">Cancel</button>
631+
</div>
632+
633+
</div>
634+
</div>
635+
636+
<script src="/static/data/skills.js"></script>
602637
<script src="/static/script.js"></script>
603638
</body>
604639

0 commit comments

Comments
 (0)