summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorArjun Satarkar <me@arjunsatarkar.net>2024-07-28 09:03:31 +0000
committerArjun Satarkar <me@arjunsatarkar.net>2024-07-28 09:03:31 +0000
commitbe1c517a29be2ca80a6d824d1ca0656c73cde1d3 (patch)
tree947e281f6dc437774f65f2b4cb3997716b81f3fd
parentcff1319621c80c4c836f5500946d073766f2a343 (diff)
downloadmediasync-be1c517a29be2ca80a6d824d1ca0656c73cde1d3.tar
mediasync-be1c517a29be2ca80a6d824d1ca0656c73cde1d3.tar.gz
mediasync-be1c517a29be2ca80a6d824d1ca0656c73cde1d3.zip
Discord activity: reduce code duplication
-rw-r--r--priv/discord_activity.html.eex8
-rw-r--r--priv/static/discordActivity.js6
2 files changed, 8 insertions, 6 deletions
diff --git a/priv/discord_activity.html.eex b/priv/discord_activity.html.eex
index 9dd0649..5cb8a68 100644
--- a/priv/discord_activity.html.eex
+++ b/priv/discord_activity.html.eex
@@ -75,11 +75,15 @@
</div>
<iframe src="<%= home_url %>" style="display: none;" class="at-home" name="activity-inner-iframe"></iframe>
<script>
+ const QUERY_PARAM_DISCORD_ACTIVITY_INNER = "<%= Mediasync.Constants.query_param_discord_activity_inner() %>";
const DISCORD_CLIENT_ID = "<%= Application.fetch_env!(:mediasync, :discord_client_id) %>";
- const ACCESS_TOKEN_URL = "/.proxy/discord_activity/access_token?<%= Mediasync.Constants.query_param_discord_activity_inner() %>";
+ const ACCESS_TOKEN_URL = `/.proxy/discord_activity/access_token?${QUERY_PARAM_DISCORD_ACTIVITY_INNER}`;
const HOME_URL = "<%= home_url %>";
+ const roomsForInstanceUrl = (instanceId) => {
+ return `/.proxy/discord_activity/rooms_for_instance?${QUERY_PARAM_DISCORD_ACTIVITY_INNER}&instance_id=${instanceId}`;
+ };
const roomUrl = (roomId) => {
- return `/.proxy/room/${roomId}?<%= Mediasync.Constants.query_param_discord_activity_inner() %>`;
+ return `/.proxy/room/${roomId}?${QUERY_PARAM_DISCORD_ACTIVITY_INNER}`;
};
</script>
<script src="/static/discord-embedded-app-sdk/Discord.js" type="module"></script>
diff --git a/priv/static/discordActivity.js b/priv/static/discordActivity.js
index 873bdde..f00ec1d 100644
--- a/priv/static/discordActivity.js
+++ b/priv/static/discordActivity.js
@@ -11,9 +11,7 @@ const updateInstanceRoomInfo = () => {
contentEl.replaceChildren(defaultContents);
}
- fetch(
- `/.proxy/discord_activity/rooms_for_instance?discord_activity_inner&instance_id=${discordSdk.instanceId}`,
- )
+ fetch(roomsForInstanceUrl(discordSdk.instanceId))
.then((response) => {
if (!response.ok) {
throw new Error(`Fetching instance room info failed with status code ${response.status}`);
@@ -35,7 +33,7 @@ const updateInstanceRoomInfo = () => {
form.style.display = "inline";
const hiddenInput = form.appendChild(document.createElement("input"));
hiddenInput.type = "hidden";
- hiddenInput.name = "discord_activity_inner";
+ hiddenInput.name = QUERY_PARAM_DISCORD_ACTIVITY_INNER;
const submitInput = form.appendChild(document.createElement("input"));
submitInput.type = "submit";
submitInput.value = "join";