Skip to content

Commit

Permalink
曜日とコマで検索できるようにした
Browse files Browse the repository at this point in the history
  • Loading branch information
swawa-yu committed Dec 26, 2023
1 parent 14c47b8 commit 25a39dd
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 5 deletions.
2 changes: 2 additions & 0 deletions src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ function App() {
bookmarkFilter: 'all',
teacher: '',
subjectName: '',
youbi: '',
koma: '',
});
const [isTableRaw, setIsTableRaw] = useState(true);

Expand Down
14 changes: 14 additions & 0 deletions src/search/SearchComponent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ const SearchComponent: React.FC<SearchComponentProps> = ({ onSearch }: SearchCom
bookmarkFilter: 'all',
teacher: '',
subjectName: '',
youbi: '',
koma: '',
});

const handleSearch = () => {
Expand Down Expand Up @@ -39,6 +41,18 @@ const SearchComponent: React.FC<SearchComponentProps> = ({ onSearch }: SearchCom
onChange={(e) => setSearchOptions({ ...searchOptions, teacher: e.target.value })}
placeholder="担当教員名"
/>
<input
type="text"
value={searchOptions.youbi}
onChange={(e) => setSearchOptions({ ...searchOptions, youbi: e.target.value })}
placeholder="曜日"
/>
<input
type="text"
value={searchOptions.koma}
onChange={(e) => setSearchOptions({ ...searchOptions, koma: e.target.value })}
placeholder="コマ"
/>
<input
type="checkbox"
checked={searchOptions.bookmarkFilter === 'bookmark'}
Expand Down
12 changes: 11 additions & 1 deletion src/search/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { subjectCodeList, subjectMap, Subject } from "../subject";
import { parseSchedule } from "../subject/parser";

// 検索条件で絞り込んだ科目のリスト(講義コードのリスト)を返す
export const filteredSubjectCodeList = (searchOptions: SearchOptions) => {
Expand All @@ -14,6 +15,8 @@ export interface SearchOptions {
subjectName: string;
teacher: string;
bookmarkFilter: 'all' | 'bookmark' | 'except-bookmark';
youbi: string;
koma: string;
// season: NormalSeasons | undefined;
// module: Modules | undefined;
// periods: Periods;
Expand All @@ -34,5 +37,12 @@ export function matchesSearchOptions(subject: Subject, searchOptions: SearchOpti
let machesCampus = searchOptions.campus === "" || subject["開講キャンパス"] === searchOptions.campus;
let machesSubjectName = searchOptions.subjectName === "" || subject["授業科目名"].includes(searchOptions.subjectName);
let machesTeacher = searchOptions.teacher === "" || subject["担当教員名"].includes(searchOptions.teacher);
return machesCampus && machesSubjectName && machesTeacher;
let machesYoubi = searchOptions.youbi === "" || subject["曜日・時限・講義室"].includes(searchOptions.youbi);
const schedules = parseSchedule(subject["曜日・時限・講義室"]);
let machesKoma = searchOptions.koma === "" ||
schedules.some((schedule) => {
return schedule.jigen?.komaRange[0] === "解析エラー" ? false :
(schedule.jigen?.komaRange[0] as number) <= parseInt(searchOptions.koma) && parseInt(searchOptions.koma) <= (schedule.jigen?.komaRange[1] as number)
});
return machesCampus && machesSubjectName && machesTeacher && machesYoubi && machesKoma;
}
6 changes: 2 additions & 4 deletions src/subject/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export interface Jigen {

export interface Schedule {
jikiKubun: JikiKubun // 1ターム、2ターム、3ターム、4ターム、セメスター(前期)、セメスター(後期)、ターム外(前期)、ターム外(後期)、年度、通年、集中
jigen: Jigen | undefined // 集中講義の場合はundefined
jigen: Jigen | undefined // TODO: 集中講義の場合はundefined でよいのか? Jigen["youbi"]に"集中"を入れるべきか?
room: string // 何も書かれていない場合は空文字列
}

Expand Down Expand Up @@ -51,9 +51,7 @@ export type SubjectProperty =
"その他"


export type Subject = {
[key in SubjectProperty]: string
}
export type Subject = { [key in SubjectProperty]: string }

export type SubjectMap = { [subjectCode: string]: Subject }
export const subjectMap: SubjectMap = {};
Expand Down

0 comments on commit 25a39dd

Please sign in to comment.