forked from Sefaria/Sefaria-Mobile
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Story.js
147 lines (129 loc) · 4.66 KB
/
Story.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
'use strict';
import React, { useContext } from 'react';
import PropTypes from 'prop-types';
import {
View,
} from 'react-native';
import {
SaveButton,
SimpleInterfaceBlock,
SimpleContentBlock,
SimpleLinkedBlock,
ProfileListing,
HebrewInEnglishText,
} from './Misc';
import styles from './Styles';
import { GlobalStateContext, getTheme } from './StateManager';
import { useGlobalState, useRtlFlexDir } from './Hooks';
const sheetPropType = PropTypes.shape({
publisher_id: PropTypes.number,
publisher_name: PropTypes.string,
publisher_url: PropTypes.string,
publisher_image:PropTypes.string,
publisher_position: PropTypes.string,
publisher_organization: PropTypes.string,
publisher_followed: PropTypes.bool,
sheet_id: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
sheet_title: PropTypes.string,
sheet_summary: PropTypes.string,
});
const textPropType = PropTypes.shape({
"ref": PropTypes.string.isRequired,
"heRef": PropTypes.string.isRequired,
"en": PropTypes.string.isRequired,
"he": PropTypes.string.isRequired,
});
const bilingualPropType = PropTypes.shape({
en: PropTypes.string.isRequired,
he: PropTypes.string.isRequired,
});
/****************************
* *
* Pieces *
* *
*****************************/
// todo: if we don't want the monopoly card effect, this component isn't needed. // style={{"borderColor": cardColor || "#18345D"}}>
const StoryFrame = ({extraStyles, children}) => (
<View style={extraStyles}>
{children}
</View>
);
StoryFrame.propTypes = {
cls: PropTypes.string, // Story type as class name
cardColor: PropTypes.string
};
const StoryTitleBlock = ({ he, en, children, onClick }) => {
const { interfaceLanguage } = useContext(GlobalStateContext);
const SBlock = onClick ? SimpleLinkedBlock : SimpleInterfaceBlock;
const isHeb = interfaceLanguage === 'hebrew';
return (
<View style={{flex: 1}}>
<SBlock he={he} en={en} extraStyles={[styles.topicSourceTitle, isHeb ? styles.he : styles.en]} onClick={onClick} />
{children}
</View>
);
};
const ColorBarBox = ({tref, children}) => {
const { interfaceLanguage } = useContext(GlobalStateContext);
const langStyle = interfaceLanguage == 'hebrew' ? styles.colorBarBoxHebrew : styles.colorBarBoxEnglish;
return (<View style={[langStyle, {"borderColor": Sefaria.palette.refColor(tref)}]}>{children}</View>);
};
const StoryBodyBlock = ({en, he}) => <SimpleContentBlock en={en} he={he}/>;
const SheetBlock = ({sheet, compact, cozy, smallfonts, isTitle, showToast, onClick, extraStyles }) => {
const { theme, interfaceLanguage } = useGlobalState();
const flexDirection = useRtlFlexDir(interfaceLanguage);
const historyItem = {
ref: "Sheet " + sheet.sheet_id,
sheet_title: sheet.sheet_title,
sheet_owner: sheet.publisher_name,
book: "Sheet",
is_sheet: true,
versions: {},
};
const isHeb = interfaceLanguage === 'hebrew';
const title = Sefaria.util.stripHtml(sheet.sheet_title);
return (
<View style={extraStyles}>
<SaveLine historyItem={historyItem} showToast={showToast} flexDirection={flexDirection} imageStyles={[{marginTop: -12}]}>
<StoryTitleBlock en={title} he={title} onClick={onClick} />
</SaveLine>
{(sheet.sheet_summary && !(compact || cozy))?<SimpleInterfaceBlock en={sheet.sheet_summary} he={sheet.sheet_summary}/>:null}
{cozy ? "" : (
<View style={{marginTop: 10}}>
<ProfileListing
image={sheet.publisher_image}
name={sheet.publisher_name}
organization={sheet.publisher_organization}
flexDirection={flexDirection}
/>
</View>
)}
</View>
);
};
SheetBlock.propTypes = {sheet: sheetPropType.isRequired};
const SaveLine = ({ children, historyItem, dref, versions={}, showToast, flexDirection="row", imageStyles=[] }) => (
<View style={[styles.saveLine, {flexDirection}]}>
{children}
<SaveButton
historyItem={historyItem || {ref: dref, versions, book: Sefaria.textTitleForRef(dref)}}
showToast={showToast}
extraStyles={imageStyles}
/>
</View>
);
SaveLine.propTypes = {
historyItem: PropTypes.object, // One or
dref: PropTypes.string, // the other
versions: PropTypes.object,
afterChildren: PropTypes.object,
};
export {
SheetBlock,
SaveLine,
StoryTitleBlock,
ColorBarBox,
StoryBodyBlock,
StoryFrame,
textPropType,
};