Skip to content

Commit

Permalink
Remove unneeded Vite env wrapper
Browse files Browse the repository at this point in the history
  • Loading branch information
Willdotwhite committed Jan 14, 2024
1 parent ea58d77 commit 16f8ec3
Show file tree
Hide file tree
Showing 10 changed files with 46 additions and 25 deletions.
2 changes: 1 addition & 1 deletion ui/src/api/apiRequest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ export async function apiRequest<T>(
options["body"] = JSON.stringify(apiRequestOptions.body);
}

const res = await fetch(`${importMetaEnv().VITE_API_URL}${path}`, options);
const res = await fetch(`${import.meta.env.VITE_API_URL}${path}`, options);
if (!res.ok) {
if (res.status === 401) {
dependencies.logout();
Expand Down
4 changes: 1 addition & 3 deletions ui/src/api/login.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import {importMetaEnv} from "../common/utils/importMeta";

const LOGIN_URL = `${importMetaEnv().VITE_API_URL}/login`;
const LOGIN_URL = `${import.meta.env.VITE_API_URL}/login`;

export const LOCAL_STORAGE_RETURN_AUTH_PATH_KEY = "auth_redirect_path";

Expand Down
6 changes: 0 additions & 6 deletions ui/src/common/utils/importMeta.ts

This file was deleted.

33 changes: 33 additions & 0 deletions ui/src/env.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/// <reference types="vite/client" />

interface ImportMetaEnv {
/** REQUIRED ENVIRONMENT VARIABLES */
// URL of the API which serves data
VITE_API_URL: string;

// Human-readable name of the Discord group running this event (e.g. 'GTMK')
VITE_DISCORD_NAME: string;

// Invite URL for users to join your discord server
VITE_DISCORD_INVITE_URL: string;

// Human-readable name of the game jam being run
VITE_JAM_NAME: string;

// URL of the game jame for people to join/view
VITE_JAM_URL: string;

/** OPTIONAL ENVIRONMENT VARIABLES */
// String of when the event starts and website automatically becomes active
VITE_JAM_START: string;

// String of when the event ends and website automatically becomes inactive
VITE_JAM_END: string;

// Sentry.io DSN URL for analytics tracking
VITE_SENTRY_DSN: string;
}

interface importMeta {
readonly env: ImportMetaEnv
}
9 changes: 4 additions & 5 deletions ui/src/pages/about/About.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import React from "react";
import {Link} from "react-router-dom";
import {importMetaEnv} from "../../common/utils/importMeta.ts";

const discordGroupName = importMetaEnv().VITE_DISCORD_NAME;
const discordGroupInviteUrl = importMetaEnv().VITE_DISCORD_INVITE_URL;
const jamName = importMetaEnv().VITE_JAM_NAME;
const jamUrl = importMetaEnv().VITE_JAM_URL;
const discordGroupName = import.meta.env.VITE_DISCORD_NAME;
const discordGroupInviteUrl = import.meta.env.VITE_DISCORD_INVITE_URL;
const jamName = import.meta.env.VITE_JAM_NAME;
const jamUrl = import.meta.env.VITE_JAM_URL;

export const About: React.FC = () => {
return (
Expand Down
3 changes: 1 addition & 2 deletions ui/src/pages/components/Footer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@ import React from "react";
import discordIcon from "../../assets/icons/social/discord.svg";
import gmtkIcon from "../../assets/icons/social/gmtk-letter-logo.png";
import youtubeIcon from "../../assets/icons/social/youtube.svg";
import {importMetaEnv} from "../../common/utils/importMeta.ts";

const jamUrl = importMetaEnv().VITE_JAM_URL;
const jamUrl = import.meta.env.VITE_JAM_URL;

const Footer: React.FC = () => {
const footerImages = [
Expand Down
3 changes: 1 addition & 2 deletions ui/src/pages/home/Home.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import {useEffect, useState} from "react";
import {PostTile} from "../../common/components/PostTile.tsx";
import {Onboarding} from "./components/Onboarding.tsx";
import {SiteIntro} from "./components/SiteIntro.tsx";
import {importMetaEnv} from "../../common/utils/importMeta.ts";
import {useAuth} from "../../api/AuthContext.tsx";
import {Post} from "../../common/models/post.ts";

Expand All @@ -20,7 +19,7 @@ export const Home: React.FC = () => {
const path = searchParams.get('bookmarked') === "true" ? "posts/favourites" : "posts"
searchParams.delete('bookmarked')

const url = new URL(path + "?" + searchParams.toString(), importMetaEnv().VITE_API_URL)
const url = new URL(path + "?" + searchParams.toString(), import.meta.env.VITE_API_URL)
const init: RequestInit = {method: "GET", headers: {"Content-Type": "application/json"}}

if (token) {
Expand Down
5 changes: 2 additions & 3 deletions ui/src/pages/home/components/Onboarding.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import React from "react";
import {importMetaEnv} from "../../../common/utils/importMeta.ts";
import {useAuth} from "../../../api/AuthContext.tsx";
import {useUserInfo} from "../../../api/userInfo.ts";
import {login} from "../../../api/login.ts";

const discordGroupName = importMetaEnv().VITE_DISCORD_NAME;
const discordGroupInviteUrl = importMetaEnv().VITE_DISCORD_INVITE_URL;
const discordGroupName = import.meta.env.VITE_DISCORD_NAME;
const discordGroupInviteUrl = import.meta.env.VITE_DISCORD_INVITE_URL;

export const Onboarding: React.FC = () => {
const isLoggedIn = Boolean(useAuth());
Expand Down
5 changes: 2 additions & 3 deletions ui/src/pages/home/components/SiteIntro.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import { useEffect, useState } from "react";
import { importMetaEnv } from "../../../common/utils/importMeta.ts";

const jamName = importMetaEnv().VITE_JAM_NAME;
const jamStartDate = new Date(importMetaEnv().VITE_JAM_START);
const jamName = import.meta.env.VITE_JAM_NAME;
const jamStartDate = new Date(import.meta.env.VITE_JAM_START);

// Set the date we're counting down to
export const SiteIntro = () => {
Expand Down
1 change: 1 addition & 0 deletions ui/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import react from '@vitejs/plugin-react-swc'
// https://vitejs.dev/config/
export default defineConfig(() => {
return {
envDir: "../",
server: {
host: "0.0.0.0",
port: 3000,
Expand Down

0 comments on commit 16f8ec3

Please sign in to comment.