Skip to content

Commit

Permalink
path stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
GregTCLTK committed Nov 1, 2023
1 parent d2ebf0a commit e203707
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 12 deletions.
5 changes: 4 additions & 1 deletion pages/hosting/loading.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { HmRequest, LoginRequest, MessageType, SyncResponse, TriggerRequest } from "https://deno.land/x/hmsys_connector@0.9.0/mod.ts";
import { API, ProgressTracker } from "shared";
import { API, ProgressTracker, stupidErrorAlert } from "shared";
import { Deferred, deferred } from "std/async/deferred.ts";
import { decodeBase64, encodeBase64 } from "std/encoding/base64.ts";
import { Pointer, State, asPointer, lazyInit } from "webgen/mod.ts";
Expand All @@ -11,6 +11,9 @@ import { canWriteInFolder, currentFiles } from "./views/state.ts";

export async function refreshState() {
state.servers = State((await API.hosting.servers()).map(x => State(x)));
const server = await API.hosting.serverId("64667d43cd05eda8384c6481").get().then(stupidErrorAlert);
if (!state.servers.find(it => it._id == "64667d43cd05eda8384c6481"))
state.servers.push(State(server));
state.meta = State(await API.hosting.meta());
}

Expand Down
30 changes: 26 additions & 4 deletions pages/hosting/main.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,45 @@
import { Vertical, View, WebGen } from "webgen/mod.ts";
import { State, Vertical, View, WebGen } from "webgen/mod.ts";
import '../../assets/css/main.css';
import { DynaNavigation } from "../../components/nav.ts";
import { RegisterAuthRefresh, changeThemeColor, renewAccessTokenIfNeeded } from "../_legacy/helper.ts";
import { state } from "./data.ts";
import { listener, refreshState } from "./loading.ts";
import { listener, refreshState, startSidecarConnection, streamingPool } from "./loading.ts";
import { hostingMenu } from "./views/menu.ts";

import '../../assets/css/hosting.css';
import { LoadingSpinner } from "../shared/components.ts";
import { API, stupidErrorAlert } from "../shared/restSpec.ts";
await RegisterAuthRefresh();

const url = new URLSearchParams(location.search);

const urlPath = url.get("path");

WebGen({
events: {
themeChanged: changeThemeColor()
}
});

View(() => Vertical(DynaNavigation("Hosting"), hostingMenu)).appendOn(document.body);
View(() => Vertical(DynaNavigation("Hosting"), state.$loaded.map(loaded => loaded ? hostingMenu : LoadingSpinner()).asRefComponent())).appendOn(document.body);

renewAccessTokenIfNeeded()
.then(() => refreshState())
.then(() => listener())
.then(() => state.loaded = true);
.then(async () => {
if (!urlPath) {
state.loaded = true;
return;
}
const serverId = urlPath.split("/")[ 1 ];
if (serverId) {
const server = await API.hosting.serverId(serverId).get().then(stupidErrorAlert);
if (!state.servers.find(it => it._id == serverId))
state.servers.push(State(server));
await streamingPool();
if (!server.identifier)
startSidecarConnection(serverId);
}
state.loaded = true;
hostingMenu.path.setValue(urlPath);
});
1 change: 1 addition & 0 deletions pages/hosting/views/ServerDetails.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ export function ServerDetails(server: StateHandler<Server>) {
title: "Storage",
subtitle: "Manage your persistence",
}).onClick(async () => {
console.log(hostingMenu.path.getValue());
await listFiles("/");
path.setValue("/");
hostingMenu.path.setValue(`${hostingMenu.path.getValue()}/storage/`);
Expand Down
8 changes: 1 addition & 7 deletions pages/hosting/views/menu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,14 +138,8 @@ export const hostingMenu = Navigation({
"limited-width"
);

state.$loaded.listen(loaded => {
if (loaded)
hostingMenu.path.setValue((state.servers.length == 0 ? 'resources/' : 'servers/'));
else
hostingMenu.path.setValue("-/");
});

hostingMenu.path.listen(path => {
history.pushState(undefined, "", `/hosting?path=${path}`);
if ([ "servers/", "resources/" ].includes(path)) {
hostingButtons.setValue(
[
Expand Down
1 change: 1 addition & 0 deletions pages/shared/restSpec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ export async function asExternal<T>(promise: Promise<T>): Promise<PromiseSettled
};
}
}
}

function json<T>() {
return async (rsp: Response) => {
Expand Down

0 comments on commit e203707

Please sign in to comment.