Skip to content

Commit

Permalink
Update packages and create a config API
Browse files Browse the repository at this point in the history
  • Loading branch information
joestump committed Oct 18, 2024
1 parent 79425ec commit 259a2f8
Show file tree
Hide file tree
Showing 16 changed files with 6,286 additions and 8,242 deletions.
4 changes: 2 additions & 2 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
"editor.formatOnSave": true,
"editor.defaultFormatter": "dbaeumer.vscode-eslint",
"editor.codeActionsOnSave": {
"source.fixAll.eslint": true,
"source.fixAll.stylelint": true
"source.fixAll.eslint": "explicit",
"source.fixAll.stylelint": "explicit"
},
"typescript.preferences.importModuleSpecifier": "non-relative",
"css.validate": false,
Expand Down
23 changes: 23 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Use an official Node runtime as the base image
FROM node:20-alpine

# Set the working directory in the container
WORKDIR /app

# Copy package.json and package-lock.json
COPY package*.json ./

# Install project dependencies
RUN npm install

# Copy the rest of the application code
COPY . .

# Build the Next.js application
RUN npm run build

# Expose the port the app runs on (usually 3000 for Next.js)
EXPOSE 3000

# Start the application
CMD ["npm", "start"]
80 changes: 44 additions & 36 deletions components/Layout.tsx
Original file line number Diff line number Diff line change
@@ -1,46 +1,54 @@
import React from "react";
import { getTimeOfDay } from "../functions/common";
import { DOMAIN } from "../functions/constants";
import { Props } from "../interfaces";
import { NavMenu } from "./common";
import TitleHead from "./TitleHead";
import Head from "next/head";

const Layout = ({ children, title, token }: Props) => (
<div>
<TitleHead title={title}>
<meta
name="description"
content="The Reddit client for Silicon Valley. "
/>
<meta property="og:url" content={DOMAIN} />
<meta
property="og:description"
content="The Reddit client for Silicon Valley. "
/>
<meta property="og:image" content={`${DOMAIN}/reddium-mockup.png`} />
</TitleHead>
<header>
<nav className="flex items-center justify-center max-width-main mx-auto z-50 h-16 my-6 lg:mx-12 sm:mx-6">
<div className="flex-grow flex items-center">
<a href="/">
<div className="pr-4 nav-img h-8 flex flex-row items-center cursor-pointer sm:border-0">
<img className="h-full sm:h-6" src="reddium_symbol.svg" />
<h1 className="ml-4 site-name text-3xl tracking-tighter sm:hidden text-black">
Reddium
interface LayoutProps {
children: React.ReactNode;
title?: string;
token: string | null; // Adjust the type according to your token's actual type
}

const Layout = ({ children, title = "This is the default title", token }: LayoutProps) => {
return (
<div>
<Head>
<title>{title}</title>
<meta
name="description"
content="The Reddit client for Silicon Valley. "
/>
<meta property="og:url" content={DOMAIN} />
<meta
property="og:description"
content="The Reddit client for Silicon Valley. "
/>
<meta property="og:image" content={`${DOMAIN}/reddium-mockup.png`} />
</Head>
<header>
<nav className="flex items-center justify-center max-width-main mx-auto z-50 h-16 my-6 lg:mx-12 sm:mx-6">
<div className="flex-grow flex items-center">
<a href="/">
<div className="pr-4 nav-img h-8 flex flex-row items-center cursor-pointer sm:border-0">
<img className="h-full sm:h-6" src="reddium_symbol.svg" />
<h1 className="ml-4 site-name text-3xl tracking-tighter sm:hidden text-black">
Reddium
</h1>
</div>
</a>
<div className="pl-4">
<h1 className="font-bold text-lg leading-6 nav-greeting sm:hidden">
{getTimeOfDay()}
</h1>
</div>
</a>
<div className="pl-4">
<h1 className="font-bold text-lg leading-6 nav-greeting sm:hidden">
{getTimeOfDay()}
</h1>
</div>
</div>
<NavMenu token={token} />
</nav>
</header>
{children}
</div>
);
<NavMenu token={token} />
</nav>
</header>
{children}
</div>
);
};

export default Layout;
65 changes: 39 additions & 26 deletions components/common/index.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { zipObject } from "lodash";
import _ from 'lodash';
import React, { useEffect, useRef, useState } from "react";
import { getIntFromString, getTime, limitText } from "../../functions/common";
import { CLIENT_ID, DESC_MAX, REDIRECT_URI } from "../../functions/constants";
import { DropdownProps, Props } from "../../interfaces";
import { useConfig } from '../../lib/ConfigContext';

export const MidContainer = ({ children }: Props) => (
<div className="mid-container px-4 sm:px-0">{children}</div>
Expand Down Expand Up @@ -98,7 +99,7 @@ export const Dropdown = ({
className="dropdown-select w-48 max-w-full absolute z-10"
ref={dropdown}
>
{zipObject(paramKey, paramVal)[id].map((value: string, ind) => (
{_.zipObject(paramKey, paramVal)[id].map((value: string, ind) => (
<div
className="my-1 px-4 mx-1 p-2 cursor-pointer"
key={ind}
Expand Down Expand Up @@ -135,14 +136,18 @@ export const PostMetadata = ({
export const NavMenu = ({ token = "" }: any) => {
const [showSearch, setShowSearch] = useState(false);
const [searchTerm, setSearchTerm] = useState("");
const config = useConfig();

const newSearch = () => (window.location.href = `/search/?q=${searchTerm}`);

return (
<div className="items-center flex flex-row h-full justify-end">
<div className="flex flex-row items-center justify-end h-full">
<img
className="cursor-pointer p-1 mr-2 ml-3 sub-opacity-68 link-black-hover"
src="/search.svg"
onClick={() => setShowSearch(!showSearch)}
alt="Search"
/>
{showSearch ? (
<input
Expand All @@ -155,36 +160,44 @@ export const NavMenu = ({ token = "" }: any) => {
) : (
""
)}
<a
href="https://ko-fi.com/eightants"
target="_blank"
rel="noopener noreferrer"
>
<img
className="h-8 cursor-pointer p-1 ml-2 sub-opacity-68 link-black-hover"
src="/coffee.svg"
/>
</a>
{!config.REDDIUM_DISABLE_KOFI_LINK && (
<a
href="https://ko-fi.com/eightants"
target="_blank"
rel="noopener noreferrer"
>
<img
className="h-8 cursor-pointer p-1 ml-2 sub-opacity-68 link-black-hover"
src="/coffee.svg"
alt="Ko-fi"
/>
</a>
)}
{!config.REDDIUM_DISABLE_GITHUB_LINK && (
<a
href="https://github.com/eightants/reddium/"
target="_blank"
rel="noopener noreferrer"
>
<img
className="h-10 cursor-pointer p-1 ml-2 sub-opacity-68 link-black-hover hidden md:block"
src="/github.svg"
alt="GitHub"
/>
</a>
)}
</div>
{!config.REDDIUM_DISABLE_GITHUB_LINK && (
<a
href="https://github.com/eightants/reddium/"
target="_blank"
rel="noopener noreferrer"
>
<img
className="h-10 cursor-pointer p-1 ml-2 sub-opacity-68 link-black-hover hidden md:block"
src="/github.svg"
/>
<button className="md:hidden my-4 ml-4 p-1 px-3 sub-opacity-68 link-black-hover text-sm cursor-pointer max-w-full btn-outline-black rounded">
Star on GitHub
</button>
</a>
</div>
<a
href="https://github.com/eightants/reddium/"
target="_blank"
rel="noopener noreferrer"
>
<button className="md:hidden my-4 ml-4 p-1 px-3 sub-opacity-68 link-black-hover text-sm cursor-pointer max-w-full btn-outline-black rounded">
Star on GitHub
</button>
</a>
)}
{token != "" ? (
<ProfileOptions />
) : (
Expand Down
4 changes: 2 additions & 2 deletions functions/common.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { capitalize } from "lodash";
import _ from 'lodash';

const DAY_MILLISECONDS = 1000 * 60 * 60 * 24;
const HOUR_MILLISECONDS = 1000 * 60 * 60;
Expand Down Expand Up @@ -44,7 +44,7 @@ export function limitText(text: string, max: number) {
export const replaceGifv = (text: string) => text.replace(".gifv", ".gif");

export const unsplashCredits = (filename: string) =>
capitalize(filename.split("-").slice(0, -2).join(" "));
_.capitalize(filename.split("-").slice(0, -2).join(" "));

export const findThreadDepth = (root: any) =>
1 +
Expand Down
37 changes: 37 additions & 0 deletions lib/ConfigContext.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import React, { createContext, useContext, useState, useEffect } from 'react';

interface Config {
[key: string]: string;
}

const ConfigContext = createContext<Config | null>(null);

export const useConfig = () => {
const context = useContext(ConfigContext);
if (context === null) {
throw new Error('useConfig must be used within a ConfigProvider');
}
return context;
};

export const ConfigProvider: React.FC<React.PropsWithChildren<{}>> = ({ children }) => {
const [config, setConfig] = useState<Config | null>(null);

useEffect(() => {
fetch('/api/config')
.then(response => response.json())
.then(data => {
setConfig(data);
console.log('Fetched config:', data);
})
.catch(error => {
console.error('Error fetching config:', error);
});
}, []);

if (config === null) {
return <div>Loading configuration...</div>; // Or any loading indicator
}

return <ConfigContext.Provider value={config}>{children}</ConfigContext.Provider>;
};
2 changes: 1 addition & 1 deletion next-env.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
/// <reference types="next/image-types/global" />

// NOTE: This file should not be edited
// see https://nextjs.org/docs/basic-features/typescript for more information.
// see https://nextjs.org/docs/pages/building-your-application/configuring/typescript for more information.
6 changes: 6 additions & 0 deletions next.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,10 @@ module.exports = {
unoptimized: true,
domains: ["a.thumbs.redditmedia.com"],
},
publicRuntimeConfig: Object.keys(process.env).reduce((config, key) => {
if (key.startsWith('REDDIUM_')) {
config[key] = process.env[key];
}
return config;
}, {}),
};
Loading

0 comments on commit 259a2f8

Please sign in to comment.