Refactored all of the javscript code. Updates, refreshes, and initializations are in their own separated functions now.

This commit is contained in:
Ada Werefox 2024-04-08 22:22:32 -05:00
parent f15f125630
commit 08cae8765e
6 changed files with 591 additions and 606 deletions

View File

@ -0,0 +1,39 @@
async function refresh_overview(server_address) {
try {
const response = await fetch(`${server_address}overview`);
if (response.ok) {
const data = await response.json();
if (!("error" in data)) {
return { overview: data, error: null };
}
}
return { overview: null, error: null };
} catch (e) {
return { overview: null, error: e };
}
}
async function refresh_hints(server_address) {
const response = await fetch(`${server_address}hints`);
const data = await response.json();
return data;
}
async function refresh_checks(server_address) {
const response = await fetch(`${server_address}items`);
const data = await response.json();
return data;
}
async function refresh_entrances(server_address) {
const response = await fetch(`${server_address}doors`);
const data = await response.json();
return data;
}
export default {
refresh_overview,
refresh_checks,
refresh_entrances,
refresh_hints,
};

File diff suppressed because it is too large Load Diff

View File

@ -14,6 +14,7 @@
<link rel="stylesheet" href="https://csshake.surge.sh/csshake-default.css">
<script src="{% static "tracker/assets/button-functions.js" %}"></script>
<script type="module" src="{% static "tracker/assets/main.js" %}"></script>
<script type="module" src="{% static "tracker/assets/fetch-updates.js" %}"></script>
<script type="module" src="{% static "tracker/assets/translate-hints.js" %}"></script>
</head>
<body class="min-h-screen font-nerd bg-gradient-to-br from-bluelight-background-dark to-bluelight-background">

View File

@ -1,10 +1,10 @@
<div class="flex flex-col space-y-2 max-w-full {{ extra_classes }}"
<div class="breakdown flex flex-col space-y-2 max-w-full {{ extra_classes }}"
data-current="{{ is_current_scene }}"
data-breakdown-scene="{{ scene_title }}">
data-scene="{{ scene_title }}">
<div class="px-2">
<div class="flex text-xl breakdown-block-title">{{ scene_title }}</div>
<div class="flex flex-col justify-center md:flex-row md:space-x-4">
<div class="flex flex-col overflow-hidden basis-1/2">
<div class="flex flex-col overflow-hidden breakdown-checks basis-1/2">
<div class="flex flex-col my-2 space-y-2">
<div class="text-md breakdown-block-checks-title"
data-checks="{{ scene_data.checks.collected }}">
@ -24,7 +24,7 @@
{% endfor %}
</div>
</div>
<div class="flex flex-col overflow-hidden basis-1/2">
<div class="flex flex-col overflow-hidden breakdown-entrances basis-1/2">
<div class="grid grid-flow-row my-2 space-y-2">
<div class="text-md breakdown-block-entrances-title"
data-entrances="{{ scene_data.entrances.found }}">
@ -49,7 +49,8 @@
<div class="flex flex-col p-1 mx-auto space-y-2 min-w-max breakdown-block-mapped-list">
<button type="button"
class="py-0.5 text-start bg-gradient-to-br from-bluelight-translucent-dark to-trans-pride-cyan-translucent rounded-md px-1 text-sm hidden"
onclick="open_breakdown(this)"></button>
onclick="open_breakdown(this)"
data-scene=""></button>
{% for entrance_origin, entrance_destination in scene_data.entrances.doors.items %}
{% if entrance_destination.door %}
<button type="button"

View File

@ -1,16 +1,18 @@
<button type="button"
class="rounded-xl {{ is_hidden }}"
class="summary rounded-xl {{ is_hidden }}"
onclick="open_breakdown(this)"
data-scene="{{ scene }}">
<div class="p-2 *:mr-auto *:justify-start *:text-left min-h-full flex flex-col rounded-lg bg-gradient-to-tl shadow-sm shadow-[#242424] {{ extra_classes }}">
<div class="summary-title">{{ scene }}:</div>
<div class="summary-checks"
data-checks-undiscovered="{{ scene_data.checks.collected }}"
data-checks-collected="{{ scene_data.checks.collected }}"
data-checks-remaining="{{ scene_data.checks.remaining }}"
data-checks-total="{{ scene_data.checks.total }}">
Checks: {{ scene_data.checks.collected }}/{{ scene_data.checks.total }} ({{ scene_data.checks.remaining }})
</div>
<div class="summary-entrances"
data-entrances-undiscovered="{{ scene_data.entrances.found }}"
data-entrances-found="{{ scene_data.entrances.found }}"
data-entrances-remaining="{{ scene_data.entrances.remaining }}"
data-entrances-total="{{ scene_data.entrances.total }}">
Entrances: {{ scene_data.entrances.found }}/{{ scene_data.entrances.total }} ({{ scene_data.entrances.remaining }})
</div>