-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
19 changed files
with
250 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
export function createPage1Content(): HTMLElement { | ||
const container = document.createElement("div"); | ||
container.textContent = "This is the content of page 1"; | ||
return container; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
export function createPage2Content(): HTMLElement { | ||
const container = document.createElement("div"); | ||
container.textContent = "This is the content of page 2"; | ||
return container; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
export async function load404Page() { | ||
const contentArea = document.getElementById("content-area"); | ||
|
||
if (contentArea) { | ||
try { | ||
const response = await fetch("./404.html"); | ||
const html = await response.text(); | ||
contentArea.innerHTML = html; | ||
} catch (error) { | ||
console.error("Failed to load 404 page:", error); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
export async function loadHomePage() { | ||
const contentArea = document.getElementById("content-area"); | ||
|
||
if (contentArea) { | ||
try { | ||
const response = await fetch("./home.html"); | ||
const html = await response.text(); | ||
contentArea.innerHTML = html; | ||
} catch (error) { | ||
console.error("Failed to load home page:", error); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { createPage1Content } from "../components/component1"; | ||
|
||
export async function loadPage1() { | ||
const contentArea = document.getElementById("content-area"); | ||
|
||
if (contentArea) { | ||
try { | ||
const content = createPage1Content(); | ||
contentArea.innerHTML = ""; | ||
Check warning on line 9 in src/controllers/page1.ts GitHub Actions / check-for-empty-strings
|
||
contentArea.appendChild(content); | ||
} catch (error) { | ||
console.error("Failed to load page 1:", error); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { createPage2Content } from "../components/component2"; | ||
|
||
export async function loadPage2() { | ||
const contentArea = document.getElementById("content-area"); | ||
|
||
if (contentArea) { | ||
try { | ||
const content = createPage2Content(); | ||
contentArea.innerHTML = ""; | ||
Check warning on line 9 in src/controllers/page2.ts GitHub Actions / check-for-empty-strings
|
||
contentArea.appendChild(content); | ||
} catch (error) { | ||
console.error("Failed to load page 2:", error); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { handleRouting } from "./router"; | ||
import { initializeState } from "./on-load"; | ||
|
||
export async function mainModule() { | ||
try { | ||
await initializeState(); | ||
console.log("State initialized"); | ||
|
||
await handleRouting(); | ||
} catch (error) { | ||
console.error("Error in main: ", error); | ||
} | ||
} | ||
|
||
mainModule().catch((error) => { | ||
console.error("Unhandled error:", error); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { GlobalState } from "./types"; | ||
|
||
export const globalState: GlobalState = { | ||
isLoading: false, | ||
data: {}, | ||
}; | ||
|
||
export async function initializeState() { | ||
globalState.isLoading = true; | ||
try { | ||
// Initial data loading goes here | ||
globalState.data = {}; | ||
} finally { | ||
globalState.isLoading = false; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import { loadPage1 } from "./controllers/page1"; | ||
import { loadPage2 } from "./controllers/page2"; | ||
import { load404Page } from "./controllers/404"; | ||
import { loadHomePage } from "./controllers/home"; | ||
|
||
function normalizeRoute(hash: string): string { | ||
// Remove file extensions | ||
let route = hash.replace(/\.[^/.]+$/, ""); | ||
Check warning on line 8 in src/router.ts GitHub Actions / check-for-empty-strings
|
||
// Ensure hash starts with #/ | ||
if (!route.startsWith("#")) route = "#" + route; | ||
if (!route.startsWith("#/")) route = "#/" + route.substring(1); | ||
// Remove trailing slash except for root | ||
if (route !== "#/") route = route.replace(/\/$/, ""); | ||
Check warning on line 13 in src/router.ts GitHub Actions / check-for-empty-strings
|
||
return route; | ||
} | ||
|
||
// URL Path based routing | ||
export async function handleRouting() { | ||
const contentArea = document.getElementById("content-area"); | ||
|
||
if (!contentArea) return; | ||
|
||
const route = normalizeRoute(window.location.hash); | ||
|
||
switch (route) { | ||
case "#/page1": | ||
await loadPage1(); | ||
break; | ||
case "#/page2": | ||
await loadPage2(); | ||
break; | ||
case "#/": | ||
case "#/home": | ||
case "#/index": | ||
await loadHomePage(); | ||
break; | ||
default: | ||
// Redirect to home if no route matches | ||
await load404Page(); | ||
break; | ||
} | ||
} | ||
|
||
// Run handleRouting on hashchange | ||
window.addEventListener("hashchange", () => { | ||
handleRouting().catch(console.error); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
export interface GlobalState { | ||
isLoading: boolean; | ||
data: Record<string, unknown>; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<div id="Page404"> | ||
<div> | ||
<p>Oops!</p> | ||
<p>We can't seem to find the page you're looking for</p> | ||
<p> | ||
<b>Here are some helpful links instead:</b> | ||
</p> | ||
<ul> | ||
<li> | ||
<a href="//github.com/ubiquity/ubiquity-dollar/wiki" target="_blank">Docs</a> | ||
</li> | ||
<li> | ||
<a href="//dao.ubq.fi/faq" target="_blank">FAQ</a> | ||
</li> | ||
<li> | ||
<a href="//github.com/ubiquity/ubiquity-dollar" target="_blank">Github</a> | ||
</li> | ||
<li> | ||
<a href="//discord.gg/SjymJ5maJ4" target="_blank">Discord</a> | ||
</li> | ||
<li> | ||
<a href="//t.me/ubiquitydao" target="_blank">Telegram</a> | ||
</li> | ||
<li> | ||
<a href="//x.com/UbiquityDAO" target="_blank">X</a> | ||
</li> | ||
</ul> | ||
</div> | ||
<div> 404 </div> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
<div class="content"> | ||
<h1>Ubiquity TypeScript Template Home</h1> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
<div class="content"> | ||
<h1>Ubiquity TypeScript Template Page 1</h1> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
<div class="content"> | ||
<h1>Ubiquity TypeScript Template Page 2</h1> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters