Skip to content

Commit

Permalink
Fix the date linked permalink up
Browse files Browse the repository at this point in the history
  • Loading branch information
lyxal committed Jan 13, 2025
1 parent c4d84ea commit 3e7ac5d
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 9 deletions.
18 changes: 11 additions & 7 deletions src/latest/scripts/interpreter/permalink.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { gunzipString, gzipString } from "gzip-utils";

const compat = JSON.parse(compatRaw);
const releaseDates = JSON.parse(datesRaw);
const LATEST_VYXAL_VERSION_CONSTANT_RETURNED_FROM_DETERMINE_VERSION = "hacky ahh solution"
const LATEST_VYXAL_VERSION_CONSTANT_RETURNED_FROM_DETERMINE_VERSION = "latest"

type OldPermalinks = {
format: 2,
Expand All @@ -16,7 +16,7 @@ type OldPermalinks = {
version: string,
};

const latestPermalink = 4;
const latestPermalink = 3;
export type Permalink = {
format: typeof latestPermalink,
flags: string[],
Expand All @@ -28,6 +28,7 @@ export type Permalink = {
};

function decodeVersion(version: string): string {

// This is what happens when you let lyxal write a hack
// solution to something that probably required a bigger
// refactoring. (Comment written by, surprisingly, lyxal)
Expand All @@ -51,15 +52,16 @@ function decodeVersion(version: string): string {
// Now, iterate through the release dates and find the
// first release after the given date.

const candidates = Object.entries(releaseDates).filter(([_, d]) => new Date(d.toString()) > date);
const parsedDates: [string, Date][] = Object.entries(releaseDates).map(([v, d]) => [v, new Date(Date.parse(d as string))]);
const candidates = parsedDates.filter(([_, d]) => new Date(d) > date);

Check warning

Code scanning / ESLint

Disallow unused variables Warning

'_' is defined but never used.
if (candidates.length === 0) {
return LATEST_VYXAL_VERSION_CONSTANT_RETURNED_FROM_DETERMINE_VERSION;
}
return candidates[0][1].toString();
return candidates[0][0];
}

function incompatible(permalinkVersion: string) {
if (permalinkVersion === LATEST_VYXAL_VERSION_CONSTANT_RETURNED_FROM_DETERMINE_VERSION) { return true; }
if (permalinkVersion === LATEST_VYXAL_VERSION_CONSTANT_RETURNED_FROM_DETERMINE_VERSION) { return false; }
return compat[permalinkVersion] ?? false;
}

Expand Down Expand Up @@ -120,8 +122,10 @@ export async function decodeHash(hash: string): Promise<DecodeResult | null> {
}
try {
let realVersion = decodeVersion(permalink.version);
if (incompatible(permalink.version)) {
return { compatible: false, version: permalink.version };
console.log("Real version:", realVersion);
console.log("Permalink version:", permalink.version);
if (incompatible(realVersion)) {
return { compatible: false, version: realVersion };
}
switch (permalink.format) {
case 2: {
Expand Down
4 changes: 3 additions & 1 deletion src/latest/scripts/main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ const fallback = document.getElementById("fallback-ui")!;
fallback.hidden = true;
const permalink = window.location.hash.length ? await decodeHash(window.location.hash.slice(1)) : null;
if (permalink != null && !permalink.compatible) {
window.location.replace(`https://vyxal.github.io/versions/v${permalink.version}#${location.hash.substring(1)}`);
console.error("Incompatible permalink version!", permalink.version);
// window.location.replace(`https://vyxal.github.io/versions/v${permalink.version}#${location.hash.substring(1)}`);

} else {
// @ts-expect-error DATA_URI gets replaced by Webpack
const elementData = parseElementData(await fetch(`${DATA_URI}/theseus.json`).then((r) => r.json()));
Expand Down
2 changes: 1 addition & 1 deletion src/latest/scripts/ui/Theseus.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ export function Theseus({ permalink }: TheseusProps) {
footer,
flags: [...serializeFlags(elementData.flagDefs, flags)],
inputs: inputs.map(({ name, inputs }) => [name, inputs.map(({ input }) => input)]),
version: `${date.getDate()}/${date.getMonth() + 1}/${date.getFullYear()}`,
version: `${date.getFullYear()}-${date.getMonth() + 1}-${date.getDate()}`,
}).then((hash) => history.replaceState(undefined, "", "#" + hash));
}, [header, code, footer, flags, inputs, elementData]);

Expand Down

0 comments on commit 3e7ac5d

Please sign in to comment.