Skip to content

Commit bff5d76

Browse files
authored
Merge pull request #1360 from thunderstore-io/02-24-enable_beta_switch_on_all_pages_but
Enable beta switch on all pages but
2 parents cdb5a65 + 50c1629 commit bff5d76

File tree

2 files changed

+48
-23
lines changed

2 files changed

+48
-23
lines changed

apps/cyberstorm-remix/public/cyberstorm-static/scripts/beta-switch.js

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
const enabledPages = ["/communities", "c/[^/]+/?$"];
21
const legacyProd = {
32
protocol: "https://",
43
hostname: "thunderstore.io",
@@ -36,6 +35,12 @@ const betaDev = {
3635
tld: "temp",
3736
};
3837
async function checkBetaRedirect(legacy, beta, goToBetaRoR2) {
38+
const legacyOnlyPages = [
39+
"/settings",
40+
"/package/create",
41+
"c/[^/]+/p/[^/]+/[^/]+/wiki/?$",
42+
"c/[^/]+/p/[^/]+/[^/]+/source/?$",
43+
];
3944
if (goToBetaRoR2) {
4045
window.location.assign(
4146
`${beta.protocol}${beta.hostname}${beta.port !== "" ? ":" : ""}${
@@ -44,35 +49,35 @@ async function checkBetaRedirect(legacy, beta, goToBetaRoR2) {
4449
);
4550
} else {
4651
let switchProject = legacy;
52+
let path = window.location.pathname;
4753
if (window.location.hostname === beta.hostname) {
4854
switchProject = legacy;
4955
} else if (window.location.hostname === legacy.hostname) {
5056
switchProject = beta;
57+
legacyOnlyPages.forEach((regPath) => {
58+
const regExecuted = new RegExp(regPath).exec(window.location.pathname);
59+
const found = regExecuted !== null && regExecuted.length < 2;
60+
if (found) {
61+
path = "/communities";
62+
}
63+
});
5164
}
5265
window.location.assign(
5366
`${switchProject.protocol}${switchProject.hostname}${
5467
switchProject.port !== "" ? ":" : ""
55-
}${switchProject.port}${window.location.pathname}`
68+
}${switchProject.port}${path}`
5669
);
5770
}
5871
}
5972
async function insertSwitchButton(legacy, beta) {
60-
let betaIsAvailable = false;
61-
enabledPages.forEach((regPath) => {
62-
const regExecuted = new RegExp(regPath).exec(window.location.pathname);
63-
const found = regExecuted !== null && regExecuted.length < 2;
64-
if (!betaIsAvailable && found) {
65-
betaIsAvailable = true;
66-
}
67-
});
6873
const isDoNotRenderPage =
6974
window.location.hostname === legacy.hostname &&
7075
window.location.pathname.startsWith("/communities");
7176
const goToBetaRoR2 =
7277
window.location.hostname === legacy.hostname &&
7378
(window.location.pathname === "/" ||
7479
window.location.pathname === "/package/");
75-
if ((betaIsAvailable && !isDoNotRenderPage) || goToBetaRoR2) {
80+
if (!isDoNotRenderPage || goToBetaRoR2) {
7681
const switchButton = document.createElement("button");
7782
if (window.location.hostname === beta.hostname) {
7883
switchButton.setAttribute(

packages/beta-switch/src/index.ts

Lines changed: 32 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const enabledPages = ["/communities", "c/[^/]+/?$"];
1+
// const enabledPages = ["/communities", "c/[^/]+/?$"];
22

33
type UrlStructure = {
44
protocol: string;
@@ -54,6 +54,13 @@ async function checkBetaRedirect(
5454
beta: UrlStructure,
5555
goToBetaRoR2: boolean
5656
) {
57+
const legacyOnlyPages = [
58+
"/settings",
59+
"/package/create",
60+
"c/[^/]+/p/[^/]+/[^/]+/wiki/?$",
61+
"c/[^/]+/p/[^/]+/[^/]+/source/?$",
62+
];
63+
5764
if (goToBetaRoR2) {
5865
// Don't include the search params as those differ in projects and are not handled gracefully
5966
window.location.assign(
@@ -63,31 +70,44 @@ async function checkBetaRedirect(
6370
);
6471
} else {
6572
let switchProject = legacy;
73+
let path = window.location.pathname;
6674

6775
if (window.location.hostname === beta.hostname) {
6876
switchProject = legacy;
6977
} else if (window.location.hostname === legacy.hostname) {
7078
switchProject = beta;
79+
legacyOnlyPages.forEach((regPath) => {
80+
const regExecuted = new RegExp(regPath).exec(window.location.pathname);
81+
const found = regExecuted !== null && regExecuted.length < 2;
82+
if (found) {
83+
path = "/communities";
84+
}
85+
});
86+
// legacyOnlyPages.forEach((lop) => {
87+
// if (window.location.pathname.startsWith(lop)) {
88+
// path = "/";
89+
// }
90+
// });
7191
}
7292

7393
// Don't include the search params as those differ in projects and are not handled gracefully
7494
window.location.assign(
7595
`${switchProject.protocol}${switchProject.hostname}${
7696
switchProject.port !== "" ? ":" : ""
77-
}${switchProject.port}${window.location.pathname}`
97+
}${switchProject.port}${path}`
7898
);
7999
}
80100
}
81101

82102
async function insertSwitchButton(legacy: UrlStructure, beta: UrlStructure) {
83-
let betaIsAvailable = false;
84-
enabledPages.forEach((regPath) => {
85-
const regExecuted = new RegExp(regPath).exec(window.location.pathname);
86-
const found = regExecuted !== null && regExecuted.length < 2;
87-
if (!betaIsAvailable && found) {
88-
betaIsAvailable = true;
89-
}
90-
});
103+
// let betaIsAvailable = false;
104+
// enabledPages.forEach((regPath) => {
105+
// const regExecuted = new RegExp(regPath).exec(window.location.pathname);
106+
// const found = regExecuted !== null && regExecuted.length < 2;
107+
// if (!betaIsAvailable && found) {
108+
// betaIsAvailable = true;
109+
// }
110+
// });
91111

92112
const isDoNotRenderPage =
93113
window.location.hostname === legacy.hostname &&
@@ -98,7 +118,7 @@ async function insertSwitchButton(legacy: UrlStructure, beta: UrlStructure) {
98118
(window.location.pathname === "/" ||
99119
window.location.pathname === "/package/");
100120

101-
if ((betaIsAvailable && !isDoNotRenderPage) || goToBetaRoR2) {
121+
if (!isDoNotRenderPage || goToBetaRoR2) {
102122
const switchButton = document.createElement("button");
103123

104124
// Add styles
@@ -125,7 +145,7 @@ async function insertSwitchButton(legacy: UrlStructure, beta: UrlStructure) {
125145
window.location.hostname === legacy.hostname ? "beta" : "legacy"
126146
}`;
127147

128-
// Insert button to desktop
148+
// Insert button to mobile
129149
if (
130150
window.location.hostname === beta.hostname ||
131151
window.location.pathname.startsWith("/communities")

0 commit comments

Comments
 (0)