Skip to content

Commit

Permalink
code smells
Browse files Browse the repository at this point in the history
  • Loading branch information
qdraw committed Nov 7, 2023
1 parent e631e5e commit c650902
Show file tree
Hide file tree
Showing 25 changed files with 198 additions and 225 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ namespace starsky.foundation.native.Trash.Helpers;
/// </summary>
[SuppressMessage("ReSharper", "InconsistentNaming")]
[SuppressMessage("Usage", "S101: Rename struct 'SHFILEOPSTRUCT' to match pascal case naming rules, consider using 'Shfileopstruct'.")]
[SuppressMessage("Usage", "S1075: Refactor your code not to use hardcoded absolute paths or URIs.")]
public static class WindowsShellTrashBindingHelper
{
/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,8 @@ const MenuArchive: React.FunctionComponent<IMenuArchiveProps> = memo(() => {

const toggleLabels = () => new Sidebar(setSidebar, history).toggleSidebar();

const [isModalExportOpen, setModalExportOpen] = useState(false);
const [isModalPublishOpen, setModalPublishOpen] = useState(false);
const [isModalExportOpen, setIsModalExportOpen] = useState(false);
const [isModalPublishOpen, setIsModalPublishOpen] = useState(false);

// Selection
const [select, setSelect] = React.useState(
Expand All @@ -96,11 +96,11 @@ const MenuArchive: React.FunctionComponent<IMenuArchiveProps> = memo(() => {
setSelect(new URLPath().StringToIUrl(history.location.search).select);
}, [history.location.search]);

const [isDisplayOptionsOpen, setDisplayOptionsOpen] = React.useState(false);
const [isSynchronizeManuallyOpen, setSynchronizeManuallyOpen] =
const [isDisplayOptionsOpen, setIsDisplayOptionsOpen] = React.useState(false);
const [isSynchronizeManuallyOpen, setIsSynchronizeManuallyOpen] =
React.useState(false);
const [isModalMkdirOpen, setModalMkdirOpen] = React.useState(false);
const [isModalRenameFolder, setModalRenameFolder] = React.useState(false);
const [isModalMkdirOpen, setIsModalMkdirOpen] = React.useState(false);
const [isModalRenameFolder, setIsModalRenameFolder] = React.useState(false);
const [dropAreaUploadFilesList, setDropAreaUploadFilesList] = React.useState(
newIFileIndexItemArray()
);
Expand Down Expand Up @@ -134,7 +134,7 @@ const MenuArchive: React.FunctionComponent<IMenuArchiveProps> = memo(() => {
{/* Modal download */}
{isModalExportOpen ? (
<ModalDownload
handleExit={() => setModalExportOpen(!isModalExportOpen)}
handleExit={() => setIsModalExportOpen(!isModalExportOpen)}

Check warning on line 137 in starsky/starsky/clientapp/src/components/organisms/menu-archive/menu-archive.tsx

View check run for this annotation

Codecov / codecov/patch

starsky/starsky/clientapp/src/components/organisms/menu-archive/menu-archive.tsx#L137

Added line #L137 was not covered by tests
select={new URLPath().MergeSelectParent(
select,
new URLPath().StringToIUrl(history.location.search).f
Expand All @@ -150,8 +150,7 @@ const MenuArchive: React.FunctionComponent<IMenuArchiveProps> = memo(() => {
{/* Modal Display options */}
{isDisplayOptionsOpen ? (
<ModalDisplayOptions
parentFolder={new URLPath().StringToIUrl(history.location.search).f}
handleExit={() => setDisplayOptionsOpen(!isDisplayOptionsOpen)}
handleExit={() => setIsDisplayOptionsOpen(!isDisplayOptionsOpen)}

Check warning on line 153 in starsky/starsky/clientapp/src/components/organisms/menu-archive/menu-archive.tsx

View check run for this annotation

Codecov / codecov/patch

starsky/starsky/clientapp/src/components/organisms/menu-archive/menu-archive.tsx#L153

Added line #L153 was not covered by tests
isOpen={isDisplayOptionsOpen}
/>
) : null}
Expand All @@ -161,7 +160,7 @@ const MenuArchive: React.FunctionComponent<IMenuArchiveProps> = memo(() => {
<ModalArchiveSynchronizeManually
parentFolder={new URLPath().StringToIUrl(history.location.search).f}
handleExit={() =>
setSynchronizeManuallyOpen(!isSynchronizeManuallyOpen)
setIsSynchronizeManuallyOpen(!isSynchronizeManuallyOpen)

Check warning on line 163 in starsky/starsky/clientapp/src/components/organisms/menu-archive/menu-archive.tsx

View check run for this annotation

Codecov / codecov/patch

starsky/starsky/clientapp/src/components/organisms/menu-archive/menu-archive.tsx#L163

Added line #L163 was not covered by tests
}
isOpen={isSynchronizeManuallyOpen}
/>
Expand All @@ -172,7 +171,7 @@ const MenuArchive: React.FunctionComponent<IMenuArchiveProps> = memo(() => {
<ModalArchiveMkdir
state={state}
dispatch={dispatch}
handleExit={() => setModalMkdirOpen(!isModalMkdirOpen)}
handleExit={() => setIsModalMkdirOpen(!isModalMkdirOpen)}

Check warning on line 174 in starsky/starsky/clientapp/src/components/organisms/menu-archive/menu-archive.tsx

View check run for this annotation

Codecov / codecov/patch

starsky/starsky/clientapp/src/components/organisms/menu-archive/menu-archive.tsx#L174

Added line #L174 was not covered by tests
isOpen={isModalMkdirOpen}
/>
) : null}
Expand All @@ -182,7 +181,7 @@ const MenuArchive: React.FunctionComponent<IMenuArchiveProps> = memo(() => {
subPath={state.subPath}
dispatch={dispatch}
handleExit={() => {
setModalRenameFolder(!isModalRenameFolder);
setIsModalRenameFolder(!isModalRenameFolder);

Check warning on line 184 in starsky/starsky/clientapp/src/components/organisms/menu-archive/menu-archive.tsx

View check run for this annotation

Codecov / codecov/patch

starsky/starsky/clientapp/src/components/organisms/menu-archive/menu-archive.tsx#L184

Added line #L184 was not covered by tests
}}
isOpen={isModalRenameFolder}
/>
Expand All @@ -203,7 +202,7 @@ const MenuArchive: React.FunctionComponent<IMenuArchiveProps> = memo(() => {
select={select}
stateFileIndexItems={state.fileIndexItems}
isModalPublishOpen={isModalPublishOpen}
setModalPublishOpen={setModalPublishOpen}
setModalPublishOpen={setIsModalPublishOpen}
/>

{/* Menu */}
Expand Down Expand Up @@ -258,9 +257,10 @@ const MenuArchive: React.FunctionComponent<IMenuArchiveProps> = memo(() => {
className={!readOnly ? "menu-option" : "menu-option disabled"}
data-test="mkdir"
tabIndex={0}
onClick={() => setModalMkdirOpen(!isModalMkdirOpen)}
onClick={() => setIsModalMkdirOpen(!isModalMkdirOpen)}
onKeyDown={(event) => {
event.key === "Enter" && setModalMkdirOpen(!isModalMkdirOpen);
event.key === "Enter" &&
setIsModalMkdirOpen(!isModalMkdirOpen);
}}
>
{MessageMkdir}
Expand All @@ -269,10 +269,10 @@ const MenuArchive: React.FunctionComponent<IMenuArchiveProps> = memo(() => {
className="menu-option"
data-test="display-options"
tabIndex={0}
onClick={() => setDisplayOptionsOpen(!isDisplayOptionsOpen)}
onClick={() => setIsDisplayOptionsOpen(!isDisplayOptionsOpen)}
onKeyDown={(event) => {
event.key === "Enter" &&
setDisplayOptionsOpen(!isDisplayOptionsOpen);
setIsDisplayOptionsOpen(!isDisplayOptionsOpen);
}}
>
{MessageDisplayOptions}
Expand All @@ -281,7 +281,7 @@ const MenuArchive: React.FunctionComponent<IMenuArchiveProps> = memo(() => {
isReadOnly={false}
testName="synchronize-manually"
isSet={isSynchronizeManuallyOpen}
set={setSynchronizeManuallyOpen}
set={setIsSynchronizeManuallyOpen}
localization={localization.MessageSynchronizeManually}
/>
{state ? <UploadMenuItem /> : null}
Expand All @@ -292,10 +292,10 @@ const MenuArchive: React.FunctionComponent<IMenuArchiveProps> = memo(() => {
: "menu-option disabled"
}
data-test="rename"
onClick={() => setModalRenameFolder(!isModalRenameFolder)}
onClick={() => setIsModalRenameFolder(!isModalRenameFolder)}
onKeyDown={(event) => {
event.key === "Enter" &&
setModalRenameFolder(!isModalRenameFolder);
setIsModalRenameFolder(!isModalRenameFolder);
}}
>
{MessageRenameDir}
Expand Down Expand Up @@ -334,14 +334,14 @@ const MenuArchive: React.FunctionComponent<IMenuArchiveProps> = memo(() => {
isReadOnly={false}
testName="export"
isSet={isModalExportOpen}
set={setModalExportOpen}
set={setIsModalExportOpen}
localization={localization.MessageDownload}
/>
<MenuOption
isReadOnly={false}
testName="publish"
isSet={isModalPublishOpen}
set={setModalPublishOpen}
set={setIsModalPublishOpen}
localization={localization.MessagePublish}
/>
<MenuOptionMoveToTrash
Expand All @@ -356,10 +356,10 @@ const MenuArchive: React.FunctionComponent<IMenuArchiveProps> = memo(() => {
<li
className="menu-option"
data-test="display-options"
onClick={() => setDisplayOptionsOpen(!isDisplayOptionsOpen)}
onClick={() => setIsDisplayOptionsOpen(!isDisplayOptionsOpen)}
onKeyDown={(event) => {
event.key === "Enter" &&
setDisplayOptionsOpen(!isDisplayOptionsOpen);
setIsDisplayOptionsOpen(!isDisplayOptionsOpen);
}}
>
{MessageDisplayOptions}
Expand All @@ -369,7 +369,7 @@ const MenuArchive: React.FunctionComponent<IMenuArchiveProps> = memo(() => {
isReadOnly={false}
testName="synchronize-manually"
isSet={isSynchronizeManuallyOpen}
set={setSynchronizeManuallyOpen}
set={setIsSynchronizeManuallyOpen}
localization={localization.MessageSynchronizeManually}
/>
{state ? <UploadMenuItem /> : null}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,56 +109,56 @@ const MenuDetailView: React.FunctionComponent<MenuDetailViewProps> = ({
}, [history.location.search]);

/* show marker with 'Saved' */
const [isRecentEdited, setRecentEdited] = React.useState(
const [isRecentEdited, setIsRecentEdited] = React.useState(
IsEditedNow(state?.fileIndexItem?.lastEdited)
);
useEffect(() => {
if (!state?.fileIndexItem?.lastEdited) return;
const isEditedNow = IsEditedNow(state.fileIndexItem.lastEdited);
if (!isEditedNow) {
setRecentEdited(false);
setIsRecentEdited(false);
return;
}
setRecentEdited(isEditedNow);
setIsRecentEdited(isEditedNow);
}, [state?.fileIndexItem?.lastEdited]);

function toggleLabels() {
const urlObject = new URLPath().StringToIUrl(history.location.search);
urlObject.details = !details;
setDetails(urlObject.details);
setRecentEdited(false); // disable to avoid animation
setIsRecentEdited(false); // disable to avoid animation
history.navigate(new URLPath().IUrlToString(urlObject), { replace: true });
}

const [isMarkedAsDeleted, setMarkedAsDeleted] = React.useState(
const [isMarkedAsDeleted, setIsMarkedAsDeleted] = React.useState(
state?.fileIndexItem?.status === IExifStatus.Deleted
);
const [enableMoreMenu, setEnableMoreMenu] = React.useState(false);

/* only update when the state is changed */
useEffect(() => {
setMarkedAsDeleted(state.fileIndexItem.status === IExifStatus.Deleted);
setIsMarkedAsDeleted(state.fileIndexItem.status === IExifStatus.Deleted);
}, [state.fileIndexItem.status, history.location.search]);

const [isSourceMissing, setSourceMissing] = React.useState(
const [isSourceMissing, setIsSourceMissing] = React.useState(
state.fileIndexItem.status === IExifStatus.NotFoundSourceMissing
);

useEffect(() => {
setSourceMissing(
setIsSourceMissing(
state.fileIndexItem.status === IExifStatus.NotFoundSourceMissing
);
setReadOnly(
setIsReadOnly(
state.fileIndexItem.status === IExifStatus.NotFoundSourceMissing
);
}, [state.fileIndexItem.status, history.location.search]);

/* only update when the state is changed */
const [isReadOnly, setReadOnly] = React.useState(state.isReadOnly);
const [isReadOnly, setIsReadOnly] = React.useState(state.isReadOnly);
useEffect(() => {
if (state.fileIndexItem.status === IExifStatus.NotFoundSourceMissing)
return;
setReadOnly(state.isReadOnly);
setIsReadOnly(state.isReadOnly);
}, [state.isReadOnly, state.fileIndexItem.status]);

// preloading icon
Expand Down Expand Up @@ -317,10 +317,11 @@ const MenuDetailView: React.FunctionComponent<MenuDetailViewProps> = ({
TrashFile();
});

const [isModalExportOpen, setModalExportOpen] = React.useState(false);
const [isModalRenameFileOpen, setModalRenameFileOpen] = React.useState(false);
const [isModalMoveFile, setModalMoveFile] = React.useState(false);
const [isModalPublishOpen, setModalPublishOpen] = useState(false);
const [isModalExportOpen, setIsModalExportOpen] = React.useState(false);
const [isModalRenameFileOpen, setIsModalRenameFileOpen] =
React.useState(false);
const [isModalMoveFile, setIsModalMoveFile] = React.useState(false);
const [isModalPublishOpen, setIsModalPublishOpen] = useState(false);

return (
<>
Expand All @@ -330,23 +331,23 @@ const MenuDetailView: React.FunctionComponent<MenuDetailViewProps> = ({
{isModalExportOpen && state && !isSourceMissing ? (
<ModalDownload
collections={false}
handleExit={() => setModalExportOpen(!isModalExportOpen)}
handleExit={() => setIsModalExportOpen(!isModalExportOpen)}

Check warning on line 334 in starsky/starsky/clientapp/src/components/organisms/menu-detail-view/menu-detail-view.tsx

View check run for this annotation

Codecov / codecov/patch

starsky/starsky/clientapp/src/components/organisms/menu-detail-view/menu-detail-view.tsx#L334

Added line #L334 was not covered by tests
select={[state.subPath]}
isOpen={isModalExportOpen}
/>
) : null}
{isModalRenameFileOpen && state && !isReadOnly ? (
<ModalDetailviewRenameFile
state={state}
handleExit={() => setModalRenameFileOpen(!isModalRenameFileOpen)}
handleExit={() => setIsModalRenameFileOpen(!isModalRenameFileOpen)}

Check warning on line 342 in starsky/starsky/clientapp/src/components/organisms/menu-detail-view/menu-detail-view.tsx

View check run for this annotation

Codecov / codecov/patch

starsky/starsky/clientapp/src/components/organisms/menu-detail-view/menu-detail-view.tsx#L342

Added line #L342 was not covered by tests
isOpen={isModalRenameFileOpen}
/>
) : null}
{isModalMoveFile && state && !isReadOnly ? (
<ModalMoveFile
selectedSubPath={state.fileIndexItem.filePath}
parentDirectory={state.fileIndexItem.parentDirectory}
handleExit={() => setModalMoveFile(!isModalMoveFile)}
handleExit={() => setIsModalMoveFile(!isModalMoveFile)}

Check warning on line 350 in starsky/starsky/clientapp/src/components/organisms/menu-detail-view/menu-detail-view.tsx

View check run for this annotation

Codecov / codecov/patch

starsky/starsky/clientapp/src/components/organisms/menu-detail-view/menu-detail-view.tsx#L350

Added line #L350 was not covered by tests
isOpen={isModalMoveFile}
/>
) : null}
Expand All @@ -355,7 +356,7 @@ const MenuDetailView: React.FunctionComponent<MenuDetailViewProps> = ({
select={[state.fileIndexItem.fileName]}
stateFileIndexItems={[state.fileIndexItem]}
isModalPublishOpen={isModalPublishOpen}
setModalPublishOpen={setModalPublishOpen}
setModalPublishOpen={setIsModalPublishOpen}
/>

<header className={GetHeaderClass(details, isMarkedAsDeleted)}>
Expand Down Expand Up @@ -419,9 +420,10 @@ const MenuDetailView: React.FunctionComponent<MenuDetailViewProps> = ({
!isSourceMissing ? "menu-option" : "menu-option disabled"
}
data-test="export"
onClick={() => setModalExportOpen(!isModalExportOpen)}
onClick={() => setIsModalExportOpen(!isModalExportOpen)}
onKeyDown={(event) => {
event.key === "Enter" && setModalExportOpen(!isModalExportOpen);
event.key === "Enter" &&
setIsModalExportOpen(!isModalExportOpen);
}}
>
Download
Expand All @@ -443,9 +445,9 @@ const MenuDetailView: React.FunctionComponent<MenuDetailViewProps> = ({
tabIndex={0}
className={!isReadOnly ? "menu-option" : "menu-option disabled"}
data-test="move"
onClick={() => setModalMoveFile(!isModalMoveFile)}
onClick={() => setIsModalMoveFile(!isModalMoveFile)}
onKeyDown={(event) => {
event.key === "Enter" && setModalMoveFile(!isModalMoveFile);
event.key === "Enter" && setIsModalMoveFile(!isModalMoveFile);
}}
>
{MessageMove}
Expand All @@ -454,10 +456,10 @@ const MenuDetailView: React.FunctionComponent<MenuDetailViewProps> = ({
tabIndex={0}
className={!isReadOnly ? "menu-option" : "menu-option disabled"}
data-test="rename"
onClick={() => setModalRenameFileOpen(!isModalRenameFileOpen)}
onClick={() => setIsModalRenameFileOpen(!isModalRenameFileOpen)}
onKeyDown={(event) => {
event.key === "Enter" &&
setModalRenameFileOpen(!isModalRenameFileOpen);
setIsModalRenameFileOpen(!isModalRenameFileOpen);
}}
>
{MessageRenameFileName}
Expand Down Expand Up @@ -501,7 +503,7 @@ const MenuDetailView: React.FunctionComponent<MenuDetailViewProps> = ({
isReadOnly={false}
testName="publish"
isSet={isModalPublishOpen}
set={setModalPublishOpen}
set={setIsModalPublishOpen}
localization={localization.MessagePublish}
/>
</MoreMenu>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,16 +76,16 @@ export const MenuSearch: React.FunctionComponent<IMenuSearchProps> = ({
const toggleLabels = () => new Sidebar(setSidebar, history).toggleSidebar();

// download modal
const [isModalExportOpen, setModalExportOpen] = useState(false);
const [isModalExportOpen, setIsModalExportOpen] = useState(false);
// publish modal
const [isModalPublishOpen, setModalPublishOpen] = useState(false);
const [isModalPublishOpen, setIsModalPublishOpen] = useState(false);

return (
<>
{/* Modal download */}
{isModalExportOpen ? (
<ModalDownload
handleExit={() => setModalExportOpen(!isModalExportOpen)}
handleExit={() => setIsModalExportOpen(!isModalExportOpen)}

Check warning on line 88 in starsky/starsky/clientapp/src/components/organisms/menu-search/menu-search.tsx

View check run for this annotation

Codecov / codecov/patch

starsky/starsky/clientapp/src/components/organisms/menu-search/menu-search.tsx#L88

Added line #L88 was not covered by tests
select={
select
? new URLPath().MergeSelectFileIndexItem(
Expand All @@ -103,7 +103,7 @@ export const MenuSearch: React.FunctionComponent<IMenuSearchProps> = ({
select={select}
stateFileIndexItems={state.fileIndexItems}
isModalPublishOpen={isModalPublishOpen}
setModalPublishOpen={setModalPublishOpen}
setModalPublishOpen={setIsModalPublishOpen}
/>

<header className={GetArchiveSearchMenuHeaderClass(sidebar, select)}>
Expand Down Expand Up @@ -195,14 +195,14 @@ export const MenuSearch: React.FunctionComponent<IMenuSearchProps> = ({
isReadOnly={false}
testName="export"
isSet={isModalExportOpen}
set={setModalExportOpen}
set={setIsModalExportOpen}
localization={localization.MessageDownload}
/>
<MenuOption
isReadOnly={false}
testName="publish"
isSet={isModalPublishOpen}
set={setModalPublishOpen}
set={setIsModalPublishOpen}
localization={localization.MessagePublish}
/>
<MenuOptionMoveToTrash
Expand Down
Loading

0 comments on commit c650902

Please sign in to comment.