-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #152 from Alforoan/upload-download-temp
upload and download frontend
- Loading branch information
Showing
10 changed files
with
376 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import React, { useState } from "react"; | ||
import { useBoard } from "../context/BoardContext"; | ||
import { useTemplates } from "../context/TemplateContext"; | ||
import { v4 as uuidv4 } from "uuid"; | ||
|
||
const UploadBoardComponent = () => { | ||
const { selectedBoard } = useBoard(); | ||
const [boardName, setBoardName] = useState(selectedBoard!.name); | ||
const { handleUploadNewTemplate } = useTemplates(); | ||
|
||
const handleClickUpload = () => { | ||
console.log(selectedBoard?.name); | ||
// THIS SHOULD POP UP MODAL TO CONFIRM WITH AN OPPORTUNITY TO CHANGE BOARD NAME | ||
// TOAST SUCCESS NEEDED AFTER UPLOAD | ||
const boardToUpload = { | ||
...selectedBoard!, | ||
name: boardName, | ||
uuid: uuidv4(), | ||
}; | ||
handleUploadNewTemplate(boardToUpload); | ||
}; | ||
return ( | ||
<button | ||
onClick={handleClickUpload} | ||
className="bg-flair text-white px-4 py-2 rounded font-primary" | ||
> | ||
Upload | ||
</button> | ||
); | ||
}; | ||
|
||
export default UploadBoardComponent; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import { useState } from "react"; | ||
import axios from "axios"; | ||
import { Template } from "../types"; // Ensure Card is also imported if it's a separate type | ||
|
||
const useGetAllTemplates = () => { | ||
const [isLoading, setIsLoading] = useState(false); | ||
const [error, setError] = useState<Error | null>(null); | ||
|
||
const getAllTemplates = async (): Promise<Template[]> => { | ||
setIsLoading(true); | ||
setError(null); | ||
try { | ||
const response = await axios.get( | ||
`${import.meta.env.VITE_BACKEND_URL}/api/templates` | ||
); | ||
setIsLoading(false); | ||
const templates: Template[] = response.data.map( | ||
(datapt: { [x: string]: any }) => { | ||
let template: Template = { | ||
uuid: datapt["uuid"], | ||
name: datapt["name"], | ||
downloads: datapt["downloads"], | ||
author: datapt["author"], | ||
cards: [], | ||
}; | ||
|
||
return template; | ||
} | ||
); | ||
return templates; | ||
} catch (err) { | ||
if (err instanceof Error) { | ||
setError(err); | ||
setIsLoading(false); | ||
} | ||
return []; | ||
} | ||
}; | ||
|
||
return { getAllTemplates, isLoading, error }; | ||
}; | ||
|
||
export default useGetAllTemplates; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import { useState } from "react"; | ||
import axios from "axios"; | ||
import { Card, CardDetails, ChecklistEntry, Columns } from "../types"; // Ensure Card is also imported if it's a separate type | ||
|
||
const useGetTemplateCards = () => { | ||
const [isLoading, setIsLoading] = useState(false); | ||
const [error, setError] = useState<Error | null>(null); | ||
|
||
const getCardsFromTemplate = async (boardId: string): Promise<Card[]> => { | ||
setIsLoading(true); | ||
setError(null); | ||
|
||
try { | ||
const response = await axios.get( | ||
`${import.meta.env.VITE_BACKEND_URL}/api/templates/${boardId}` | ||
); | ||
setIsLoading(false); | ||
|
||
const cards = response.data.map((datapt: { [x: string]: any }) => { | ||
let details = JSON.parse(datapt["details"]); | ||
const cardDetails: CardDetails = { | ||
checklist: details["checklist"] as ChecklistEntry[], | ||
notes: details["notes"], | ||
timeEstimate: details["timeEstimate"], | ||
}; | ||
|
||
let card: Card = { | ||
id: datapt["card_id"], | ||
cardName: datapt["card_name"], | ||
column: datapt["column_name"] as Columns, | ||
creationDate: datapt["creation_date"] as Date, | ||
order: datapt["order"], | ||
details: cardDetails, | ||
}; | ||
|
||
return card; | ||
}); | ||
|
||
return cards; | ||
} catch (err) { | ||
if (err instanceof Error) { | ||
setError(err); | ||
setIsLoading(false); | ||
} | ||
return []; | ||
} | ||
}; | ||
|
||
return { getCardsFromTemplate, isLoading, error }; | ||
}; | ||
|
||
export default useGetTemplateCards; |
Oops, something went wrong.