Fix time formatting, add publish date to info page

This commit is contained in:
Piotr Rogowski 2022-10-18 15:53:41 +02:00
parent 99f36ed258
commit 69d1a88d35
No known key found for this signature in database
GPG Key ID: 4A842D702D9C6F8F
3 changed files with 17 additions and 6 deletions

View File

@ -35,6 +35,7 @@ import {
import { ProfilesRecord } from '../@types/pocketbase-types'; import { ProfilesRecord } from '../@types/pocketbase-types';
import { isEscape } from '../utils/keyboard/shortcuts'; import { isEscape } from '../utils/keyboard/shortcuts';
import { TunesRecordFull } from '../types/dbData'; import { TunesRecordFull } from '../types/dbData';
import { formatTime } from '../pocketbase';
const { useBreakpoint } = Grid; const { useBreakpoint } = Grid;
const { Text, Title } = Typography; const { Text, Title } = Typography;
@ -62,7 +63,7 @@ const Hub = () => {
author: (tune['@expand'] as { userProfile: ProfilesRecord }).userProfile.username, author: (tune['@expand'] as { userProfile: ProfilesRecord }).userProfile.username,
displacement: `${tune.displacement}l`, displacement: `${tune.displacement}l`,
aspiration: aspirationMapper[tune.aspiration], aspiration: aspirationMapper[tune.aspiration],
created: new Date(tune.created).toLocaleString(), published: formatTime(tune.updated),
stars: 0, stars: 0,
}))); })));
setIsLoading(false); setIsLoading(false);
@ -98,7 +99,7 @@ const Hub = () => {
<> <>
<Title level={5}>{tune.vehicleName}</Title> <Title level={5}>{tune.vehicleName}</Title>
<Space direction="vertical"> <Space direction="vertical">
<Text type="secondary">{tune.author}, {tune.created}</Text> <Text type="secondary">{tune.author}, {tune.published}</Text>
<Text>{tune.engineMake}, {tune.engineCode}, {tune.displacement}, {tune.cylindersCount} cylinders, {tune.aspiration}</Text> <Text>{tune.engineMake}, {tune.engineCode}, {tune.displacement}, {tune.cylindersCount} cylinders, {tune.aspiration}</Text>
<Text code>{tune.signature}</Text> <Text code>{tune.signature}</Text>
</Space> </Space>
@ -156,8 +157,8 @@ const Hub = () => {
}, },
{ {
title: 'Published', title: 'Published',
dataIndex: 'created', dataIndex: 'published',
key: 'created', key: 'published',
responsive: ['sm'], responsive: ['sm'],
}, },
{ {

View File

@ -21,6 +21,7 @@ import {
import Loader from '../components/Loader'; import Loader from '../components/Loader';
import { Routes } from '../routes'; import { Routes } from '../routes';
import { useAuth } from '../contexts/AuthContext'; import { useAuth } from '../contexts/AuthContext';
import { formatTime } from '../pocketbase';
const { Item } = Form; const { Item } = Form;
const rowProps = { gutter: 10 }; const rowProps = { gutter: 10 };
@ -67,16 +68,21 @@ const Info = ({ tuneData }: { tuneData: TuneDataState }) => {
<Divider>Details</Divider> <Divider>Details</Divider>
<Form> <Form>
<Row {...rowProps}> <Row {...rowProps}>
<Col span={24} sm={24}> <Col {...colProps}>
<Item> <Item>
<Input value={tuneData['@expand'].userProfile.username} addonBefore="Author" /> <Input value={tuneData['@expand'].userProfile.username} addonBefore="Author" />
</Item> </Item>
</Col> </Col>
<Col {...colProps}>
<Item>
<Input value={tuneData.signature} addonBefore="Signature" />
</Item>
</Col>
</Row> </Row>
<Row {...rowProps}> <Row {...rowProps}>
<Col span={24} sm={24}> <Col span={24} sm={24}>
<Item> <Item>
<Input value={tuneData.signature} addonBefore="Signature" /> <Input value={formatTime(tuneData.updated)} addonBefore="Published at" />
</Item> </Item>
</Col> </Col>
</Row> </Row>

View File

@ -17,8 +17,12 @@ const formatError = (error: any) => {
return message; return message;
}; };
// NOTE: PocketBase doesn't return ISO time, this may change here: https://github.com/pocketbase/pocketbase/issues/376
const formatTime = (time: string) => new Date(`${time}Z`).toLocaleString();
export { export {
API_URL, API_URL,
client, client,
formatError, formatError,
formatTime,
}; };