Skip to content

fixed images not showing issue on refresh for multiple uploads #55

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 18, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 28 additions & 3 deletions client/src/Annotation/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import SetupPage from "../SetupPage";
import { useSettings } from "../SettingsProvider";
import {setIn} from "seamless-immutable"
import config from '../config.js';
import { useSnackbar } from '../SnackbarContext'

const extractRelevantProps = (region) => ({
cls: region.cls,
Expand Down Expand Up @@ -50,6 +51,7 @@ export default () => {
const [showLabel, setShowLabel] = useState(false)
const [imageNames, setImageNames] = useState([])
const settingsConfig = useSettings()
const { showSnackbar } = useSnackbar();
const [settings, setSettings] = useState({
taskDescription: "",
taskChoice: "image_classification",
Expand Down Expand Up @@ -114,6 +116,24 @@ export default () => {
}
};

const fetchImages = async (imageUrls) => {
try {
const fetchPromises = imageUrls.map(url =>
fetch(url.src).then(response => response.blob())
.then(blob => ({ ...url, src: URL.createObjectURL(blob) }))
);
const images = await Promise.all(fetchPromises);
setSettings(prevSettings => ({
...prevSettings,
images
}));
setImageNames(images);
} catch (error) {
showSnackbar(error.message, 'error');
} finally {
setLoading(false);
}
}

const getToolSelectionType = (toolName) => {
const regions = [ {name: "Polygon", value: "create-polygon"}, {name: "Bounding Box", value: "create-box"}, {name: "Point", value: "create-point"}]
Expand All @@ -129,9 +149,14 @@ export default () => {
}

useEffect(() => {
preloadConfiguration()
setLoading(false);
}, []);
preloadConfiguration();
if (settings.images.length > 0) {
fetchImages(settings.images);
} else {
setLoading(false);
}
}, [settingsConfig.settings, showLabel]);


return (
<>
Expand Down
Loading