Quellcode durchsuchen

not working

blog-new
Pavle Golubovic vor 3 Jahren
Ursprung
Commit
dd829e8b95
3 geänderte Dateien mit 124 neuen und 87 gelöschten Zeilen
  1. 2
    2
      frontend/src/components/Landing.jsx
  2. 60
    54
      frontend/src/hooks/useDataApi.js
  3. 62
    31
      frontend/src/pages/Home.jsx

+ 2
- 2
frontend/src/components/Landing.jsx Datei anzeigen

<div className="mb-16 -mt-12 md:mt-5 flex flex-col lg:flex-row justify-between items-center gap-90p"> <div className="mb-16 -mt-12 md:mt-5 flex flex-col lg:flex-row justify-between items-center gap-90p">
<div className="flex flex-col gap-8p"> <div className="flex flex-col gap-8p">
<h6 className="subheading"> <h6 className="subheading">
{data.subheading}
{/* {data.subheading} */}
</h6> </h6>
<h1 className="heading"> <h1 className="heading">
Software Solutions Tailored to Each Client Software Solutions Tailored to Each Client
</h1> </h1>
<p className="paragraph"> <p className="paragraph">
{data.paragraph}
{/* {data.paragraph} */}


</p> </p>
</div> </div>

+ 60
- 54
frontend/src/hooks/useDataApi.js Datei anzeigen







//Reducer
const dataFetchReducer = (state, action) => { const dataFetchReducer = (state, action) => {
switch (action.type) {
case 'FETCH_INIT':
return {
...state,
isLoading: true,
isError: false,
};
case 'FETCH_SUCCESS':
return {
...state,
isLoading: false,
isError: false,
data: action.payload,
};
case 'FETCH_FAILURE':
return {
...state,
isLoading: false,
isError: true,
};
default:
throw new Error();
}
};
switch (action.type) {
case 'FETCH_INIT':
return {
...state,
isLoading: true,
isError: false
};
case 'FETCH_SUCCESS':
return {
...state,
isLoading: false,
isError: false,
data: action.payload,
};
case 'FETCH_FAILURE':
return {
...state,
isLoading: false,
isError: true,
};
default:
throw new Error();
}
};



//hook
const useDataApi = (initialUrl, initialData) => { const useDataApi = (initialUrl, initialData) => {
const [url, setUrl] = useState(initialUrl);
const [state, dispatch] = useReducer(dataFetchReducer, {
isLoading: false,
isError: false,
data: initialData,
});
const [url, setUrl] = useState(initialUrl);

const [state, dispatch] = useReducer(dataFetchReducer, {
isLoading: false,
isError: false,
data: initialData,
});

useEffect(() => {
let didCancel = false;

const fetchData = async () => {
dispatch({ type: 'FETCH_INIT' });

try {
const result = await axios(url);

if (!didCancel) {
dispatch({ type: 'FETCH_SUCCESS', payload: result.data });
}
} catch (error) {
if (!didCancel) {
dispatch({ type: 'FETCH_FAILURE' });
}
}
};

fetchData();


//getData
useEffect(() => {
const fetchData = async () => {
dispatch({ type: 'FETCH_INIT' });
try {
const result = await axios(url);
dispatch({ type: 'FETCH_SUCCESS', payload: result.data });
} catch (error) {
dispatch({ type: 'FETCH_FAILURE' });
}
};
fetchData();
}, [url]);
return () => {
didCancel = true;
};
}, [url]);


return [state, setUrl];
};
return [state, setUrl];
};


export default useDataApi;
export default useDataApi

+ 62
- 31
frontend/src/pages/Home.jsx Datei anzeigen

import PortfolioSection from '../components/PortfolioSection'; import PortfolioSection from '../components/PortfolioSection';
import PageLayout from '../layout/PageLayout'; import PageLayout from '../layout/PageLayout';
import MapDilig from '../components/Map'; import MapDilig from '../components/Map';

const api_url = process.env.REACT_APP_API_URL;

export default function Home({scrollToView, forwardedRef}) {
import useDataApi from '../hooks/useDataApi';

//const api_url = process.env.REACT_APP_API_URL;
const api_url = 'http://localhost:1337';

//const query = '';

const strapiPopulate = [
'Cards',
'Cards.Card1',
'Cards.Card1.Icon',
'Cards.Card2',
'Cards.Card2.Icon',
'Cards.Card3',
'Cards.Card3.Icon',
'HeroNumbers',
'HeroNumbers.number',
]

const stringBuilder = () => {
let stringQuery = '';
strapiPopulate.map((item,index) => {
if (index !== 0) stringQuery += '&';
stringQuery += `populate=${item}`;
});
return stringQuery;
};

export default function Home({forwardedRef}) {
const [cnt, setCnt] = useState(''); const [cnt, setCnt] = useState('');
const [isLoaded, setIsLoaded] = useState('');


const [contactRef, setRef] = useState(forwardedRef) const [contactRef, setRef] = useState(forwardedRef)
const [contactElement, setContactElement] = useState(0);


// const UIContext = useContext(UIContext);


// const initUIValues = UIContext ?? {
// tab: '',
// contactRef: contactRef
// };

const [{data, isLoading, isError}, doFetch] = useDataApi(`${api_url}/api/w-home-page?${stringBuilder()}`);

const landingData = {
data
}

useEffect(() => { useEffect(() => {
document.title = 'Diligent Software'; document.title = 'Diligent Software';
},[]); },[]);



useEffect(() => { useEffect(() => {
var vid = document.getElementById('animation');
vid.playbackRate = 2;
axios
.get(
`${api_url}/api/homepage?populate[0]=landing&populate[1]=why&populate[2]=why.heading&populate[3]=why.card_left.icon&populate[4]=why.card_mid.icon&populate[5]=why.card_right.icon&populate[6]=why.card_left.icon&populate[7]=why.card_mid.icon&populate[8]=why.card_right.icon&populate[9]=landing.heading`,
// api/homepage?&populate[0]=why&populate[1]=why.heading&populate[2]=why.card_left.icon&populate[3]=why.card_mid.icon&populate[4]=why.card_right.icon&populate[5]=why.card_left.icon&populate[6]=why.card_mid.icon&populate[7]=why.card_right.icon
)
.then(res => {
setCnt(res.data.data.attributes);
//console.log(res)
setIsLoaded(true);
})
.catch(err => {
console.log(err);
setIsLoaded(false);
});
}, []);
console.log(data);
//stringBuilder();
},[data]);



// useEffect(() => {
// var vid = document.getElementById('animation');
// vid.playbackRate = 2;
// axios
// .get(
// `${api_url}/api/homepage?populate[0]=landing&populate[1]=why&populate[2]=why.heading&populate[3]=why.card_left.icon&populate[4]=why.card_mid.icon&populate[5]=why.card_right.icon&populate[6]=why.card_left.icon&populate[7]=why.card_mid.icon&populate[8]=why.card_right.icon&populate[9]=landing.heading`,
// // api/homepage?&populate[0]=why&populate[1]=why.heading&populate[2]=why.card_left.icon&populate[3]=why.card_mid.icon&populate[4]=why.card_right.icon&populate[5]=why.card_left.icon&populate[6]=why.card_mid.icon&populate[7]=why.card_right.icon
// )
// .then(res => {
// setCnt(res.data.data.attributes);
// //console.log(res)
// setIsLoaded(true);
// })
// .catch(err => {
// console.log(err);
// setIsLoaded(false);
// });
// }, []);


useEffect(() => { useEffect(() => {


}, [contactRef, cnt]) }, [contactRef, cnt])


if (!isLoaded) {
if (isLoading) {
return ( return (
<div className="z-50 w-full h-screen bg-white dark:bg-dg-primary-1700 overflow-hidden dark:text-white flex items-center justify-center text-3xl font-semibold"> <div className="z-50 w-full h-screen bg-white dark:bg-dg-primary-1700 overflow-hidden dark:text-white flex items-center justify-center text-3xl font-semibold">
<video id="animation" width="540" height="540" autoPlay muted loop> <video id="animation" width="540" height="540" autoPlay muted loop>
</Tab.Group> */} </Tab.Group> */}


{/* Landing Section */} {/* Landing Section */}
<Landing data={cnt.landing.heading} />
<Landing />


{/* Why Us Section */} {/* Why Us Section */}
<WhySection data={cnt.why} /> <WhySection data={cnt.why} />

Laden…
Abbrechen
Speichern