Skip to content

Commit

Permalink
Children books
Browse files Browse the repository at this point in the history
  • Loading branch information
isdenmois committed Jul 1, 2019
1 parent c3af32d commit 5e4798e
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 2 deletions.
33 changes: 31 additions & 2 deletions src/screens/details/components/book-details.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ export class BookDetails extends React.Component<Props> {

{!!book.description && <BookDescriptionLine description={book.description} />}

{!!book.children.length && this.renderChildrenBooks()}

{!!book.parent.length && this.renderParentBooks()}
</ScrollView>
</View>
Expand Down Expand Up @@ -106,15 +108,42 @@ export class BookDetails extends React.Component<Props> {
<Text>ВХОДИТ В</Text>

{this.props.book.parent.map(book => (
<ViewLineTouchable key={book.id} onPress={() => this.openParent(book)} title={book.type} value={book.title} />
<ViewLineTouchable key={book.id} onPress={() => this.openBook(book)} title={book.type} value={book.title} />
))}
</View>
);
}

renderChildrenBooks() {
return (
<View style={s.parentBooks}>
<Text>СОДЕРЖИТ</Text>

{this.props.book.children.map(book => (
<ViewLineTouchable
key={book.id}
onPress={() => this.openBook(book)}
title={book.type}
value={this.getChildBookTitle(book)}
/>
))}
</View>
);
}

getChildBookTitle(book) {
if (book.year) {
return `${book.title} (${book.year})`;
}

return book.title;
}

openChangeStatus = () => this.props.navigation.navigate('/modal/change-status', { book: this.props.book });

openParent = book => this.props.navigation.push('Details', { bookId: book.id });
openBook(book) {
this.props.navigation.push('Details', { bookId: book.id });
}
}

const s = StyleSheet.create({
Expand Down
10 changes: 10 additions & 0 deletions src/services/api/fantlab/book.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export const mapBody = {
genre,
searchTitles,
parent,
children,
};

function editionCount(book) {
Expand Down Expand Up @@ -55,3 +56,12 @@ function parent(w) {
})),
).filter(p => p.id);
}

function children(w) {
return _.filter(w.children, c => +c.deep === 1 && c.work_id).map(c => ({
id: c.work_id,
title: c.work_name || c.work_name_alt || c.work_name_orig,
type: _.capitalize(c.work_type) || 'Другое',
year: c.work_year,
}));
}
7 changes: 7 additions & 0 deletions src/types/book-extended.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,10 @@ export interface ParentBook {
title: string;
type: string;
}

export interface ChildBook {
id: string;
title: string;
type: string;
year?: number;
}

0 comments on commit 5e4798e

Please sign in to comment.