Skip to content

Commit

Permalink
Feat: Add event listener to handle dropdown template selection
Browse files Browse the repository at this point in the history
  • Loading branch information
KBandipo authored and Ifycode committed Nov 28, 2024
1 parent 161af83 commit cabbceb
Showing 1 changed file with 26 additions and 5 deletions.
31 changes: 26 additions & 5 deletions @dev-client/views/@plugin_githubsync/githubsync.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { getLastIndexOfCharaterInString } from '../@library_external/transform.j

const submitIssueForm = document.getElementById('submitIssueForm');
const displayToastrMessage = document.getElementById('displayToastrMessage');
const issueTemplatesDropdown = document.getElementById('issueTemplates');
const issueTemplatesDropdownSelect = document.getElementById('issueTemplates');
const issueBodyInput = document.getElementById('issueBody');
/* ----------------------------------
Submit an Issue ticket through UI
Expand Down Expand Up @@ -57,23 +57,44 @@ const fetchTemplates = async () => {
const templates = await response.json();
return templates.templates;
} catch (error) {
console.error('Error fetching templates:', error);
console.log('Error fetching templates:', error);
displayToastrMessage.innerHTML = 'Could not load issue templates.';
return;
return [];
}
};

const fetchTemplatesDropdown = async () => {
const templates = await fetchTemplates();
templates.forEach((template) => {
const option = document.createElement('option');
option.value = template.download.url;
option.value = template.download_url;
option.textContent = template.name.replace('.md', '').split('-').join(' ').replace(/^./, char => char.toUpperCase());
issueTemplatesDropdown.appendChild(option);
issueTemplatesDropdownSelect.appendChild(option);
});
};


issueTemplatesDropdownSelect.addEventListener('change', async (e) => {
const downloadUrl = e.target.value;

if (!downloadUrl) {
issueBodyInput.value = '';
return ;
}

try {
const response = await fetch(downloadUrl);
if (!response.ok) {
throw new Error(`Failed to fetch template content: ${response.statusText}`);
}
const content = await response.text();
issueBodyInput.value = content;
} catch (error) {
console.log('Error fetching template content:', error);
displayToastrMessage.innerHTML = 'Could not load selected template content.';
}
});

fetchTemplatesDropdown();


Expand Down

0 comments on commit cabbceb

Please sign in to comment.