Fixed dropping file
This commit is contained in:
parent
b7303fa032
commit
73b42e917d
6 changed files with 31 additions and 30 deletions
|
|
@ -58,7 +58,6 @@ const FlowsContextInitialValue: FlowsContextType = {
|
|||
setTabId: (index: string) => {},
|
||||
isLoading: true,
|
||||
flows: [],
|
||||
refreshFlows: () => {},
|
||||
removeFlow: (id: string) => {},
|
||||
addFlow: async (newProject: boolean, flowData?: FlowType) => "",
|
||||
updateFlow: (newFlow: FlowType) => {},
|
||||
|
|
@ -98,7 +97,7 @@ export function FlowsProvider({ children }: { children: ReactNode }) {
|
|||
|
||||
const [tabId, setTabId] = useState("");
|
||||
|
||||
const [isLoading, setIsLoading] = useState(true);
|
||||
const [isLoading, setIsLoading] = useState(false);
|
||||
|
||||
const [flows, setFlows] = useState<Array<FlowType>>([]);
|
||||
const [id, setId] = useState(uid());
|
||||
|
|
@ -124,25 +123,27 @@ export function FlowsProvider({ children }: { children: ReactNode }) {
|
|||
}
|
||||
|
||||
function refreshFlows() {
|
||||
setIsLoading(true);
|
||||
getTabsDataFromDB().then((DbData) => {
|
||||
if (DbData && Object.keys(templates).length > 0) {
|
||||
try {
|
||||
processFlows(DbData, false);
|
||||
updateStateWithDbData(DbData);
|
||||
setIsLoading(false);
|
||||
} catch (e) {}
|
||||
}
|
||||
});
|
||||
if (Object.keys(templates).length > 0) {
|
||||
setIsLoading(true);
|
||||
getTabsDataFromDB().then((DbData) => {
|
||||
if (DbData) {
|
||||
try {
|
||||
processFlows(DbData, false);
|
||||
updateStateWithDbData(DbData);
|
||||
setIsLoading(false);
|
||||
} catch (e) {}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
useEffect(() => {
|
||||
// If the user is authenticated, fetch the types. This code is important to check if the user is auth because of the execution order of the useEffect hooks.
|
||||
if (getAuthentication() === true) {
|
||||
if (getAuthentication() === true && Object.keys(templates).length > 0) {
|
||||
// get data from db
|
||||
refreshFlows();
|
||||
}
|
||||
}, [templates, getAuthentication()]);
|
||||
}, [getAuthentication(), templates, tabId]);
|
||||
|
||||
function getTabsDataFromDB() {
|
||||
//get tabs from db
|
||||
|
|
@ -333,7 +334,6 @@ export function FlowsProvider({ children }: { children: ReactNode }) {
|
|||
if (file) {
|
||||
let text = await file.text();
|
||||
let fileData = JSON.parse(text);
|
||||
console.log(fileData);
|
||||
if (fileData.is_component === undefined) {
|
||||
reject("Your file doesn't have the is_component property.");
|
||||
} else if (
|
||||
|
|
@ -761,7 +761,6 @@ export function FlowsProvider({ children }: { children: ReactNode }) {
|
|||
tabId,
|
||||
setTabId,
|
||||
flows,
|
||||
refreshFlows,
|
||||
incrementNodeId,
|
||||
removeFlow,
|
||||
addFlow,
|
||||
|
|
|
|||
|
|
@ -362,6 +362,11 @@ export default function Page({
|
|||
newProject: false,
|
||||
isComponent: false,
|
||||
file: event.dataTransfer.files.item(0)!,
|
||||
}).catch((error) => {
|
||||
setErrorData({
|
||||
title: "Error uploading file",
|
||||
list: [error],
|
||||
});
|
||||
});
|
||||
} else {
|
||||
setErrorData({
|
||||
|
|
|
|||
|
|
@ -212,7 +212,14 @@ export default function ExtraSidebar(): JSX.Element {
|
|||
<button
|
||||
className="extra-side-bar-buttons"
|
||||
onClick={() => {
|
||||
uploadFlow({ newProject: false, isComponent: false });
|
||||
uploadFlow({ newProject: false, isComponent: false }).catch(
|
||||
(error) => {
|
||||
setErrorData({
|
||||
title: "Error uploading file",
|
||||
list: [error],
|
||||
});
|
||||
}
|
||||
);
|
||||
}}
|
||||
>
|
||||
<IconComponent name="FileUp" className="side-bar-button-size " />
|
||||
|
|
|
|||
|
|
@ -51,6 +51,7 @@ export default function ComponentsComponent({
|
|||
const start = (pageIndex - 1) * pageSize;
|
||||
const end = start + pageSize;
|
||||
setData(allData.slice(start, end));
|
||||
console.log(allData);
|
||||
}, [pageIndex, pageSize, allData]);
|
||||
|
||||
const [data, setData] = useState<FlowType[]>([]);
|
||||
|
|
|
|||
|
|
@ -9,17 +9,8 @@ import { USER_PROJECTS_HEADER } from "../../constants/constants";
|
|||
import { alertContext } from "../../contexts/alertContext";
|
||||
import { FlowsContext } from "../../contexts/flowsContext";
|
||||
export default function HomePage(): JSX.Element {
|
||||
const {
|
||||
flows,
|
||||
setTabId,
|
||||
downloadFlows,
|
||||
uploadFlows,
|
||||
addFlow,
|
||||
removeFlow,
|
||||
uploadFlow,
|
||||
refreshFlows,
|
||||
isLoading,
|
||||
} = useContext(FlowsContext);
|
||||
const { setTabId, downloadFlows, uploadFlows, addFlow, uploadFlow } =
|
||||
useContext(FlowsContext);
|
||||
const { setErrorData, setSuccessData } = useContext(alertContext);
|
||||
const location = useLocation();
|
||||
const pathname = location.pathname;
|
||||
|
|
@ -63,7 +54,6 @@ export default function HomePage(): JSX.Element {
|
|||
// Set a null id
|
||||
useEffect(() => {
|
||||
setTabId("");
|
||||
refreshFlows();
|
||||
}, [pathname]);
|
||||
|
||||
const navigate = useNavigate();
|
||||
|
|
|
|||
|
|
@ -7,7 +7,6 @@ export type FlowsContextType = {
|
|||
isLoading: boolean;
|
||||
setTabId: (index: string) => void;
|
||||
flows: Array<FlowType>;
|
||||
refreshFlows: () => void;
|
||||
removeFlow: (id: string) => void;
|
||||
addFlow: (
|
||||
newProject: boolean,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue