-
Notifications
You must be signed in to change notification settings - Fork 25
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
244 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,3 @@ | ||
export function createPage1Content(): string { | ||
return `<div>This is the content of page 1</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 @@ | ||
export function createPage2Content(): string { | ||
return `<div>This is the content of page 2</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,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,14 @@ | ||
import { createPage1Content } from "../components/component1"; | ||
|
||
export async function loadPage1() { | ||
const contentArea = document.getElementById("content-area"); | ||
|
||
if (contentArea) { | ||
try { | ||
const content = createPage1Content(); | ||
contentArea.innerHTML = 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,14 @@ | ||
import { createPage2Content } from "../components/component2"; | ||
|
||
export async function loadPage2() { | ||
const contentArea = document.getElementById("content-area"); | ||
|
||
if (contentArea) { | ||
try { | ||
const content = createPage2Content(); // Use a reusable component | ||
contentArea.innerHTML = 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,23 @@ | ||
import { handleRouting, setupRouter } from "./router"; | ||
import { initializeState } from "./on-load"; | ||
|
||
setupRouter(); | ||
|
||
export async function mainModule() { | ||
try { | ||
await initializeState(); | ||
console.log("State initialized"); | ||
|
||
await handleRouting(); | ||
} catch (error) { | ||
console.error("Error in main: ", error); | ||
} | ||
} | ||
|
||
mainModule() | ||
.then(() => { | ||
console.log("mainModule loaded"); | ||
}) | ||
.catch((error) => { | ||
console.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,41 @@ | ||
import { loadPage1 } from "./controllers/page1"; | ||
import { loadPage2 } from "./controllers/page2"; | ||
import { load404Page } from "./controllers/404"; | ||
import { loadHomePage } from "./controllers/home"; | ||
|
||
// URL Path based routing | ||
export async function handleRouting() { | ||
const contentArea = document.getElementById("content-area"); | ||
|
||
if (!contentArea) return; | ||
|
||
const route = window.location.hash; | ||
|
||
switch (route) { | ||
case "": | ||
Check warning on line 15 in src/router.ts GitHub Actions / check-for-empty-strings
|
||
case "#/home": | ||
case "#/index": | ||
await loadHomePage(); | ||
break; | ||
case "#/page1": | ||
await loadPage1(); | ||
break; | ||
case "#/page2": | ||
await loadPage2(); | ||
break; | ||
default: | ||
// Redirect to 404 page if no route matches | ||
await load404Page(); | ||
break; | ||
} | ||
} | ||
|
||
export function setupRouter() { | ||
if (typeof window !== "undefined") { | ||
window.addEventListener("hashchange", () => { | ||
handleRouting().catch(console.error); | ||
}); | ||
|
||
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