Skip to content

Commit cccb3ff

Browse files
committed
Remove loadPage function and componentLoader import, cleanup unused code
1 parent 2397dd8 commit cccb3ff

File tree

1 file changed

+1
-109
lines changed

1 file changed

+1
-109
lines changed

public/js/main.js

Lines changed: 1 addition & 109 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,7 @@ function initRouter() {
7373
window.router = router;
7474
}
7575

76-
// Import utilities from deps.js
77-
import { componentLoader } from './deps.js';
76+
// Import page initializers
7877
import {
7978
initLoginPage,
8079
initRegisterPage,
@@ -84,113 +83,6 @@ import {
8483
initResetPasswordPage
8584
} from './page-initializers.js';
8685

87-
/**
88-
* Load a page from the server
89-
* @param {string} url - Page URL
90-
* @returns {Promise<string>} - Page HTML
91-
*/
92-
async function loadPage(url) {
93-
try {
94-
console.log(`Loading page: ${url}`);
95-
96-
97-
// Add cache-busting parameter to prevent caching
98-
const cacheBuster = `?_=${Date.now()}`;
99-
const fullUrl = `${url}${cacheBuster}`;
100-
console.log(`Fetching URL: ${fullUrl}`);
101-
102-
const response = await fetch(fullUrl);
103-
console.log(`Response status: ${response.status} ${response.statusText}`);
104-
console.log(`Response headers:`, Object.fromEntries([...response.headers.entries()]));
105-
106-
if (!response.ok) {
107-
console.error(`Failed to load page: ${response.status} ${response.statusText}`);
108-
throw new Error(`Failed to load page: ${response.status} ${response.statusText}`);
109-
}
110-
111-
const html = await response.text();
112-
113-
// Extract the content from the page
114-
const parser = new DOMParser();
115-
const doc = parser.parseFromString(html, 'text/html');
116-
117-
// Create a wrapper element to hold the content temporarily
118-
const wrapper = document.createElement('div');
119-
wrapper.style.display = 'none';
120-
document.body.appendChild(wrapper);
121-
122-
// Get the content - either from body or the first element
123-
let content;
124-
if (doc.body.children.length === 0) {
125-
content = doc.body.innerHTML;
126-
} else {
127-
// Create a temporary div to hold the content
128-
const tempDiv = document.createElement('div');
129-
130-
// Extract module script sources (they'll be loaded later by the router)
131-
const moduleScripts = componentLoader.extractModuleScriptSources(doc);
132-
console.log('Extracted module scripts:', moduleScripts);
133-
134-
// Filter out script tags (they'll be imported dynamically by the router)
135-
const contentWithoutScripts = componentLoader.filterScriptTags(doc.body, true); // Keep script tags
136-
content = contentWithoutScripts.innerHTML;
137-
}
138-
139-
// Add the content to the wrapper
140-
wrapper.innerHTML = content;
141-
142-
// Pre-translate the content before it's returned to the router
143-
localizer.translateContainer(wrapper);
144-
145-
// Get the translated content
146-
content = wrapper.innerHTML;
147-
148-
// Remove the wrapper
149-
document.body.removeChild(wrapper);
150-
151-
// Create DOM elements instead of using template strings
152-
const container = document.createElement('div');
153-
154-
// Add header
155-
const header = document.createElement('pf-header');
156-
container.appendChild(header);
157-
158-
// Add content container
159-
const contentDiv = document.createElement('div');
160-
contentDiv.className = 'content';
161-
162-
// Use DOM parser to convert content string to DOM nodes
163-
const contentFragment = document.createRange().createContextualFragment(content);
164-
contentDiv.appendChild(contentFragment);
165-
166-
container.appendChild(contentDiv);
167-
168-
// Add footer
169-
const footer = document.createElement('pf-footer');
170-
container.appendChild(footer);
171-
172-
// Return the HTML string representation
173-
// Get the HTML content
174-
const result = container.outerHTML;
175-
176-
// No need to schedule translation after rendering
177-
// since we're now doing it before rendering in the renderer function
178-
console.log('Content loaded, translations already applied during rendering');
179-
180-
return result;
181-
} catch (error) {
182-
console.error('Error loading page:', error);
183-
return `
184-
<pf-header></pf-header>
185-
<div class="error">
186-
<h1 data-i18n="errors.error_loading_page">Error Loading Page</h1>
187-
<p>${error.message}</p>
188-
</div>
189-
<pf-footer></pf-footer>
190-
`;
191-
}
192-
}
193-
19486
// No longer needed since we're using SPA mode exclusively
19587

19688
// No longer needed since we're using SPA mode exclusively

0 commit comments

Comments
 (0)