Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#44 add chapter text in chapter filter menu #65

Merged
merged 2 commits into from
Mar 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions src/components/Overview/ByChapter.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import SortBy from "../SortBy";

import createDataObject from "../../c60-data-query/data-object.js";
import data from "../../c60-data-query/data.js";
import { chapterIdToName } from "../../constants/chapters";
import { chapterNameToId, chapterIdToName } from "../../constants/chapters";

function ByChapter() {
const [sort, setSort] = useState(0);
Expand Down Expand Up @@ -45,7 +45,11 @@ function ByChapter() {
{result.map(([chapterName, count]) => (
<Link to={`/chapter/${chapterName}`} className="w-full" key={chapterName}>
<ListItem
title={chapterName}
title={
chapterNameToId[chapterName].match(/^[0-9]+$/)
? 'หมวด ' + chapterNameToId[chapterName] + ' ' + chapterName
: chapterName
}
count={count}
chartColor={chapterColorCode[chapterName]}
/>
Expand Down
7 changes: 6 additions & 1 deletion src/components/Overview/ByDiscussionist.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import SortBy from "../SortBy";

import createDataObject from "../../c60-data-query/data-object.js";
import data from "../../c60-data-query/data.js";
import { chapterIdToName } from "../../constants/chapters.js";
import { chapterNameToId, chapterIdToName } from "../../constants/chapters.js";

function ByDiscussionist() {
const [sort, setSort] = useState(0);
Expand Down Expand Up @@ -119,6 +119,11 @@ function ByDiscussionist() {
{selectedChapters.map((chapter) => (
<ChapterMobilePillButton
chapter={chapter}
wording={
chapterNameToId[chapter].match(/^[0-9]+$/)
? 'หมวด ' + chapterNameToId[chapter] + ' ' + chapter
: chapter
}
remove={handleRemoveChapter}
/>
))}
Expand Down
7 changes: 6 additions & 1 deletion src/components/Overview/BySection.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import SortBy from "../SortBy";

import createDataObject from "../../c60-data-query/data-object.js";
import data from "../../c60-data-query/data.js";
import { chapterIdToName } from "../../constants/chapters";
import { chapterNameToId, chapterIdToName } from "../../constants/chapters";
import isNumeric from "../../utils/isNumeric.js";

function BySection() {
Expand Down Expand Up @@ -120,6 +120,11 @@ function BySection() {
{selectedChapters.map((chapter) => (
<ChapterMobilePillButton
chapter={chapter}
wording={
chapterNameToId[chapter].match(/^[0-9]+$/)
? 'หมวด ' + chapterNameToId[chapter] + ' ' + chapter
: chapter
}
remove={handleRemoveChapter}
/>
))}
Expand Down
4 changes: 2 additions & 2 deletions src/components/SelectChapters/ChapterButton.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Icon } from "@iconify/react";

import chapterColorCode from "../../constants/chapterColorCode";

function ChapterButton({ chapter, selected, onClick }) {
function ChapterButton({ chapter, wording, selected, onClick }) {
const activeStyle = "rounded-full text-black px-2";
const inactiveStyle = "text-[#9f9f9f] px-4";

Expand Down Expand Up @@ -33,7 +33,7 @@ function ChapterButton({ chapter, selected, onClick }) {
</div>
)}
<div className="text-ellipsis whitespace-nowrap overflow-hidden">
{chapter}
{wording}
</div>
</div>
</button>
Expand Down
4 changes: 2 additions & 2 deletions src/components/SelectChapters/ChapterMobilePillButton.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Icon } from "@iconify/react";

import chapterColorCode from "../../constants/chapterColorCode";

function ChapterMobilePillButton({ chapter, remove }) {
function ChapterMobilePillButton({ chapter, wording, remove }) {
return (
<div className="bg-[#2A2A2A] rounded-full py-2 px-2">
<div className="flex justify-between gap-1 items-center">
Expand All @@ -15,7 +15,7 @@ function ChapterMobilePillButton({ chapter, remove }) {
flexShrink: 0,
}}
></div>
<div className="flex-auto text-sm">{chapter}</div>
<div className="flex-auto text-sm">{wording}</div>
<button onClick={() => remove(chapter)}>
<Icon icon="line-md:close" style={{ fontSize: "16px" }}></Icon>
</button>
Expand Down
8 changes: 7 additions & 1 deletion src/components/SelectChapters/SelectChapters.jsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import ChapterButton from "./ChapterButton";
import chapters from "../../constants/chapters";
import chapters, { chapterNameToId } from "../../constants/chapters";

function SelectChapters(props) {
const { selectedChapters, onChange } = props;
Expand All @@ -9,6 +9,7 @@ function SelectChapters(props) {
<ChapterButton
key={"ทั้งหมด"}
chapter={"ทั้งหมด"}
wording={"ทั้งหมด"}
selected={selectedChapters.length === 0}
onClick={() => {
onChange([]);
Expand All @@ -18,6 +19,11 @@ function SelectChapters(props) {
<ChapterButton
key={chapter}
chapter={chapter}
wording={
chapterNameToId[chapter].match(/^[0-9]+$/)
? 'หมวด ' + chapterNameToId[chapter] + ' ' + chapter
: chapter
}
selected={selectedChapters.includes(chapter)}
onClick={() => {
if (selectedChapters.includes(chapter)) {
Expand Down
8 changes: 7 additions & 1 deletion src/components/SelectChapters/SelectChaptersMobile.jsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import ChapterButton from "./ChapterButton";
import chapters from "../../constants/chapters";
import chapters, { chapterNameToId } from "../../constants/chapters";
import { Icon } from "@iconify/react";

function SelectChaptersMobile(props) {
Expand All @@ -13,6 +13,7 @@ function SelectChaptersMobile(props) {
<ChapterButton
key={"ทั้งหมด"}
chapter={"ทั้งหมด"}
wording={"ทั้งหมด"}
selected={selectedChapters.length === 0}
onClick={() => {
onChange([]);
Expand All @@ -22,6 +23,11 @@ function SelectChaptersMobile(props) {
<ChapterButton
key={chapter}
chapter={chapter}
wording={
chapterNameToId[chapter].match(/^[0-9]+$/)
? 'หมวด ' + chapterNameToId[chapter] + ' ' + chapter
: chapter
}
selected={selectedChapters.includes(chapter)}
onClick={() => {
if (selectedChapters.includes(chapter)) {
Expand Down
5 changes: 5 additions & 0 deletions src/pages/Discussionist.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,11 @@ export default function Discussionist() {
{selectedChapters.map((chapter) => (
<ChapterMobilePillButton
chapter={chapter}
wording={
chapterNameToId[chapter].match(/^[0-9]+$/)
? 'หมวด ' + chapterNameToId[chapter] + ' ' + chapter
: chapter
}
remove={handleRemoveChapter}
/>
))}
Expand Down
Loading