-
Notifications
You must be signed in to change notification settings - Fork 363
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
fix the loading row remains even after the plugins are loaded #730
fix the loading row remains even after the plugins are loaded #730
Conversation
Welcome @zhengtianbao! |
Despite this fixes the issue I am inclined to think this is not the idiomatic way to address the issue. Do you know why render() doesn't replace contents of the table tag? Maybe there's an option to do that. |
@ahmeth because the render function actually creates DOM nodes and appends them to a DOM tree. In this case, the rendered DOM plugin-tables will append to
The option 3 code may like : <script type="module">
import {html, render} from 'https://unpkg.com/lit-html?module';
const repoLink = repo => repo
? html`<a href="${repo}" rel="nofollow"><img src="https://img.shields.io/github/stars/${repo}.svg?label=stars&logo=github"/></a>`
: html``;
const row = plugin => html`<tr>
<td><a rel="nofollow" href="${plugin.homepage}">${plugin.name}</a></td>
<td>${plugin.short_description}</td>
<td>${repoLink(plugin.github_repo)}</td>
</tr>`;
const tableRows = plugins => plugins.map(p => html`${row(p)}`);
const error = e => e
? html`<tr><td/><td>failed to load plugins: ${e}<td><td/></tr>`
: html`<tr><td/><td>failed to load plugins<td><td/></tr>`
// here add loading info by render
const pluginTableElem = document.querySelector("#krew-plugins-list");
const loading = html`<tr>
<td colspan="3">Loading...</td>
</tr>`
// render it first time
render(loading, pluginTableElem)
document.addEventListener('DOMContentLoaded', async () => {
if (!pluginTableElem){
return;
}
try {
const resp = await fetch('/.netlify/functions/api/plugins');
const json = await resp.json()
const plugins = json.data?.plugins;
if (!Boolean(plugins?.length)) {
render(error(), pluginTableElem);
return;
}
plugins.sort((a,b) => a.name.localeCompare(b.name));
render(tableRows(plugins), pluginTableElem);
} catch (e) {
render(error(e), pluginTableElem);
}
});
</script> If you agree with 3, I'll submit my code and pull request again, thank you for review. |
Understood. I think while (tableElem.firstChild) parent.removeChild(tableElem.firstChild); would that work? |
small side note: the import from |
Thanks and done. |
site/layouts/partials/footer.html
Outdated
while (pluginTableElem.firstChild) { | ||
pluginTableElem.removeChild(pluginTableElem.firstElementChild); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should be removing "Loading..." after there's a response? 😇
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sorry, my mistake, moved.
PTAL @ preview page https://6172131faa8d4d00086a9fac--kubernetes-sigs-krew.netlify.app/plugins/ It's failing. I think one of the words have a typo. |
/lgtm |
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: ahmetb, zhengtianbao The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
It's my first solved issue, thank you for your help and patience. |
Fixes #729 site: plugin list "Loading"... row never disappears
remove table tr element which shows "Loading..." before render plugin list table.