[Glitch] Makes RelativeTimestamp default to not showing the future
Port e71d6fa344 to glitch-soc
Signed-off-by: Claire <claire.github-309c@sitedethib.com>
This commit is contained in:
1 parent
3072de056a
commit
3ed2f28301
7 files changed
+11
-19
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