mirror of
https://github.com/SomboChea/ui
synced 2026-01-20 01:55:56 +07:00
* fix: package list refresh based on logged-in user description: In `pages/home/Home.tsx` now monitoring any change in a user log-in/out which will trigger a new `API.request` to get the _packages_ from the Verdaccio-server. This is done by creating a `useEffect` on **isUserLoggedIn**. Code has been transplanted from `App/App.tsx` including the use of the Loading component during the XHR. The use of **packages** was removed from other components as no longer needed and tests updated. Resolves issue #414 * fix: package list refresh based on logged-in user description: In `pages/home/Home.tsx` now monitoring any change in a user log-in/out which will trigger a new `API.request` to get the _packages_ from the Verdaccio-server. This is done by creating a `useEffect` on **isUserLoggedIn**. Code has been transplanted from `App/App.tsx` including the use of the Loading component during the XHR. The use of **packages** was removed from other components as no longer needed and tests updated. Test snapshots updated Resolves issue #414 Co-authored-by: Juan Picado @jotadeveloper <juanpicado19@gmail.com>
36 lines
1014 B
TypeScript
36 lines
1014 B
TypeScript
import React, { useEffect, useState } from 'react';
|
|
|
|
import { PackageList } from '../../components/PackageList';
|
|
import API from '../../utils/api';
|
|
import Loading from '../../components/Loading';
|
|
|
|
interface Props {
|
|
isUserLoggedIn: boolean;
|
|
}
|
|
|
|
const Home: React.FC<Props> = ({ isUserLoggedIn }) => {
|
|
const [packages, setPackages] = useState([]);
|
|
const [isLoading, setIsLoading] = useState(true);
|
|
const loadPackages = async () => {
|
|
try {
|
|
const packages = await API.request('packages', 'GET');
|
|
// FIXME add correct type for package
|
|
setPackages(packages as never[]);
|
|
} catch (error) {
|
|
// FIXME: add dialog
|
|
console.error({
|
|
title: 'Warning',
|
|
message: `Unable to load package list: ${error.message}`,
|
|
});
|
|
}
|
|
setIsLoading(false);
|
|
};
|
|
useEffect(() => {
|
|
loadPackages().then();
|
|
}, [isUserLoggedIn]);
|
|
|
|
return <div className="container content">{isLoading ? <Loading /> : <PackageList packages={packages} />}</div>;
|
|
};
|
|
|
|
export default Home;
|