Skip to content

Commit

Permalink
renaming + unused gone
Browse files Browse the repository at this point in the history
  • Loading branch information
DRIESASTER committed May 20, 2024
1 parent 3e4d692 commit 7a48a68
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 25 deletions.
26 changes: 7 additions & 19 deletions frontend/src/queries/Project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ import {
getProject,
createProject,
getProjects,
uploadProjectFiles,
uploadTestFiles,
updateProject,
fetchProjectFiles,
fetchTestFiles,
} from "@/services/project";

function PROJECT_QUERY_KEY(projectId: number): (string | number)[] {
Expand All @@ -27,7 +27,7 @@ function PROJECTS_QUERY_KEY(): string[] {
*/

function TEST_FILES_QUERY_KEY(projectId: number): (string | number)[] {
return ["projectFiles", projectId];
return ["testFiles", projectId];
}

// Hook for fetching project details
Expand All @@ -51,18 +51,6 @@ export function useProjectsQuery(): UseQueryReturnType<UserProjectList, Error> {
});
}

// Hook for creating a new submission
export function useCreateSubmissionMutation(
groupId: Ref<number | undefined>
): UseMutationReturnType<Submission, Error, FormData, void> {
return useMutation<Submission, Error, FormData, void>({
mutationFn: (formData) => createSubmission(groupId.value!, formData),
onError: (error) => {
console.error("Submission creation failed", error);
alert("Could not create submission. Please try again.");
},
});
}
/**
* Mutation composable for creating a project
*/
Expand Down Expand Up @@ -112,25 +100,25 @@ export function useUpdateProjectMutation(): UseMutationReturnType<
});
}

export function useProjectFilesQuery(
export function useTestFilesQuery(
projectId: MaybeRefOrGetter<number | undefined>
): UseQueryReturnType<File[], Error> {
return useQuery<File[], Error>({
queryKey: TEST_FILES_QUERY_KEY(toValue(projectId)!),
queryFn: () => fetchProjectFiles(toValue(projectId)!),
queryFn: () => fetchTestFiles(toValue(projectId)!),
enabled: () => !!toValue(projectId), // Only fetch when a projectId is provided
});
}
// Hook for uploading files to a project
export function useUploadProjectFilesMutation(): UseMutationReturnType<
export function useUploadTestFilesMutation(): UseMutationReturnType<
void, // Type of data returned on success
Error, // Type of error
{ projectId: number; formData: FormData },
void
> {
const queryClient = useQueryClient();
return useMutation<void, Error, { projectId: number; formData: FormData }, void>({
mutationFn: ({ projectId, formData }) => uploadProjectFiles(projectId, formData),
mutationFn: ({ projectId, formData }) => uploadTestFiles(projectId, formData),
onSuccess: (_, { projectId }) => {
queryClient.invalidateQueries({ queryKey: PROJECT_QUERY_KEY(projectId) });
console.log("Files uploaded successfully");
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/services/project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ export async function updateProject(
}

// Function to upload test files to a specific project
export async function uploadProjectFiles(projectId: number, formData: FormData): Promise<void> {
export async function uploadTestFiles(projectId: number, formData: FormData): Promise<void> {
await authorized_fetch(
`/api/projects/${projectId}/test_files`,
{
Expand All @@ -73,7 +73,7 @@ export async function uploadProjectFiles(projectId: number, formData: FormData):
);
}

export async function fetchProjectFiles(projectId: number): Promise<any> {
export async function fetchTestFiles(projectId: number): Promise<any> {
return authorized_fetch(`/api/projects/${projectId}/test_files`, {
method: "GET",
});
Expand Down
8 changes: 4 additions & 4 deletions frontend/src/views/CreateProjectView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -141,10 +141,10 @@ import { useCreateGroupsMutation, useAddToGroupMutation } from "@/queries/Group"
import { ref, reactive, computed } from "vue";
import {
useCreateProjectMutation,
useProjectFilesQuery,
useTestFilesQuery,
useProjectQuery,
useUpdateProjectMutation,
useUploadProjectFilesMutation,
useUploadTestFilesMutation,
} from "@/queries/Project";
import type User from "@/models/User";
import DisplayTestFiles from "@/components/project/DisplayTestFiles.vue";
Expand Down Expand Up @@ -177,15 +177,15 @@ const isEditMode = computed(() => projectId.value !== undefined);
const createProjectMutation = useCreateProjectMutation();
const createGroupsMutation = useCreateGroupsMutation();
const joinGroupMutation = useAddToGroupMutation();
const uploadProjectFilesMutation = useUploadProjectFilesMutation();
const uploadProjectFilesMutation = useUploadTestFilesMutation();
const updateProjectMutation = useUpdateProjectMutation();
// Query to fetch and handle files associated with a project
const {
data: filesData,
isError: filesError,
isLoading: filesLoading,
} = useProjectFilesQuery(projectId.value);
} = useTestFilesQuery(projectId.value);
// Query to fetch and handle project details
const {
Expand Down

0 comments on commit 7a48a68

Please sign in to comment.