Skip to content

Instantly share code, notes, and snippets.

@gminero
Created March 8, 2019 03:56
Show Gist options
  • Save gminero/781c18f48239caafd6a01a4eb75986c8 to your computer and use it in GitHub Desktop.
Save gminero/781c18f48239caafd6a01a4eb75986c8 to your computer and use it in GitHub Desktop.
lex freeze when debugging
import { LightningElement, track } from 'lwc';
import ResourcesC from '@salesforce/resourceUrl/CoveoV2__searchUi';
import { loadScript, loadStyle } from 'lightning/platformResourceLoader';
/*
CoveoV2 resources can be found at
https://docs.coveo.com/en/319/javascript-search-framework/downloading-the-javascript-search-framework
OR http://productupdate.coveo.com/?product=coveo-search-ui
*/
const main_html = `<div id="search" class="CoveoSearchInterface" data-design="new" data-enable-history="false" data-auto-trigger-query='false'>
<div class="coveo-tab-section">
<a class="CoveoTab" data-id="All" data-caption="All Content"></a>
</div>
<div class="coveo-search-section">
<div class="CoveoSearchbox"></div>
<div class="coveo-main-section">
<div class="coveo-results-column">
<div class="CoveoResultList">
<script id="mySimpleResultTemplate" class="result-template" type="text/underscore">
<div class="CoveoResultLink"></div>
</script>
</div>
</div>
</div>
</div>`;
export default class HelloWorld extends LightningElement {
@track error;
@track stack;
coveoInitialized = false;
errorCallback(error) {
this.error = error;
console.log(this.error)
}
renderedCallback() {
if (this.coveoInitialized) {
return;
}
this.coveoInitialized = true;
console.log('rendering renderer')
// initialize component
Promise.all([
loadScript(this, ResourcesC + '/js/CoveoJsSearch.min.js'),
loadStyle(this, ResourcesC + '/css/CoveoFullSearchNewDesign.css'),
loadScript(this, ResourcesC + '/js/templates/templatesNew.js')
]).then(() => {
const container = this.template.querySelector('.container');
container.innerHTML = main_html;
this.initCoveo();
}).catch(error => {
console.log(error)
});
}
connectedCallback(){
console.log('connectedCallback');
}
initCoveo(){
console.log('initing coveo');
const cardTemplate = `<div class="coveo-result-frame">
<div class="coveo-result-row">
<div class="coveo-result-cell" style="padding-left:15px;">
<div class="coveo-result-row">
<div class="coveo-result-cell" style="font-size:18px;">
<a class="CoveoResultLink" >
</a>
</div>
</div>
</div>
</div>
<div class="coveo-result-row">
</div>
</div>`;
Coveo.TemplateCache.templates = {};
Coveo.TemplateCache.registerTemplate("card-default", Coveo.HtmlTemplate.fromString(cardTemplate,
{
"condition": null,
"layout": "card",
"mobile": null,
"role": null
}), true, true);
Coveo.SearchEndpoint.configureSampleEndpoint();
const root = this.template.querySelector(".CoveoSearchInterface");
Coveo.init(root);
}
}
<?xml version="1.0" encoding="UTF-8"?>
<LightningComponentBundle xmlns="http://soap.sforce.com/2006/04/metadata" fqn="helloWorld">
<apiVersion>45.0</apiVersion>
<isExposed>true</isExposed>
<targets>
<target>lightning__AppPage</target>
<target>lightning__RecordPage</target>
<target>lightning__HomePage</target>
<target>lightningCommunity__Page</target>
<target>lightningCommunity__Default</target>
</targets>
</LightningComponentBundle>
<template>
<div class="slds-m-around_medium">
<div class="container" lwc:dom="manual"></div>
</div>
</template>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment