Skip to content

Commit

Permalink
feat: automatically detect hour format
Browse files Browse the repository at this point in the history
  • Loading branch information
stonith404 committed Oct 16, 2022
1 parent 13d6f05 commit 4e3f6be
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 24 deletions.
1 change: 0 additions & 1 deletion frontend/.env.example
@@ -1,4 +1,3 @@
SHOW_HOME_PAGE=true
ALLOW_REGISTRATION=true
MAX_FILE_SIZE=1000000000
TWELVE_HOUR_TIME=false
1 change: 0 additions & 1 deletion frontend/next.config.js
Expand Up @@ -6,7 +6,6 @@ const nextConfig = {
SHOW_HOME_PAGE: process.env.SHOW_HOME_PAGE,
MAX_FILE_SIZE: process.env.MAX_FILE_SIZE,
BACKEND_URL: process.env.BACKEND_URL,
TWELVE_HOUR_TIME: process.env.TWELVE_HOUR_TIME
}
}

Expand Down
16 changes: 3 additions & 13 deletions frontend/src/components/share/CreateUploadModalBody.tsx
@@ -1,8 +1,8 @@
import {
Accordion,
Button,
Col,
Checkbox,
Col,
Grid,
NumberInput,
PasswordInput,
Expand All @@ -13,13 +13,10 @@ import {
} from "@mantine/core";
import { useForm, yupResolver } from "@mantine/form";
import { useModals } from "@mantine/modals";
import moment from "moment";
import * as yup from "yup";
import shareService from "../../services/share.service";
import { ShareSecurity } from "../../types/share.type";
import moment from "moment";
import getConfig from "next/config";

const { publicRuntimeConfig } = getConfig();

const PreviewExpiration = ({ form }: { form: any }) => {
const value = form.values.never_expires
Expand All @@ -34,14 +31,7 @@ const PreviewExpiration = ({ form }: { form: any }) => {
)
.toDate();

if (publicRuntimeConfig.TWELVE_HOUR_TIME === "true")
return `This share will expire on ${moment(expirationDate).format(
"MMMM Do YYYY, h:mm a"
)}`;
else
return `This share will expire on ${moment(expirationDate).format(
"MMMM DD YYYY, HH:mm"
)}`;
return `This share will expire on ${moment(expirationDate).format("LLL")}`;
};

const CreateUploadModalBody = ({
Expand Down
8 changes: 3 additions & 5 deletions frontend/src/components/upload/showCompletedUploadModal.tsx
Expand Up @@ -62,11 +62,9 @@ const Body = ({ share }: { share: Share }) => {
{/* If our share.expiration is timestamp 0, show a different message */}
{moment(share.expiration).unix() === 0
? "This share will never expire."
: `This share will expire on ${
publicRuntimeConfig.TWELVE_HOUR_TIME === "true"
? moment(share.expiration).format("MMMM Do YYYY, h:mm a")
: moment(share.expiration).format("MMMM DD YYYY, HH:mm")
}`}
: `This share will expire on ${moment(share.expiration).format(
"LLL"
)}`}
</Text>

<Button
Expand Down
6 changes: 2 additions & 4 deletions frontend/src/pages/account/shares.tsx
Expand Up @@ -14,6 +14,7 @@ import { useClipboard } from "@mantine/hooks";
import { useModals } from "@mantine/modals";
import { NextLink } from "@mantine/next";
import moment from "moment";
import getConfig from "next/config";
import { useRouter } from "next/router";
import { useEffect, useState } from "react";
import { TbLink, TbTrash } from "react-icons/tb";
Expand All @@ -22,7 +23,6 @@ import useUser from "../../hooks/user.hook";
import shareService from "../../services/share.service";
import { MyShare } from "../../types/share.type";
import toast from "../../utils/toast.util";
import getConfig from "next/config";

const { publicRuntimeConfig } = getConfig();

Expand Down Expand Up @@ -77,9 +77,7 @@ const MyShares = () => {
<td>
{moment(share.expiration).unix() === 0
? "Never"
: publicRuntimeConfig.TWELVE_HOUR_TIME === "true"
? moment(share.expiration).format("MMMM Do YYYY, h:mm a")
: moment(share.expiration).format("MMMM DD YYYY, HH:mm")}
: moment(share.expiration).format("LLL")}
</td>
<td>
<Group position="right">
Expand Down

0 comments on commit 4e3f6be

Please sign in to comment.