Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/display git sha on page in previewdev environments #107

Merged
34 changes: 33 additions & 1 deletion pages/_app.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import '../styles/globals.css';

import { useMediaQuery } from '@mui/material';
import GitHub from '@mui/icons-material/GitHub';
import { Card, IconButton, Tooltip, useMediaQuery } from '@mui/material';
import { createTheme, ThemeProvider } from '@mui/material/styles';
import { Analytics } from '@vercel/analytics/react';
import type { AppProps } from 'next/app';
Expand All @@ -9,6 +10,14 @@ import React from 'react';

function MyApp({ Component, pageProps }: AppProps) {
const prefersDarkMode = useMediaQuery('(prefers-color-scheme: dark)');

const showGitInfo =
typeof process.env.NEXT_PUBLIC_VERCEL_ENV !== 'undefined' &&
process.env.NEXT_PUBLIC_VERCEL_ENV === 'preview' &&
typeof process.env.NEXT_PUBLIC_VERCEL_GIT_COMMIT_SHA !== 'undefined' &&
process.env.NEXT_PUBLIC_VERCEL_GIT_COMMIT_SHA !== '';
const darkModeElevation = prefersDarkMode ? 3 : 1;

const muiTheme = createTheme({
palette: {
mode: prefersDarkMode ? 'dark' : 'light',
Expand All @@ -28,6 +37,29 @@ function MyApp({ Component, pageProps }: AppProps) {
<Component {...pageProps} />
</ThemeProvider>
<Analytics />
{showGitInfo ? (
<>
<Card
className="w-fit h-fit bg-light fixed bottom-2 right-2 rounded-full"
elevation={darkModeElevation}
>
<Tooltip title="Open GitHub commit for this instance">
<a
href={
'https://github.com/UTDNebula/utd-trends/commit/' +
process.env.NEXT_PUBLIC_VERCEL_GIT_COMMIT_SHA
}
rel="noopener noreferrer"
target="_blank"
>
<IconButton size="large">
<GitHub className="fill-dark text-3xl" />
</IconButton>
</a>
</Tooltip>
</Card>
</>
) : null}
</>
);
}
Expand Down
4 changes: 2 additions & 2 deletions pages/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { tooltipClasses, TooltipProps } from '@mui/material/Tooltip';
import type { NextPage } from 'next';
import Head from 'next/head';
import { useRouter } from 'next/router';
import React, { useEffect, useState } from 'react';
import React, { useEffect } from 'react';

import { SplashPageSearchBar } from '../components/common/SplashPageSearchBar/splashPageSearchBar';
import { LogoIcon } from '../components/icons/LogoIcon/logoIcon';
Expand All @@ -16,7 +16,7 @@ import searchQueryLabel from '../modules/searchQueryLabel/searchQueryLabel';

const TransparentTooltip = styled(({ className, ...props }: TooltipProps) => (
<Tooltip {...props} classes={{ popper: className }} />
))(({ theme }) => ({
))(() => ({
[`& .${tooltipClasses.tooltip}`]: {
backgroundColor: 'transparent',
maxWidth: 'none',
Expand Down