Skip to content

Commit

Permalink
Fixes for the new Lexical editor
Browse files Browse the repository at this point in the history
  • Loading branch information
ktecho committed Feb 2, 2024
1 parent 3d8e646 commit 3c48fd6
Showing 1 changed file with 52 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,58 +25,75 @@
$: if (saved && closeWhenSaved) {
window.setup_section.close();
}
export async function setupSection(pageIdLoad, sectionIdLoad, product = null, closeModalWhenSaved = false) {
// Clear
saved = false;
// Set
closeWhenSaved = closeModalWhenSaved;
$: if (sectionType) {
if (sectionType === 'text') {
getTextConfigFromNostr();
}
pageId = pageIdLoad;
sectionId = sectionIdLoad;
if (sectionType === 'products_with_slider') {
getProductsWithSliderConfigFromNostr();
}
}
page = getPage(pageId, $NostrGlobalConfig);
function getTextConfigFromNostr() {
if ($fileConfiguration?.admin_pubkeys?.length > 0) {
let receivedAt = 0;
sectionTitle = page?.sections[sectionId]?.title ?? '';
sectionType = page?.sections[sectionId]?.params?.sectionType ?? null;
maxProductsShown = page?.sections[sectionId]?.params?.maxProductsShown ?? 0;
initialMinifiedLexicalContent = '';
if (sectionType === 'text') {
subscribeConfiguration($fileConfiguration.admin_pubkeys, [getConfigurationKey('sectionText_' + pageId + '_' + sectionId)],
(initialMinifiedLexicalContentFromNostr, rcAt) => {
if (rcAt > receivedAt) {
receivedAt = rcAt;
initialMinifiedLexicalContent = initialMinifiedLexicalContentFromNostr;
}
});
}
}
function getProductsWithSliderConfigFromNostr() {
if (lastProductPassed) {
if ($fileConfiguration?.admin_pubkeys?.length > 0) {
let receivedAt = 0;
initialMinifiedLexicalContent = '';
initialMinifiedLexicalContent = (lastProductPassed.name ?? '') + ('\n\n' + lastProductPassed.description ?? '');
subscribeConfiguration($fileConfiguration.admin_pubkeys, [getConfigurationKey('sectionText_' + pageId + '_' + sectionId)],
subscribeConfiguration($fileConfiguration.admin_pubkeys, [getConfigurationKey('section_products_with_slider_' + pageId + '_' + sectionId + '_' + lastProductPassed.id)],
(initialMinifiedLexicalContentFromNostr, rcAt) => {
if (rcAt > receivedAt) {
receivedAt = rcAt;
initialMinifiedLexicalContent = initialMinifiedLexicalContentFromNostr;
}
});
}
} else {
lastProductPassed = null;
}
}
if (sectionType === 'products_with_slider') {
if (product) {
if ($fileConfiguration?.admin_pubkeys?.length > 0) {
lastProductPassed = product;
let receivedAt = 0;
initialMinifiedLexicalContent = (product.name ?? '') + ('\n\n' + product.description ?? '');
subscribeConfiguration($fileConfiguration.admin_pubkeys, [getConfigurationKey('section_products_with_slider_' + pageId + '_' + sectionId + '_' + product.id)],
(initialMinifiedLexicalContentFromNostr, rcAt) => {
if (rcAt > receivedAt) {
receivedAt = rcAt;
initialMinifiedLexicalContent = initialMinifiedLexicalContentFromNostr;
}
});
}
} else {
lastProductPassed = null;
}
export async function setupSection(pageIdLoad, sectionIdLoad, product = null, closeModalWhenSaved = false) {
// Clear
saved = false;
// Set
closeWhenSaved = closeModalWhenSaved;
pageId = pageIdLoad;
sectionId = sectionIdLoad;
if (product) {
lastProductPassed = product;
}
page = getPage(pageId, $NostrGlobalConfig);
sectionTitle = page?.sections[sectionId]?.title ?? '';
sectionType = page?.sections[sectionId]?.params?.sectionType ?? null;
maxProductsShown = page?.sections[sectionId]?.params?.maxProductsShown ?? 0;
if (sectionType === 'text') {
getTextConfigFromNostr()
} else if (sectionType === 'products_with_slider') {
getProductsWithSliderConfigFromNostr();
}
window.setup_section.showModal();
Expand Down Expand Up @@ -148,7 +165,7 @@
</div>
{/if}

{#if browser && initialMinifiedLexicalContent && sectionType === 'text' || (sectionType === 'products_with_slider' && lastProductPassed)}
{#if browser && sectionType === 'text' || (sectionType === 'products_with_slider' && lastProductPassed)}
<div class="mt-8">
{#key initialMinifiedLexicalContent}
<RichTextComposer {initialMinifiedLexicalContent} bind:getLexicalContent={getLexicalContent} />
Expand Down

0 comments on commit 3c48fd6

Please sign in to comment.