Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
hiroto7 committed Jan 11, 2020
2 parents 2635164 + b91f0d9 commit 3a8933e
Showing 1 changed file with 25 additions and 2 deletions.
27 changes: 25 additions & 2 deletions src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const COURSES_STATE = "courses-state"
const App = () => {
const [selected, setSelected] = useState(defaultSelected);
const [filterType, setFilterType] = useState(FilterType.None);
const [lockTarget, setLockTarget] = useState(RegistrationStatusLockTarget.None);
const { lockTarget, setLockTarget } = useLockTarget(filterType);
const { plan, setPlan } = usePlan(selected.name);

return (
Expand Down Expand Up @@ -51,6 +51,7 @@ const App = () => {
{
label: "ロックしない",
lockTarget: RegistrationStatusLockTarget.None,
disabled: filterType !== FilterType.None,
},
{
label: "[履修する] と [修得済み] の間の変更のみ許可",
Expand All @@ -59,16 +60,18 @@ const App = () => {
{
label: "[履修しない] と [履修する] の間の変更のみ許可",
lockTarget: RegistrationStatusLockTarget.Acquired,
disabled: filterType !== FilterType.None,
},
{
label: "すべてロックする",
lockTarget: RegistrationStatusLockTarget.All,
},
].map(({ label, lockTarget: lockTarget1 }) => (
].map(({ label, disabled, lockTarget: lockTarget1 }) => (
<Form.Check
custom type="radio"
id={`lockTargetCheck${lockTarget1}`}
label={label} key={lockTarget1}
disabled={disabled}
checked={lockTarget === lockTarget1}
onChange={() => setLockTarget(lockTarget1)}
/>
Expand Down Expand Up @@ -120,6 +123,26 @@ const App = () => {
);
}

const useLockTarget = (filterType: FilterType) => {
const [lockTarget, setLockTarget] = useState(RegistrationStatusLockTarget.None);

if (filterType === FilterType.None) {
return { lockTarget, setLockTarget };
} else if (lockTarget === RegistrationStatusLockTarget.None) {
return {
lockTarget: RegistrationStatusLockTarget.Unregistered,
setLockTarget,
};
} else if (lockTarget === RegistrationStatusLockTarget.Acquired) {
return {
lockTarget: RegistrationStatusLockTarget.All,
setLockTarget,
};
} else {
return { lockTarget, setLockTarget };
}
}

const usePlanMap = () => {
const [storedJSON, setStoredJSON] = useLocalStorage<readonly (readonly [string, PlanJSON])[]>(COURSES_STATE);
const [planMap0, setPlanMap0] = useState(() => {
Expand Down

0 comments on commit 3a8933e

Please sign in to comment.