-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Deck catalog
- Loading branch information
Showing
26 changed files
with
473 additions
and
211 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
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,6 @@ | ||
// ISO 639-1 two-letter language codes | ||
export enum LanguageCode { | ||
Russian = "ru", | ||
English = "en", | ||
Spanish = "es", | ||
} |
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,3 @@ | ||
export const camelCaseToHuman = (str: string) => { | ||
return str.replace(/([A-Z])/g, " $1"); | ||
}; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { css } from "@emotion/css"; | ||
import { theme } from "../../ui/theme.tsx"; | ||
import React from "react"; | ||
|
||
export const DeckAddedLabel = () => { | ||
return ( | ||
<div | ||
className={css({ | ||
position: "absolute", | ||
right: 0, | ||
top: 0, | ||
fontSize: 14, | ||
fontStyle: "normal", | ||
padding: "0 8px", | ||
borderRadius: theme.borderRadius, | ||
border: "1px solid " + theme.linkColor, | ||
color: theme.linkColor, | ||
})} | ||
> | ||
ADDED | ||
</div> | ||
); | ||
}; |
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,87 @@ | ||
import { observer } from "mobx-react-lite"; | ||
import { useBackButton } from "../../lib/telegram/use-back-button.tsx"; | ||
import { screenStore } from "../../store/screen-store.ts"; | ||
import { css } from "@emotion/css"; | ||
import React from "react"; | ||
import { useDeckCatalogStore } from "../../store/deck-catalog-store-context.tsx"; | ||
import { useMount } from "../../lib/react/use-mount.ts"; | ||
import { theme } from "../../ui/theme.tsx"; | ||
import { Select } from "../../ui/select.tsx"; | ||
import { enumEntries } from "../../lib/typescript/enum-values.ts"; | ||
import { LanguageFilter } from "../../store/deck-catalog-store.ts"; | ||
import { camelCaseToHuman } from "../../lib/string/camel-case-to-human.ts"; | ||
import { DeckListItemWithDescription } from "../../ui/deck-list-item-with-description.tsx"; | ||
import { range } from "../../lib/array/range.ts"; | ||
import { DeckLoading } from "../deck-list/deck-loading.tsx"; | ||
import { NoDecksMatchingFilters } from "./no-decks-matching-filters.tsx"; | ||
import { deckListStore } from "../../store/deck-list-store.ts"; | ||
import { DeckAddedLabel } from "./deck-added-label.tsx"; | ||
|
||
export const DeckCatalog = observer(() => { | ||
const store = useDeckCatalogStore(); | ||
|
||
useMount(() => { | ||
store.load(); | ||
}); | ||
|
||
useBackButton(() => { | ||
screenStore.go({ type: "main" }); | ||
}); | ||
|
||
return ( | ||
<div | ||
className={css({ | ||
display: "flex", | ||
flexDirection: "column", | ||
gap: 6, | ||
marginBottom: 16, | ||
})} | ||
> | ||
<h3 className={css({ textAlign: "center" })}>Deck Catalog</h3> | ||
<div className={css({ display: "flex", gap: 4 })}> | ||
<div className={css({ color: theme.hintColor })}>Available in:</div> | ||
<Select<LanguageFilter> | ||
value={store.filters.language.value} | ||
onChange={store.filters.language.onChange} | ||
options={enumEntries(LanguageFilter).map(([name, key]) => ({ | ||
value: key, | ||
label: name === "Any" ? "Any language" : camelCaseToHuman(name), | ||
}))} | ||
/> | ||
</div> | ||
|
||
{(() => { | ||
if (store.decks?.state === "pending") { | ||
return range(5).map((i) => <DeckLoading key={i} />); | ||
} | ||
|
||
if (store.decks?.state === "fulfilled") { | ||
const filteredDecks = store.filteredDecks; | ||
|
||
if (filteredDecks.length === 0) { | ||
return <NoDecksMatchingFilters />; | ||
} | ||
|
||
const myDeckIds = deckListStore.myDecks.map((deck) => deck.id); | ||
|
||
return filteredDecks.map((deck) => { | ||
const isMine = myDeckIds.includes(deck.id); | ||
|
||
return ( | ||
<DeckListItemWithDescription | ||
key={deck.id} | ||
titleRightSlot={isMine ? <DeckAddedLabel /> : undefined} | ||
deck={deck} | ||
onClick={() => { | ||
deckListStore.openDeckFromCatalog(deck, isMine); | ||
}} | ||
/> | ||
); | ||
}); | ||
} | ||
|
||
return null; | ||
})()} | ||
</div> | ||
); | ||
}); |
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,20 @@ | ||
import { css } from "@emotion/css"; | ||
import { theme } from "../../ui/theme.tsx"; | ||
import React from "react"; | ||
|
||
export const NoDecksMatchingFilters = () => { | ||
return ( | ||
<div | ||
className={css({ | ||
marginTop: 150, | ||
alignSelf: "center", | ||
textAlign: "center", | ||
})} | ||
> | ||
<div className={css({ fontWeight: 500 })}>No decks found</div> | ||
<div className={css({ fontSize: 14, color: theme.hintColor })}> | ||
Try updating filters to see more decks | ||
</div> | ||
</div> | ||
); | ||
}; |
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
Oops, something went wrong.