Skip to content

Commit 693858c

Browse files
committed
fix: run the function for user and starter templates
1 parent b0026f2 commit 693858c

2 files changed

Lines changed: 69 additions & 66 deletions

File tree

src/livecodes/UI/templates.ts

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -53,12 +53,12 @@ export const noUserTemplates = () => `
5353
<div class="description alert">${window.deps.translateString('templates.noUserTemplates.heading', 'You have no saved templates.')}</div>
5454
<div class="description help">
5555
${window.deps.translateString(
56-
'templates.noUserTemplates.desc',
57-
'You can save a project as a template from <wbr />(App&nbsp;menu&nbsp;&gt;&nbsp;Save&nbsp;as&nbsp;&gt; Template).',
58-
{
59-
isHTML: true,
60-
},
61-
)}
56+
'templates.noUserTemplates.desc',
57+
'You can save a project as a template from <wbr />(App&nbsp;menu&nbsp;&gt;&nbsp;Save&nbsp;as&nbsp;&gt; Template).',
58+
{
59+
isHTML: true,
60+
},
61+
)}
6262
</div>
6363
</div>
6464
`;
@@ -68,7 +68,10 @@ export const setupTemplatesSearch = () => {
6868
if (!input) return;
6969

7070
const filterTemplates = (query: string) => {
71-
const items = document.querySelectorAll('#templates-user li');
71+
console.log('Debuounce templates with query:', query);
72+
const mainItems = document.querySelectorAll('#templates-starter li');
73+
const userItems = document.querySelectorAll('#templates-user li');
74+
const items = Array.from(mainItems).concat(Array.from(userItems));
7275
items.forEach((item) => {
7376
const text = item.textContent?.toLowerCase() || '';
7477
const matches = text.includes(query.toLowerCase());
@@ -82,6 +85,7 @@ export const setupTemplatesSearch = () => {
8285

8386
input.addEventListener('input', (e: Event) => {
8487
const val = (e.target as HTMLInputElement).value || '';
88+
console.log('Filtering templates with query:', val);
8589
debouncedFilter(val);
8690
});
8791
};

src/livecodes/core.ts

Lines changed: 58 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -250,18 +250,18 @@ const loadStyles = () =>
250250
isHeadless
251251
? Promise.resolve()
252252
: Promise.all(
253-
[
254-
snackbarUrl,
255-
...(isLite
256-
? []
257-
: [
258-
lunaObjViewerStylesUrl,
259-
lunaDataGridStylesUrl,
260-
lunaDomViewerStylesUrl,
261-
lunaConsoleStylesUrl,
262-
]),
263-
].map((url) => loadStylesheet(url, undefined, '#app-styles')),
264-
);
253+
[
254+
snackbarUrl,
255+
...(isLite
256+
? []
257+
: [
258+
lunaObjViewerStylesUrl,
259+
lunaDataGridStylesUrl,
260+
lunaDomViewerStylesUrl,
261+
lunaConsoleStylesUrl,
262+
]),
263+
].map((url) => loadStylesheet(url, undefined, '#app-styles')),
264+
);
265265

266266
let lastRun = { time: 0, result: '' };
267267
const createIframe = (container: HTMLElement, result = '', service = sandboxService) =>
@@ -353,12 +353,11 @@ const createIframe = (container: HTMLElement, result = '', service = sandboxServ
353353

354354
iframe.remove(); // avoid changing browser history
355355
const { markup, style, script } = getConfig();
356-
const query = `?markup=${markup.language}&style=${style.language}&script=${
357-
script.language
358-
}&isEmbed=${isEmbed}&isLoggedIn=${Boolean(authService?.isLoggedIn())}&appCDN=${getAppCDN()}`;
356+
const query = `?markup=${markup.language}&style=${style.language}&script=${script.language
357+
}&isEmbed=${isEmbed}&isLoggedIn=${Boolean(authService?.isLoggedIn())}&appCDN=${getAppCDN()}`;
359358
const scrollPosition =
360359
params.scrollPosition === false ||
361-
(iframeScrollPosition.x === 0 && iframeScrollPosition.y === 0)
360+
(iframeScrollPosition.x === 0 && iframeScrollPosition.y === 0)
362361
? ''
363362
: `#livecodes-scroll-position:${iframeScrollPosition.x},${iframeScrollPosition.y}`;
364363
iframe.src = service.getResultUrl() + query + scrollPosition;
@@ -505,7 +504,7 @@ const createEditors = async (config: Config) => {
505504
language: languageIsEnabled(config.markup.language, config)
506505
? config.markup.language
507506
: (config.languages?.find((lang) => getLanguageEditorId(lang) === 'markup') as Language) ||
508-
'html',
507+
'html',
509508
value: languageIsEnabled(config.markup.language, config) ? config.markup.content || '' : '',
510509
};
511510
const styleOptions: EditorOptions = {
@@ -515,7 +514,7 @@ const createEditors = async (config: Config) => {
515514
language: languageIsEnabled(config.style.language, config)
516515
? config.style.language
517516
: (config.languages?.find((lang) => getLanguageEditorId(lang) === 'style') as Language) ||
518-
'css',
517+
'css',
519518
value: languageIsEnabled(config.style.language, config) ? config.style.content || '' : '',
520519
};
521520
const scriptOptions: EditorOptions = {
@@ -525,7 +524,7 @@ const createEditors = async (config: Config) => {
525524
language: languageIsEnabled(config.script.language, config)
526525
? config.script.language
527526
: (config.languages?.find((lang) => getLanguageEditorId(lang) === 'script') as Language) ||
528-
'javascript',
527+
'javascript',
529528
value: languageIsEnabled(config.script.language, config) ? config.script.content || '' : '',
530529
};
531530

@@ -982,12 +981,12 @@ const getResultPage = async ({
982981
blockly:
983982
scriptLanguage === 'blockly'
984983
? ((await customEditors.blockly?.getContent({
985-
baseUrl,
986-
editors,
987-
config: getConfig(),
988-
html: compiledMarkup,
989-
eventsManager,
990-
})) as BlocklyContent)
984+
baseUrl,
985+
editors,
986+
config: getConfig(),
987+
html: compiledMarkup,
988+
eventsManager,
989+
})) as BlocklyContent)
991990
: {},
992991
});
993992
const compiledScript = scriptCompileResult.code;
@@ -1328,28 +1327,28 @@ const share = async (
13281327
const config = getConfig();
13291328
const content = contentOnly
13301329
? {
1331-
...getContentConfig(config),
1332-
markup: {
1333-
...config.markup,
1334-
title: undefined,
1335-
hideTitle: undefined,
1336-
},
1337-
style: {
1338-
...config.style,
1339-
title: undefined,
1340-
hideTitle: undefined,
1341-
},
1342-
script: {
1343-
...config.script,
1344-
title: undefined,
1345-
hideTitle: undefined,
1346-
},
1347-
tools: {
1348-
...config.tools,
1349-
enabled: defaultConfig.tools.enabled,
1350-
status: config.tools.status === 'none' ? defaultConfig.tools.status : config.tools.status,
1351-
},
1352-
}
1330+
...getContentConfig(config),
1331+
markup: {
1332+
...config.markup,
1333+
title: undefined,
1334+
hideTitle: undefined,
1335+
},
1336+
style: {
1337+
...config.style,
1338+
title: undefined,
1339+
hideTitle: undefined,
1340+
},
1341+
script: {
1342+
...config.script,
1343+
title: undefined,
1344+
hideTitle: undefined,
1345+
},
1346+
tools: {
1347+
...config.tools,
1348+
enabled: defaultConfig.tools.enabled,
1349+
status: config.tools.status === 'none' ? defaultConfig.tools.status : config.tools.status,
1350+
},
1351+
}
13531352
: config;
13541353

13551354
const currentUrl = (location.origin + location.pathname).split('/').slice(0, -1).join('/') + '/';
@@ -1631,7 +1630,7 @@ const setSavedStatus = async () => {
16311630
!!(
16321631
savedConfig &&
16331632
JSON.stringify(getContentConfig(savedConfig)) ===
1634-
JSON.stringify(getContentConfig(getConfig()))
1633+
JSON.stringify(getContentConfig(getConfig()))
16351634
);
16361635

16371636
const projectTitle = UI.getProjectTitleElement();
@@ -1813,12 +1812,12 @@ const login = async () =>
18131812
const displayName = user.displayName || user.username;
18141813
const loginSuccessMessage = displayName
18151814
? window.deps.translateString(
1816-
'core.login.successWithName',
1817-
'Logged in as: {{name}}',
1818-
{
1819-
name: displayName,
1820-
},
1821-
)
1815+
'core.login.successWithName',
1816+
'Logged in as: {{name}}',
1817+
{
1818+
name: displayName,
1819+
},
1820+
)
18221821
: window.deps.translateString('core.login.success', 'Logged in successfully');
18231822
notifications.success(loginSuccessMessage);
18241823
displayLoggedIn(user);
@@ -2591,9 +2590,9 @@ const handleKeyboardShortcutsScreen = () => {
25912590
<tr>
25922591
<td>${item.title}</td>
25932592
<td>${item.hotkey
2594-
?.split('+')
2595-
.map((key) => `<kbd>${capitalize(key)}</kbd>`)
2596-
.join(' ')}</td>
2593+
?.split('+')
2594+
.map((key) => `<kbd>${capitalize(key)}</kbd>`)
2595+
.join(' ')}</td>
25972596
</tr>
25982597
`,
25992598
)
@@ -3151,8 +3150,6 @@ const handleNew = () => {
31513150
const templatesContainer = createTemplatesContainer(eventsManager, () => loadUserTemplates());
31523151
const userTemplatesScreen = UI.getUserTemplatesScreen(templatesContainer);
31533152

3154-
setupTemplatesSearch();
3155-
31563153
const loadUserTemplates = async () => {
31573154
const defaultTemplate = getAppData()?.defaultTemplate;
31583155
const userTemplates = ((await stores.templates?.getList()) || []).sort((a, b) =>
@@ -3268,6 +3265,7 @@ const handleNew = () => {
32683265
starterTemplatesCache = starterTemplates;
32693266
loadingText?.remove();
32703267
starterTemplates.forEach((template) => {
3268+
console.log('Template loaded:', template.name);
32713269
const link = createStarterTemplateLink(template, starterTemplatesList, baseUrl);
32723270
eventsManager.addEventListener(
32733271
link,
@@ -3279,6 +3277,7 @@ const handleNew = () => {
32793277
false,
32803278
);
32813279
});
3280+
setupTemplatesSearch();
32823281
})
32833282
.catch(() => {
32843283
loadingText?.remove();

0 commit comments

Comments
 (0)