-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
SOROKA-138: cards layout
- Loading branch information
Showing
14 changed files
with
196 additions
and
42 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import { CALENDAR_TYPE, PROPERTIES_NAMES } from "../utils/constants"; | ||
// @ts-ignore | ||
import GregorianDate from "ilib/lib/GregorianDate"; | ||
// @ts-ignore | ||
import JulianDate from "ilib/lib/JulianDate"; | ||
// @ts-ignore | ||
import DateFmt from "ilib/lib/DateFmt"; | ||
import { PropertiesParserProps } from "./PropertiesParser"; | ||
|
||
const fromJDJulian = (julianday: number) => { | ||
const dateFormat = new DateFmt({ template: "dd.MM.yyyy", calendar: "julian", timezone: "GMT" }); | ||
return dateFormat.format(new JulianDate({ julianday, timezone: "GMT" })); | ||
}; | ||
|
||
const fromJDGregorian = (julianday: number) => { | ||
const dateFormat = new DateFmt({ template: "dd.MM.yyyy", timezone: "GMT" }); | ||
return dateFormat.format(new GregorianDate({ julianday, timezone: "GMT" })); | ||
}; | ||
|
||
const DatePropertyParser = ({ property }: PropertiesParserProps) => { | ||
const data = JSON.parse(property.data)[0]; | ||
if (data.calendar === CALENDAR_TYPE.STRING) { | ||
return ( | ||
<p> | ||
{`${PROPERTIES_NAMES[property.propertyName]}: `} | ||
|
||
{data.startContext ? `${data.startContext} (${fromJDGregorian(data.startJD)})` : fromJDGregorian(data.startJD)} | ||
{data.endJD | ||
? data.endContext | ||
? `- ${data.endContext} (${fromJDGregorian(data.endJD)})` | ||
: `- ${fromJDGregorian(data.endJD)}` | ||
: ""} | ||
</p> | ||
); | ||
} else if (data.calendar === CALENDAR_TYPE.JULIAN) { | ||
return ( | ||
<p> | ||
{`${PROPERTIES_NAMES[property.propertyName]}:`}{" "} | ||
{`${fromJDJulian(data.startJD)} ${data.endJD && "- " + fromJDJulian(data.endJD)} (по старому стилю)`} | ||
</p> | ||
); | ||
} | ||
return ( | ||
<p> | ||
{`${PROPERTIES_NAMES[property.propertyName]}:`}{" "} | ||
{`${fromJDGregorian(data.startJD)} ${data.endJD && "- " + fromJDGregorian(data.endJD)}`} | ||
</p> | ||
); | ||
}; | ||
|
||
export default DatePropertyParser; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { PROPERTIES_NAMES } from "../utils/constants"; | ||
import { PropertiesParserProps } from "./PropertiesParser"; | ||
|
||
const GeoPropertyParser = ({ property }: PropertiesParserProps) => { | ||
return ( | ||
<div>{`${PROPERTIES_NAMES[property.propertyName]}: ${JSON.parse(property.data)[0].location.coordinates[0]}, ${ | ||
JSON.parse(property.data)[0].location.coordinates[1] | ||
}`}</div> | ||
); | ||
}; | ||
|
||
export default GeoPropertyParser; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import { CardProperty } from "../api/cards"; | ||
import { DATA_TYPES } from "../utils/constants"; | ||
import GeoPropertyParser from "./GeoPropertyParser"; | ||
import DatePropertyParser from "./DatePropertyParser"; | ||
import TextPropertyParser from "./TextPropertyParser"; | ||
import RichTextPropertyParser from "./RichTextPropertyParser"; | ||
|
||
export type PropertiesParserProps = { | ||
property: CardProperty; | ||
}; | ||
|
||
const PropertiesParser = ({ property }: PropertiesParserProps) => { | ||
const dataType = property.propertyDataType; | ||
switch (dataType) { | ||
case DATA_TYPES.TEXT: | ||
return <TextPropertyParser property={property} />; | ||
case DATA_TYPES.RICH_TEXT: | ||
return <RichTextPropertyParser property={property} />; | ||
case DATA_TYPES.JULIAN_DATE: | ||
return <DatePropertyParser property={property} />; | ||
case DATA_TYPES.GEO_POINT: | ||
return <GeoPropertyParser property={property} />; | ||
case DATA_TYPES.MEDIA: | ||
return <div>в разработке</div>; | ||
default: | ||
return <span>Неизвестное свойство</span>; | ||
} | ||
}; | ||
|
||
export default PropertiesParser; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { PROPERTIES_NAMES } from "../utils/constants"; | ||
import { PropertiesParserProps } from "./PropertiesParser"; | ||
|
||
const RichTextPropertyParser = ({ property }: PropertiesParserProps) => { | ||
return ( | ||
<p> | ||
{`${PROPERTIES_NAMES[property.propertyName]}: `}{" "} | ||
<span dangerouslySetInnerHTML={{ __html: property.data.slice(1, -1) }}></span> | ||
</p> | ||
); | ||
}; | ||
|
||
export default RichTextPropertyParser; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import { PROPERTIES_NAMES } from "../utils/constants"; | ||
import { PropertiesParserProps } from "./PropertiesParser"; | ||
|
||
const TextPropertyParser = ({ property }: PropertiesParserProps) => { | ||
return <p>{`${PROPERTIES_NAMES[property.propertyName]}: ${JSON.parse(property.data).value}`}</p>; | ||
}; | ||
|
||
export default TextPropertyParser; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
export const DATA_TYPES = { | ||
GEO_POINT: "GEO_POINT", | ||
RICH_TEXT: "RICH_TEXT", | ||
JULIAN_DATE: "JULIAN_DATE", | ||
MEDIA: "MEDIA", | ||
TEXT: "TEXT" | ||
}; | ||
|
||
export const CALENDAR_TYPE = { | ||
GREGORIAN: 1, | ||
JULIAN: 2, | ||
STRING: 3 | ||
}; | ||
|
||
export const PROPERTIES_NAMES: { [key: string]: string } = { | ||
unknownProperty: "Неизвестное свойство", | ||
address: "Адрес", | ||
legalName: "Юридическое название", | ||
artisticText: "Художественный текст", | ||
tags: "Теги", | ||
sources: "Источники", | ||
quote: "Цитата", | ||
julianDate: "Дата", | ||
geoPoint: "Гео-точка", | ||
annotation: "Аннотация", | ||
media: "Медиа", | ||
bibliography: "Библиографическое описание", | ||
copyrightHolder: "Правообладатель", | ||
creationPlace: "Место создания", | ||
creator: "Создатель", | ||
family: "Родители (семья)", | ||
format: "Формат", | ||
originalText: "Оригинальный текст", | ||
participants: "Участники", | ||
profession: "Профессия", | ||
refutation: "Опровержение", | ||
socialNetworks: "Социальные сети", | ||
storage: "Место хранения", | ||
url: "URL" | ||
}; |