Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions html/src/Components/ShareComponent.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ActionIcon, ActionIconGroup, Anchor, Box, Button, CopyButton, Flex, Group, Paper, Popover, Progress, Stack, Text, Tooltip, useMantineTheme } from "@mantine/core";
import { humanFileSize, prettyfiedCount, Share } from "../hupload";
import { humanFileSize, prettyfiedCount, Share, ShareDefaults } from "../hupload";
import { Link } from "react-router-dom";
import classes from './ShareComponent.module.css';
import { IconClock, IconDots, IconLink, IconTrash } from "@tabler/icons-react";
Expand Down Expand Up @@ -48,6 +48,17 @@ export function ShareComponent(props: {share: Share}) {
})
}

const renew = () => {
H.get('/defaults').then((r) => {
const d = r as ShareDefaults
const shareStartDate = new Date(share.created).getTime()
const shareEndDate = Date.now() + d.validity*1000*60*60*24
const newValidity = Math.ceil((shareEndDate-shareStartDate) / 1000 / 60 / 60 / 24)

setNewOptions({ ...newOptions, validity: newValidity})
})
}

const linkify = (text: string) => {
const urlRegex = /^https?:\/\/(?:www\.)?[-a-zA-Z0-9@:%._+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b(?:[-a-zA-Z0-9()@:%_+.~#?&/=]*)$/
if (urlRegex.test(text)) {
Expand Down Expand Up @@ -172,7 +183,7 @@ export function ShareComponent(props: {share: Share}) {
<IconDots style={{ width: '70%', height: '70%' }} stroke={1.5}/>
</ActionIcon>
</Tooltip>
<ShareEditor buttonTitle={t("update")} onChange={setNewOptions} onClick={updateShare} options={newOptions}/>
<ShareEditor buttonTitle={t("update")} onChange={setNewOptions} onClick={updateShare} onRenew={renew} options={newOptions}/>
</ResponsivePopover>
</ActionIconGroup>
</Flex>
Expand Down
38 changes: 26 additions & 12 deletions html/src/Components/ShareEditor.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Share } from "@/hupload";
import { ActionIcon, Box, BoxComponentProps, Button, Flex, Input, NumberInput, rem, SegmentedControl, Stack, TextInput, useMantineTheme } from "@mantine/core";
import { IconChevronLeft, IconChevronRight } from "@tabler/icons-react";
import { ActionIcon, Box, BoxComponentProps, Button, Flex, Group, Input, NumberInput, rem, SegmentedControl, Stack, TextInput, Tooltip, useMantineTheme } from "@mantine/core";
import { IconChevronLeft, IconChevronRight, IconClockPlus } from "@tabler/icons-react";
import { useDisclosure, useMediaQuery, useUncontrolled } from "@mantine/hooks";
import classes from './ShareEditor.module.css';
import { MarkDownEditor } from "./MarkdownEditor";
Expand All @@ -10,6 +10,7 @@ import { useTranslation } from "react-i18next";
interface ShareEditorProps {
onChange: (options: Share["options"]) => void;
onClick: () => void;
onRenew?: () => void;
close?: () => void;
options: Share["options"];
buttonTitle: string;
Expand All @@ -18,7 +19,7 @@ interface ShareEditorProps {
export function ShareEditor(props: ShareEditorProps&BoxComponentProps) {
const { t } = useTranslation()
// Initialize props
const { onChange, onClick, close, buttonTitle } = props;
const { onChange, onClick, onRenew, close, buttonTitle } = props;

// Initialize state
const [options, setOptions] = useUncontrolled({
Expand All @@ -40,6 +41,9 @@ export function ShareEditor(props: ShareEditorProps&BoxComponentProps) {
onChange(o)
}

const renew = () => {
onRenew && onRenew();
}
return (
<Box miw={rem(200)} h="100%" w="100%" display={"flex"}>
<Flex direction="column" gap="sm" w="100%" justify={"space-between"}>
Expand Down Expand Up @@ -73,15 +77,25 @@ export function ShareEditor(props: ShareEditorProps&BoxComponentProps) {
</Input.Wrapper>

{/* Share validity */}
<NumberInput
label={t("validity")}
description={t("number_of_days_the_share_is_valid")}
value={options.validity}
min={0}
classNames={{wrapper: classes.numberInput}}
onChange={(v) => { notifyChange({...options, validity:v as number}); }}
/>

<NumberInput
label={t("validity")}
description={t("number_of_days_the_share_is_valid")}
value={options.validity}
min={0}
classNames={{wrapper: classes.numberInput}}
onChange={(v) => { notifyChange({...options, validity:v as number}); }}
inputContainer={(children) => (
<>
<Group gap="xs" align="center">
{children}
<Tooltip label={t("renew_share")} withArrow>
<ActionIcon mt="xs" variant="light" radius="xl" onClick={renew} >
<IconClockPlus style={{ width: '70%', height: '70%' }} stroke={1.5}/>
</ActionIcon>
</Tooltip>
</Group>
</>)}
/>
{/* Share description */}
<TextInput label={t("description")} value={options.description}
onChange={(v) => { notifyChange({...options, description:v.target.value}); }}
Expand Down
2 changes: 1 addition & 1 deletion html/src/hupload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export interface Message {
}

export interface ShareDefaults {
expiration: number;
validity: number;
exposure: string;
}

Expand Down
2 changes: 2 additions & 0 deletions html/src/i18n/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ i18n
send: "Send",
receive: "Receive",
both: "Both",
renew_share: "Renew validity",

validity: "Validity",
number_of_days_the_share_is_valid: "Number of days the share is valid. 0 is unlimited.",
Expand Down Expand Up @@ -153,6 +154,7 @@ i18n
send: "Envoyer",
receive: "Reçevoir",
both: "Les deux",
renew_share: "Étendre la validité",

validity: "Expiration",
number_of_days_the_share_is_valid: "Nombre de jours pendant lesquels le partage est valide. 0 signifie illimité.",
Expand Down