Skip to content

Commit

Permalink
fix race condition
Browse files Browse the repository at this point in the history
  • Loading branch information
as6325400 committed Jan 18, 2024
1 parent eada47c commit b7c28eb
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 12 deletions.
7 changes: 4 additions & 3 deletions src/components/pages/main/courseCard.vue
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
<!-- 反面 -->
<div v-else id="back">
<div>
<commonOption @click.stop="delete_course_card(item), setConflictState(true)">刪除</commonOption>
<commonOption @click.stop="delete_course_card(item)">刪除</commonOption>
<commonOption @click="openColorTemplate(item, 1)">修改顏色</commonOption>
<commonOption @click="openColorTemplate(item, 2)">文字樣式</commonOption>
<commonOption @click="show_comment(item.getId())">查看評價</commonOption>
Expand Down Expand Up @@ -101,8 +101,9 @@
// if(color != )
}
let delete_course_card = function(item){
console.log(item);
let delete_course_card = async function(item){
await setConflictState(1)
await setConflictState(2)
if(item.getCredit() != null){
decreaseCredit(item.getCredit())
}
Expand Down
6 changes: 4 additions & 2 deletions src/components/pages/main/inputArea.vue
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
<td> {{ item.getStartTime() }} </td>
<td>
<button class = "bg-gray-700 py-2 my-1 px-6 rounded-lg text-white hover:bg-gray-500"
v-on:click="delete_course(item), setConflictState(true)">
v-on:click="delete_course(item)">
刪除
</button>
</td>
Expand Down Expand Up @@ -148,9 +148,11 @@ watch(toggleActive1, (inputValue) => {
}
})
var delete_course = function(item)
var delete_course = async function(item)
{
// 刪除課程
await setConflictState(1);
await setConflictState(2);
if(item.getCredit() != null){
decreaseCredit(item.getCredit())
}
Expand Down
2 changes: 1 addition & 1 deletion src/components/pages/main/search_box.vue
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ const setConflictState = (state) => store.dispatch("setrunConflictState", state)
watch(runConflictState, async (state) => {
if(state){
if(state == 2){
data.value = data.value.map(temp => {
temp['conflict'] = classconflict(temp);
return temp;
Expand Down
5 changes: 3 additions & 2 deletions src/components/pages/main/serach_modes/department.vue
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ const classClick = (item) => {
};
watch(runConflictState, async (state) => {
if(state){
if(state == 1){
courseList.value = courseList.value.map(temp => {
temp['conflict'] = classconflict(temp);
temp['click'] = false;
Expand Down Expand Up @@ -123,7 +123,8 @@ async function clickDepartment()
});
let coursedata = await getCourseByDepartment(departmentInput.value);
courseList.value = coursedata;
setConflictState(true);
// department 給 1
setConflictState(1)
show_search_list.value = true;
}
Expand Down
8 changes: 4 additions & 4 deletions src/store/course.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ interface State {
searchTime_status: boolean;
timeSearchMode: boolean;
timeSearchArgument: Array<number>;
runConflict: boolean;
runConflict: number;
}

function Transfer(data : any)
Expand Down Expand Up @@ -58,7 +58,7 @@ const store: Module<State, any> = {
searchTime_status: false,
timeSearchMode: false,
timeSearchArgument: [0, 0, 0],
runConflict: false
runConflict: 0
},
mutations: {
display(state: State) {
Expand Down Expand Up @@ -172,7 +172,7 @@ const store: Module<State, any> = {
settimeSearchArgument(state: State, arg: Array<number>){
state.timeSearchArgument = arg;
},
setrunConflictState(state: State, arg: boolean){
setrunConflictState(state: State, arg: number){
state.runConflict = arg;
}
},
Expand Down Expand Up @@ -251,7 +251,7 @@ const store: Module<State, any> = {
settimeSearchArgument(context: any, arg: Array<number>){
context.commit("settimeSearchArgument", arg);
},
setrunConflictState(context: any, arg: boolean){
setrunConflictState(context: any, arg: number){
context.commit("setrunConflictState", arg);
}
}
Expand Down

0 comments on commit b7c28eb

Please sign in to comment.