Skip to content

Commit

Permalink
ref: resolve todos
Browse files Browse the repository at this point in the history
  • Loading branch information
githubering182 committed Jun 21, 2024
1 parent 7b56758 commit 1f407bd
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 52 deletions.
2 changes: 1 addition & 1 deletion frontend-app/src/components/FilesValidate/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ export default function FilesValidation({ pathID, attributes, canValidate }) {

if (!card.length) handleChange("card", ['v']);

// TODO: query collectors depend on uploads to project by users, REFACTOR!
// TODO: query collectors depend on uploads to project by users. REFACTOR!
Promise.allSettled([
api.get(`/api/files/project/${pathID}/`, {
params: { card, attr, type, author, from: date?.from, to: date?.to, page, dateSort },
Expand Down
1 change: 0 additions & 1 deletion frontend-app/src/components/ProjectEdit/component.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,5 @@ test("project edit component test", async () => {
await tryDelete("some");
expect(alertTrigger).toBeTruthy();
expect(screen.queryByText(/Are you sure you want to delete/)).toBeNull();
// TODO: resolve warning
await tryDelete("project name");
});
33 changes: 11 additions & 22 deletions frontend-app/src/components/common/DownloadView/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,26 +12,14 @@ import "./styles.css";
* @returns {ReactElement}
*/
export default function DownloadView({ taskID }) {
const [intervalCheck, setIntervalCheck] = useState(false);
const [message, setMessage] = useState("");
const [download, setDownload] = useState(false);
const [pageBlock] = useState(true);
const dispatch = useDispatch();
const componentRef = useRef(null);
const intervalCheck = useRef(null);

// TODO: couldnt clear interval the normal way.
// useref as store for handler might help
// consider ^ + dinf similar issues everywhere
const Helper = () => {
useEffect(() => {
var interval = setInterval(checkTaskStatus, 5000);
return () => {
clearInterval(interval);
};
}, []);
};

async function copyID({ clientX: X, clientY: Y }) {
const copyID = async ({ clientX: X, clientY: Y }) => {
var clipboardTip = document.createElement("div");

clipboardTip.className = "iss__downloadingView__clipboardTip";
Expand Down Expand Up @@ -63,7 +51,7 @@ export default function DownloadView({ taskID }) {
componentRef.current.appendChild(clipboardTip);

setTimeout(() => clipboardTip.parentNode.removeChild(clipboardTip), 500);
}
};

const statusHandlers = {
SUCCESS: (archiveID) => {
Expand All @@ -79,7 +67,7 @@ export default function DownloadView({ taskID }) {
}
};

async function getDataset(archiveId) {
const getDataset = async (archiveId) => {
setDownload(true);

try {
Expand Down Expand Up @@ -112,9 +100,9 @@ export default function DownloadView({ taskID }) {
noSession: authFailed
}));
}
}
};

async function checkTaskStatus() {
const checkTaskStatus = async () => {
try {
var { data } = await fileApi.get(`/api/task/${taskID}/`, {
headers: { Authorization: "Bearer " + localStorage.getItem("dtcAccess") },
Expand All @@ -123,7 +111,8 @@ export default function DownloadView({ taskID }) {
var handler = statusHandlers[status];

if (handler) {
setIntervalCheck(false);
clearInterval(intervalCheck.current);
intervalCheck.current = null;
handler(archive_id);
}
}
Expand All @@ -138,7 +127,7 @@ export default function DownloadView({ taskID }) {
noSession: authFailed
}));
}
}
};

useBlocker(() => {
return pageBlock
Expand All @@ -155,13 +144,13 @@ export default function DownloadView({ taskID }) {
}, [pageBlock]);

useEffect(() => {
setIntervalCheck(true);
checkTaskStatus();
const interval = setInterval(checkTaskStatus, 5000);
intervalCheck.current = interval;
}, []);

return (
<>
{intervalCheck && <Helper />}
<div ref={componentRef} className="iss__downloadingView__title">
<h2>Task id: </h2>
<span
Expand Down
48 changes: 26 additions & 22 deletions frontend-app/src/components/ui/FileMedia/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,20 @@ import { addAlert } from "../../../slices/alerts";
import { useDispatch } from "react-redux";
import "./styles.css";

const FALLBACK_SRC = "/images/fallback-media.svg";

/**
* @type {Function}
* @param {object} event
* @param {object} event.target
* @returns {void}
*/
var handleMediaFallback = ({ target }) => {
var fallbackSrc = "/images/fallback-media.svg";

// TODO: after this fallback controls wont show up again, fix
const handleMediaFallback = ({ target }) => {
if (target.tagName === "VIDEO") {
target.controls = false;
target.poster = fallbackSrc;
target.poster = FALLBACK_SRC;
}
else target.src = fallbackSrc;
else target.src = FALLBACK_SRC;
};

/**
Expand All @@ -47,17 +46,17 @@ function FileMedia({ files, slide, pathID }, ref) {
const navigate = useNavigate();
const mediaRef = useRef(null);

var MediaItem = useCallback((props) => {
const MediaItem = useCallback((props) => {
return typeVideo
? <video
autoPlay
muted
controls
playsInline
controls
{ ...props }
onError={(e) => handleMediaFallback(e)}
onError={handleMediaFallback}
/>
: <img alt="validation_item" {...props} onError={(e) => handleMediaFallback(e)} />;
: <img alt="media" {...props} onError={handleMediaFallback} />;
}, [fileUrl]);

let scale = 1,
Expand All @@ -66,46 +65,46 @@ function FileMedia({ files, slide, pathID }, ref) {
pointY = 0,
start = { x: 0, y: 0 };

function resetZoom() {
const resetZoom = () => {
scale = 1;
panning = false;
pointX = 0;
pointY = 0;
start = { x: 0, y: 0 };
setTransform();
}
};

useImperativeHandle(ref, () => resetZoom);

function setTransform() {
const setTransform = () => {
mediaRef.current.style.transform = `translate(${pointX}px, ${pointY}px) scale(${scale})`;
}
};

function handleMouseDown(ev) {
const handleMouseDown = (ev) => {
ev.preventDefault();
start = { x: ev.clientX - pointX, y: ev.clientY - pointY };
panning = true;
}
};

function handleMouseUp() { panning = false; }
const handleMouseUp = () => panning = false;

function handleMouseMove(ev) {
const handleMouseMove = (ev) => {
ev.preventDefault();
if (!panning) return;
pointX = ev.clientX - start.x;
pointY = ev.clientY - start.y;
setTransform();
}
};

function handleWheel(ev) {
const handleWheel = (ev) => {
let xs = (ev.clientX - pointX) / scale,
ys = (ev.clientY - pointY) / scale,
delta = (ev.wheelDelta ? ev.wheelDelta : -ev.deltaY);
(delta > 0) ? (scale *= 1.05) : (scale /= 1.05);
pointX = ev.clientX - xs * scale;
pointY = ev.clientY - ys * scale;
setTransform();
}
};

useEffect(() => {
var media = mediaRef.current;
Expand Down Expand Up @@ -161,7 +160,12 @@ function FileMedia({ files, slide, pathID }, ref) {
onMouseMove={handleMouseMove}
onWheel={handleWheel}
className="mediaItem"
>{fileUrl && <MediaItem src={fileUrl} className='mediaFile' />}</div>
>
{
fileUrl &&
<MediaItem src={fileUrl} className='mediaFile' />
}
</div>
</div>
);
}
Expand Down
2 changes: 1 addition & 1 deletion frontend-app/src/pages/Registration/component.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,5 @@ test("login page test", () => {

expect(nav.title).toBe("Registration");
expect(nav.nav).toHaveLength(2);
// TODO: resolve same issue as in login
// TODO: resolve same issue as at login
});
5 changes: 3 additions & 2 deletions storage-app/src/shared/app_services.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,8 +177,9 @@ async def _set_hash(self, file_item: dict[str, Any]) -> None:
{"metadata.hash": new_hash}
)

# TODO: this fetch is gonna be depracated
if await cursor.fetch_next: raise AssertionError
try:
if await cursor.next(): raise AssertionError
except StopAsyncIteration: ...

file_item["metadata"]["hash"] = new_hash

Expand Down
3 changes: 0 additions & 3 deletions storage-app/src/shared/worker_services.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,7 @@ async def archive_objects(self) -> Optional[bool]:
self.archive = f"{self.temp_prefix}/{ObjectId()}.{self.archive_extension}"
json_data: Any = dumps(self.annotation, indent=4).encode('utf-8')

# TODO: check other compress types
with ZipFile(self.archive, 'w', ZIP_DEFLATED) as zip:
# TODO: proper iterating had fetch_next but it returns int apparently
# can use db's io loop
try:
while object := await self.object_set.next():
zip.writestr(self._get_object_name(object), object.read())
Expand Down

0 comments on commit 1f407bd

Please sign in to comment.