-
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.
- Loading branch information
Showing
16 changed files
with
676 additions
and
29 deletions.
There are no files selected for viewing
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
Binary file not shown.
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,2 @@ | ||
export * as bookModel from "./model"; | ||
export * from "./ui"; |
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 { combine, createEffect, createStore } from "effector"; | ||
import api from "shared/api"; | ||
import type { Book } from "shared/api/book"; | ||
|
||
export const getBookListFx = createEffect((cursor?: string) => api.book.list(cursor)); | ||
export const $getBookListFxLoading = getBookListFx.pending; | ||
|
||
export const $books = createStore<Book[]>([]) | ||
.on(getBookListFx.doneData, (_, book) => book.data); | ||
|
||
export const $booksList = combine($books, (books) => Object.values(books)); | ||
export const $booksListEmpty = $booksList.map((list) => list.length === 0); |
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 { Row } from "antd"; | ||
import { Book } from "shared/api/book"; | ||
|
||
export interface BookRowProps { | ||
data: Book | ||
} | ||
|
||
export const BookRow: React.FC<BookRowProps> = ({ data }) => ( | ||
<Row> | ||
{data.title} | ||
</Row> | ||
); |
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 @@ | ||
export * from "./book-row"; |
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 |
---|---|---|
@@ -1,7 +1,61 @@ | ||
import { Layout } from "antd"; | ||
import { list, variant } from "@effector/reflect"; | ||
import { Col, Empty, Layout, Spin } from "antd"; | ||
import { combine } from "effector"; | ||
import { bookModel } from "entities/book"; | ||
import { BookRow } from "entities/book/ui/book-row"; | ||
import { Book } from "shared/api/book"; | ||
|
||
const MainPage: React.FC = () => ( | ||
<Layout> | ||
<BooksList/> | ||
</Layout> | ||
); | ||
|
||
const Item: React.FC<{ book: Book }> = ({ book }) => ( | ||
<Col> | ||
<BookRow | ||
data={book} | ||
/> | ||
</Col> | ||
); | ||
|
||
const TasksList = list({ | ||
view: Item, | ||
source: bookModel.$booksList, | ||
mapItem: { | ||
book: (book) => book, | ||
}, | ||
getKey: (book) => book.id, | ||
}); | ||
|
||
// eslint-disable-next-line effector/enforce-store-naming-convention | ||
const BooksList = variant({ | ||
source: combine( | ||
{ | ||
isLoading: bookModel.$getBookListFxLoading, | ||
isEmpty: bookModel.$booksListEmpty, | ||
}, | ||
({ isLoading, isEmpty }) => { | ||
switch (true) { | ||
case isLoading: | ||
return "loading"; | ||
|
||
case isEmpty: | ||
return "empty"; | ||
} | ||
|
||
return "ready"; | ||
}, | ||
), | ||
cases: { | ||
loading: () => <Spin size="large" />, | ||
empty: () => <Empty description="No books found" />, | ||
ready: TasksList, | ||
}, | ||
hooks: { | ||
// eslint-disable-next-line @typescript-eslint/no-empty-function | ||
mounted: bookModel.getBookListFx.prepend(() => { }), | ||
}, | ||
}); | ||
|
||
export default MainPage; |
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,49 @@ | ||
import AbstractAPI, { Query } from "./abstract"; | ||
import { PaginatedData } from "./types"; | ||
|
||
class API extends AbstractAPI { | ||
public async list(cursor?: string): Promise<PaginatedData<Book>> { | ||
const query: Query = {}; | ||
|
||
if (cursor) { | ||
query["cursor"] = cursor; | ||
} | ||
|
||
const resp = await this.request("GET", "/api/books", query); | ||
const json = await resp.json(); | ||
|
||
return json; | ||
} | ||
|
||
public async get(id: string): Promise<Book> { | ||
const resp = await this.request("GET", `/api/books/${id}`); | ||
const json = await resp.json(); | ||
|
||
return json; | ||
} | ||
} | ||
|
||
export interface Book { | ||
id: string, | ||
title: string, | ||
uri: string, | ||
tags: string[], | ||
highlights: Highlight[], | ||
bookmarks: Bookmark[], | ||
} | ||
|
||
export interface Highlight { | ||
page: number, | ||
start: number, | ||
end: number, | ||
title: string, | ||
note: string, | ||
} | ||
|
||
export interface Bookmark { | ||
page: number, | ||
title: string, | ||
note: string, | ||
} | ||
|
||
export default API; |
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,33 @@ | ||
import { AppServer } from "shared/mock/types"; | ||
import { Model } from "miragejs"; | ||
import { ModelDefinition } from "miragejs/-types"; | ||
import { Serializer } from "shared/mock/utils"; | ||
import { Book } from "shared/api/book"; | ||
|
||
export const BookModel: ModelDefinition<Book> = Model.extend({}); | ||
|
||
export const bookEndpoints = (server: AppServer): void => { | ||
server.get("/books", (schema) => schema.all("book")); | ||
server.get("/books/:id", (schema, request) => { | ||
const attrs = JSON.parse(request.requestBody); | ||
|
||
return schema.create("book", attrs); | ||
}); | ||
}; | ||
|
||
export const bookSeed = (server: AppServer): void => { | ||
server.create("book", { | ||
id: crypto.randomUUID(), | ||
title: "Book1", | ||
uri: "https://localhost:5173/sample.pdf", | ||
tags: [ | ||
"tag1", | ||
"tag2", | ||
"tag3", | ||
], | ||
highlights: [], | ||
bookmarks: [], | ||
}); | ||
}; | ||
|
||
export const bookSerializer = Serializer; |
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 |
---|---|---|
@@ -1,12 +1,31 @@ | ||
import { defineConfig } from "vite"; | ||
import { PluginOption, defineConfig } from "vite"; | ||
import react from "@vitejs/plugin-react"; | ||
import tsconfigPaths from "vite-tsconfig-paths"; | ||
import { viteStaticCopy } from "vite-plugin-static-copy"; | ||
|
||
// https://vitejs.dev/config/ | ||
export default defineConfig({ | ||
plugins: [ | ||
export default defineConfig(({ mode }) => { | ||
let plugins: PluginOption[] = [ | ||
react(), | ||
tsconfigPaths(), | ||
], | ||
envPrefix: "BS_", | ||
]; | ||
|
||
if (mode === "development") { | ||
plugins = [ | ||
...plugins, | ||
viteStaticCopy({ | ||
targets: [ | ||
{ | ||
src: "data/sample.pdf", | ||
dest: "/", | ||
}, | ||
], | ||
}), | ||
]; | ||
} | ||
|
||
return { | ||
plugins, | ||
envPrefix: "BS_", | ||
}; | ||
}); |
Oops, something went wrong.