From a2f36e1ce7d8f1f809a59d2aadd85a39dfb07f54 Mon Sep 17 00:00:00 2001 From: Alicia Sykes Date: Mon, 1 Apr 2024 23:39:57 +0100 Subject: [PATCH] Adds syntax highlighting to YAML snippet, and hides incomplete entries --- .../components/things/AddNewService.svelte | 59 ++++++++++++------- 1 file changed, 38 insertions(+), 21 deletions(-) diff --git a/web/src/components/things/AddNewService.svelte b/web/src/components/things/AddNewService.svelte index 35fb2c5..48c8cc8 100644 --- a/web/src/components/things/AddNewService.svelte +++ b/web/src/components/things/AddNewService.svelte @@ -19,6 +19,32 @@ const serviceSecurityAudited = writable(false); const serviceCrypto = writable(false); const additionalInfo = writable(''); + + let codeBlock: any; + let interactiveActivated = false; + + $: yamlText, updateHighlighting(); + + function updateHighlighting() { + if (codeBlock) { + codeBlock.textContent = yamlText + codeBlock.dataset.highlighted && delete codeBlock.dataset.highlighted; + if (window && (window as any).hljs) { + (window as any).hljs.highlightElement(codeBlock); + interactiveActivated = true; + } + } + } + + const filterEmptyValues = (obj: Record) => { + const filteredObj: Record = {}; + Object.keys(obj).forEach(key => { + if (obj[key] || ['name', 'url', 'icon', 'description'].includes(key)) { + filteredObj[key] = obj[key]; + } + }); + return filteredObj; + } $: yamlText = yaml.dump([{ name: $serviceName, @@ -34,7 +60,7 @@ openSource: $serviceOpenSource, securityAudited: $serviceSecurityAudited, acceptsCrypto: $serviceCrypto, - }]); + }].map(obj => filterEmptyValues(obj))); $: issueUrl = makeAdditionRequest({ listingCategory: $listingCategory, @@ -56,28 +82,16 @@ // Form submission handler function handleSubmit() { - const formData = { - listingCategory: $listingCategory, - serviceName: $serviceName, - serviceUrl: $serviceUrl, - serviceIcon: $serviceIcon, - serviceDescription: $serviceDescription, - serviceGithub: $serviceGithub, - serviceTosdrId: $serviceTosdrId, - serviceOpenSource: $serviceOpenSource, - serviceSecurityAudited: $serviceSecurityAudited, - serviceCrypto: $serviceCrypto, - additionalInfo: $additionalInfo, - serviceIosApp: $serviceIosApp, - serviceAndroidApp: $serviceAndroidApp, - serviceDiscordInvite: $serviceDiscordInvite, - serviceSubreddit: $serviceSubreddit, - }; - const issueCreationUrl = makeAdditionRequest(formData, yamlText); - window.open(issueCreationUrl, '_blank'); + window.open(issueUrl, '_blank'); } + + + + + +

Before completing this form, you must ensure that the service you are adding aligns with the Requirements for Awesome Privacy. @@ -278,7 +292,10 @@ within awesome-privacy.yml upon approval.

-
{@html yamlText}
+ {#if !interactiveActivated || !codeBlock} +
{@html yamlText}
+ {/if} +

Your submission will need to be reviewed by a maintainer and the community before it can be merged.