Makes RelativeTimestamp default to not showing the future (#38689)
This commit is contained in:
7 files changed
+12
-22
No files matched your search
@@ -23,16 +23,16 @@ export const RelativeTimestamp: FC<{
|
||||
timestamp: string;
|
||||
long?: boolean;
|
||||
noTime?: boolean;
|
||||
noFuture?: boolean;
|
||||
}> = ({ timestamp, long = false, noTime = false, noFuture = false }) => {
|
||||
hasFuture?: boolean;
|
||||
}> = ({ timestamp, long = false, noTime = false, hasFuture = false }) => {
|
||||
const intl = useIntl();
|
||||
|
||||
const [now, setNow] = useState(() => Date.now());
|
||||
|
||||
const date = useMemo(() => {
|
||||
const date = new Date(timestamp);
|
||||
return noFuture ? new Date(Math.min(date.getTime(), now)) : date;
|
||||
}, [noFuture, now, timestamp]);
|
||||
return !hasFuture ? new Date(Math.min(date.getTime(), now)) : date;
|
||||
}, [hasFuture, now, timestamp]);
|
||||
const ts = date.getTime();
|
||||
|
||||
useEffect(() => {
|
||||
|
||||
+3
-3
@@ -11,7 +11,7 @@ const meta = {
|
||||
timestamp: new Date(Date.now() - DAY * 3).toISOString(),
|
||||
long: false,
|
||||
noTime: false,
|
||||
noFuture: false,
|
||||
hasFuture: false,
|
||||
},
|
||||
argTypes: {
|
||||
timestamp: {
|
||||
@@ -44,10 +44,10 @@ export const DateOnly: Story = {
|
||||
},
|
||||
};
|
||||
|
||||
export const NoFuture: Story = {
|
||||
export const HasFuture: Story = {
|
||||
args: {
|
||||
timestamp: new Date(Date.now() + DAY * 3).toISOString(),
|
||||
noFuture: true,
|
||||
hasFuture: true,
|
||||
},
|
||||
};
|
||||
|
||||
|
||||
Reference in new issue
Block a user