-
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
10 changed files
with
165 additions
and
80 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
name: Main | ||
|
||
on: | ||
push: | ||
branches: | ||
- main | ||
pull_request: | ||
branches: | ||
- main | ||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- name: Use Node.js LTS | ||
uses: actions/setup-node@v4 | ||
with: | ||
cache: 'npm' | ||
node-version: 'lts/*' | ||
- name: node check | ||
run: | | ||
npm ci | ||
npm test | ||
env: | ||
CI: true | ||
|
||
status-checks: | ||
name: status-checks | ||
needs: [build] | ||
permissions: | ||
contents: none | ||
if: always() | ||
runs-on: ubuntu-latest | ||
timeout-minutes: 5 | ||
steps: | ||
- name: Validation Status checks | ||
run: | | ||
echo 'Configuration for Status checks that are required' | ||
echo '${{ toJSON(needs) }}' | ||
if [[ ('skipped' == '${{ needs.build.result }}') || ('success' == '${{ needs.build.result }}') ]]; then | ||
exit 0 | ||
fi | ||
exit 1 |
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,14 +1,20 @@ | ||
import { RouteObject } from 'react-router-dom'; | ||
import { RouteObject, useParams } from 'react-router-dom'; | ||
import { BookComponent } from '@/library/infrastructure/primary/BookComponent.tsx'; | ||
import { LibraryApp } from '@/library/application/LibraryApp.tsx'; | ||
import { ISBN } from '@/library/domain/ISBN.ts'; | ||
|
||
const BooksPage = () => { | ||
const { isbn } = useParams<string>(); | ||
return <BookComponent isbn={ISBN.of(isbn!)} />; | ||
}; | ||
|
||
export const libraryRoutes: RouteObject = { | ||
path: '/', | ||
element: <LibraryApp />, | ||
children: [ | ||
{ | ||
path: '', | ||
element: <BookComponent />, | ||
path: 'book/:isbn', | ||
element: <BooksPage />, | ||
}, | ||
], | ||
}; |
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,6 +1,7 @@ | ||
import { Book } from '@/library/domain/Book'; | ||
import { Either } from '@/functional/Either'; | ||
import { ISBN } from '@/library/domain/ISBN.ts'; | ||
|
||
export interface Books { | ||
get(): Promise<Either<Error, Book>>; | ||
get(isbn: ISBN): Promise<Either<Error, Book>>; | ||
} |
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,33 +1,44 @@ | ||
import { useState } from 'react'; | ||
import { useLoadEither } from '@/library/infrastructure/primary/UseLoad'; | ||
import { useEffect, useState } from 'react'; | ||
import { useTranslation } from 'react-i18next'; | ||
import { inject } from '@/injections.ts'; | ||
import { BOOKS } from '@/library/application/LibraryKeys.ts'; | ||
import { Book } from '@/library/domain/Book.ts'; | ||
import { ISBN } from '@/library/domain/ISBN.ts'; | ||
import { Loader, loadError, loadFor, loadInProgress, loadSuccess } from '@/library/infrastructure/primary/Loader.ts'; | ||
|
||
export const BookComponent = () => { | ||
const books = inject(BOOKS); | ||
const BookInfoComponent = ({ book }: { book: Book }) => { | ||
const { t } = useTranslation(); | ||
return ( | ||
<ul> | ||
<li data-selector="book.title"> | ||
<strong data-selector="book.label.title">{t('book.title')} </strong> | ||
<span data-selector="book.title">{book.title}</span> | ||
</li> | ||
<li data-selector="book.isbn">{book.isbn.get()}</li> | ||
</ul> | ||
); | ||
}; | ||
|
||
export const BookComponent = (props: { isbn: ISBN }) => { | ||
const { t } = useTranslation(); | ||
const [book, setBook] = useState<Book>(); | ||
const [bookLoader, setBookLoader] = useState<Loader<Book>>(loadInProgress()); | ||
|
||
const { isInProgress, isFailing, isSuccessful, errorMessage } = useLoadEither(books.get(), book => { | ||
setBook(book); | ||
}); | ||
useEffect(() => { | ||
setBookLoader(loadInProgress()); | ||
inject(BOOKS) | ||
.get(props.isbn) | ||
.then(either => | ||
either.evaluate( | ||
error => setBookLoader(loadError(error.message)), | ||
content => setBookLoader(loadSuccess(content)) | ||
) | ||
) | ||
.catch((error: Error) => setBookLoader(loadError(error.message))); | ||
}, [props.isbn]); | ||
|
||
return ( | ||
<> | ||
{isInProgress && <p data-selector="book.loading">{t('book.inProgress')}</p>} | ||
{isFailing && <p data-selector="book.error">{errorMessage}</p>} | ||
{isSuccessful && ( | ||
<ul> | ||
<li data-selector="book.title"> | ||
<strong data-selector="book.label.title">{t('book.title')} </strong> | ||
<span data-selector="book.title">{book?.title}</span> | ||
</li> | ||
<li data-selector="book.isbn">{book?.isbn.get()}</li> | ||
</ul> | ||
)} | ||
</> | ||
); | ||
return loadFor(bookLoader)({ | ||
progress: () => <p data-selector="book.loading">{t('book.inProgress')}</p>, | ||
error: message => <p data-selector="book.error">{message}</p>, | ||
success: book => <BookInfoComponent book={book} />, | ||
}); | ||
}; |
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,58 @@ | ||
import { ReactElement } from 'react'; | ||
|
||
const LoadingInProgress = Symbol(); | ||
const LoadingError = Symbol(); | ||
const LoadingSuccess = Symbol(); | ||
|
||
type LoadingStatus = typeof LoadingError | typeof LoadingInProgress | typeof LoadingSuccess; | ||
|
||
interface LoadWithStatus { | ||
status: LoadingStatus; | ||
} | ||
|
||
interface LoadSuccess<T> extends LoadWithStatus { | ||
content: T; | ||
status: typeof LoadingSuccess; | ||
} | ||
|
||
interface LoadError extends LoadWithStatus { | ||
errorMessage: string; | ||
status: typeof LoadingError; | ||
} | ||
|
||
interface LoadInProgress extends LoadWithStatus { | ||
status: typeof LoadingInProgress; | ||
} | ||
|
||
export type Loader<T> = LoadSuccess<T> | LoadError | LoadInProgress; | ||
|
||
export const loadInProgress = (): LoadInProgress => ({ status: LoadingInProgress }); | ||
|
||
export const loadSuccess = <T>(content: T): LoadSuccess<T> => ({ | ||
content, | ||
status: LoadingSuccess, | ||
}); | ||
|
||
export const loadError = (errorMessage: string): LoadError => ({ | ||
errorMessage, | ||
status: LoadingError, | ||
}); | ||
|
||
type LoaderCallback<T> = { | ||
success: (content: T) => ReactElement; | ||
error: (message: string) => ReactElement; | ||
progress: () => ReactElement; | ||
}; | ||
|
||
export const loadFor = | ||
<T>(loader: Loader<T>) => | ||
({ success, error, progress }: LoaderCallback<T>): ReactElement => { | ||
switch (loader.status) { | ||
case LoadingInProgress: | ||
return progress(); | ||
case LoadingError: | ||
return error(loader.errorMessage); | ||
case LoadingSuccess: | ||
return success(loader.content); | ||
} | ||
}; |
This file was deleted.
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