🐛 API endpoints not working with multiple widgets

This commit is contained in:
Meier Lukas
2023-03-30 23:15:08 +02:00
parent 18d58ad4e7
commit 77c8cb8f9e
12 changed files with 103 additions and 38 deletions

View File

@@ -63,7 +63,7 @@ function CalendarTile({ widget }: CalendarTileProps) {
await fetch(
`/api/modules/calendar?year=${month.getFullYear()}&month=${
month.getMonth() + 1
}&configName=${configName}`
}&configName=${configName}&id=${widget.id}`
)
).json()) as MediasType,
});

View File

@@ -9,11 +9,12 @@ import { DashDotInfo } from './DashDotCompactNetwork';
interface DashDotCompactStorageProps {
info: DashDotInfo;
widgetId: string;
}
export const DashDotCompactStorage = ({ info }: DashDotCompactStorageProps) => {
export const DashDotCompactStorage = ({ info, widgetId }: DashDotCompactStorageProps) => {
const { t } = useTranslation('modules/dashdot');
const { data: storageLoad } = useDashDotStorage();
const { data: storageLoad } = useDashDotStorage(widgetId);
const totalUsed = calculateTotalLayoutSize({
layout: storageLoad?.layout ?? [],
@@ -50,7 +51,7 @@ interface CalculateTotalLayoutSizeProps<TLayoutItem> {
key: keyof TLayoutItem;
}
const useDashDotStorage = () => {
const useDashDotStorage = (widgetId: string) => {
const { name: configName, config } = useConfigContext();
return useQuery({
@@ -59,16 +60,17 @@ const useDashDotStorage = () => {
{
configName,
url: config?.widgets.find((x) => x.type === 'dashdot')?.properties.url,
widgetId,
},
],
queryFn: () => fetchDashDotStorageLoad(configName),
queryFn: () => fetchDashDotStorageLoad(configName, widgetId),
});
};
async function fetchDashDotStorageLoad(configName: string | undefined) {
async function fetchDashDotStorageLoad(configName: string | undefined, widgetId: string) {
if (!configName) throw new Error('configName is undefined');
return (await (
await axios.get('/api/modules/dashdot/storage', { params: { configName } })
await axios.get('/api/modules/dashdot/storage', { params: { configName, widgetId } })
).data) as DashDotStorageLoad;
}

View File

@@ -11,6 +11,7 @@ interface DashDotGraphProps {
dashDotUrl: string;
usePercentages: boolean;
info: DashDotInfo;
widgetId: string;
}
export const DashDotGraph = ({
@@ -21,12 +22,13 @@ export const DashDotGraph = ({
dashDotUrl,
usePercentages,
info,
widgetId,
}: DashDotGraphProps) => {
const { t } = useTranslation('modules/dashdot');
const { classes } = useStyles();
if (graph === 'storage' && isCompact) {
return <DashDotCompactStorage info={info} />;
return <DashDotCompactStorage info={info} widgetId={widgetId} />;
}
if (graph === 'network' && isCompact) {

View File

@@ -160,6 +160,7 @@ function DashDotTile({ widget }: DashDotTileProps) {
const { data: info } = useDashDotInfo({
dashDotUrl,
enabled: !detectedProtocolDowngrade,
widgetId: widget.id,
});
if (detectedProtocolDowngrade) {
@@ -197,6 +198,7 @@ function DashDotTile({ widget }: DashDotTileProps) {
isCompact={g.subValues.compactView ?? false}
multiView={g.subValues.multiView ?? false}
usePercentages={usePercentages}
widgetId={widget.id}
/>
</Grid.Col>
))}
@@ -207,7 +209,15 @@ function DashDotTile({ widget }: DashDotTileProps) {
);
}
const useDashDotInfo = ({ dashDotUrl, enabled }: { dashDotUrl: string; enabled: boolean }) => {
const useDashDotInfo = ({
dashDotUrl,
enabled,
widgetId,
}: {
dashDotUrl: string;
enabled: boolean;
widgetId: string;
}) => {
const { name: configName } = useConfigContext();
return useQuery({
refetchInterval: 50000,
@@ -218,15 +228,15 @@ const useDashDotInfo = ({ dashDotUrl, enabled }: { dashDotUrl: string; enabled:
dashDotUrl,
},
],
queryFn: () => fetchDashDotInfo(configName),
queryFn: () => fetchDashDotInfo(configName, widgetId),
enabled,
});
};
const fetchDashDotInfo = async (configName: string | undefined) => {
const fetchDashDotInfo = async (configName: string | undefined, widgetId: string) => {
if (!configName) return {} as DashDotInfo;
return (await (
await axios.get('/api/modules/dashdot/info', { params: { configName } })
await axios.get('/api/modules/dashdot/info', { params: { configName, widgetId } })
).data) as DashDotInfo;
};

View File

@@ -60,7 +60,8 @@ interface RssTileProps {
function RssTile({ widget }: RssTileProps) {
const { t } = useTranslation('modules/rss');
const { data, isLoading, isFetching, isError, refetch } = useGetRssFeed(
widget.properties.rssFeedUrl
widget.properties.rssFeedUrl,
widget.id
);
const { classes } = useStyles();
const [loadingOverlayVisible, setLoadingOverlayVisible] = useState(false);