Skip to content

Commit

Permalink
code smells
Browse files Browse the repository at this point in the history
  • Loading branch information
qdraw committed Oct 21, 2023
1 parent 3af8cde commit 1434516
Show file tree
Hide file tree
Showing 22 changed files with 147 additions and 156 deletions.
10 changes: 5 additions & 5 deletions starsky/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ RUN rm /app/global.json

RUN \
if [ "$TARGETPLATFORM" = "linux/amd64" ]; then \
echo $TARGETPLATFORM ; \
echo "$TARGETPLATFORM" ; \
dotnet restore --runtime linux-x64 starsky.csproj ; \
elif [ "$TARGETPLATFORM" = "linux/arm64" ]; then \
dotnet restore --runtime linux-arm64 starsky.csproj ; \
Expand Down Expand Up @@ -85,9 +85,9 @@ RUN \
DEMO_SEED_CLI_PATH="/app/starskydemoseedcli/starskydemoseedcli.csproj" ;\
DEPS_FOLDER="/app/dependencies" ;\
TEMP_FOLDER="/app/temp" ;\
mkdir -p $DEPS_FOLDER ;\
mkdir -p $TEMP_FOLDER ;\
dotnet run --project $DEMO_SEED_CLI_PATH --configuration Release -- --dependencies $DEPS_FOLDER --tempfolder $TEMP_FOLDER -h -v ;\
mkdir -p "$DEPS_FOLDER" ;\
mkdir -p "$TEMP_FOLDER" ;\
dotnet run --project "$DEMO_SEED_CLI_PATH" --configuration Release -- --dependencies "$DEPS_FOLDER" --tempfolder "$TEMP_FOLDER" -h -v ;\
fi

# no alpine build since there is no support for multi-arch
Expand All @@ -101,7 +101,7 @@ WORKDIR /app
RUN if [ "$TEST" = "true" ]; then \
mkdir -p "/testresults" ;\
if [ "$BUILDPLATFORM" = "$TARGETPLATFORM" ]; then \
echo $TEST $BUILDPLATFORM $TARGETPLATFORM ; \
echo "$TEST" "$BUILDPLATFORM" "$TARGETPLATFORM" ; \
dotnet test -c release --results-directory /testresults --logger "trx;LogFileName=test_results.trx" --collect:"XPlat Code Coverage" --settings build.vstest.runsettings starskytest/starskytest.csproj ; \
fi ;\
touch "/testresults/test.enabled" ;\
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#nullable enable
using System;
using System.Collections.Generic;
using System.Linq;
Expand All @@ -20,11 +21,11 @@ public class CheckForUpdates : ICheckForUpdates
{
internal const string GithubApi = "https://api.github.com/repos/qdraw/starsky/releases";

private readonly AppSettings _appSettings;
private readonly IMemoryCache _cache;
private readonly AppSettings? _appSettings;
private readonly IMemoryCache? _cache;
private readonly IHttpClientHelper _httpClientHelper;

public CheckForUpdates(IHttpClientHelper httpClientHelper, AppSettings appSettings, IMemoryCache cache)
public CheckForUpdates(IHttpClientHelper httpClientHelper, AppSettings? appSettings, IMemoryCache? cache)
{
_httpClientHelper = httpClientHelper;
_appSettings = appSettings;
Expand All @@ -47,31 +48,36 @@ public async Task<KeyValuePair<UpdateStatus, string>> IsUpdateNeeded(string curr
? _appSettings.AppVersion : currentVersion;

// The CLI programs uses no cache
if( _cache == null || _appSettings?.AddMemoryCache == false)
if ( _cache == null || _appSettings?.AddMemoryCache == false )
{
return Parse(await QueryIsUpdateNeededAsync(),currentVersion);
}

if ( _cache.TryGetValue(QueryCheckForUpdatesCacheName, out var cacheResult) )
if ( _cache.TryGetValue(QueryCheckForUpdatesCacheName,
out var cacheResult) )
{
return Parse(( List<ReleaseModel> ) cacheResult, currentVersion);
}

cacheResult = await QueryIsUpdateNeededAsync();

_cache.Set(QueryCheckForUpdatesCacheName, cacheResult,
new TimeSpan(48,0,0));
new TimeSpan(48,0,0));

return Parse(( List<ReleaseModel> ) cacheResult,currentVersion);
return Parse(( List<ReleaseModel>? ) cacheResult,currentVersion);
}

internal async Task<List<ReleaseModel>> QueryIsUpdateNeededAsync()
internal async Task<List<ReleaseModel>?> QueryIsUpdateNeededAsync()
{
// argument check is done in QueryIsUpdateNeeded
var (key, value) = await _httpClientHelper.ReadString(GithubApi);
return !key ? new List<ReleaseModel>() : JsonSerializer.Deserialize<List<ReleaseModel>>(value, new JsonSerializerOptions());
}

internal static KeyValuePair<UpdateStatus, string> Parse(IEnumerable<ReleaseModel> releaseModelList, string currentVersion )
internal static KeyValuePair<UpdateStatus, string> Parse(IEnumerable<ReleaseModel>? releaseModelList, string currentVersion )
{
var orderedReleaseModelList = releaseModelList.OrderByDescending(p => p.TagName);
var tagName = orderedReleaseModelList.FirstOrDefault(p => !p.Draft && !p.PreRelease)?.TagName;
var orderedReleaseModelList = releaseModelList?.OrderByDescending(p => p.TagName);
var tagName = orderedReleaseModelList?.FirstOrDefault(p => !p.Draft && !p.PreRelease)?.TagName;
if ( string.IsNullOrWhiteSpace(tagName) ||
!tagName.StartsWith('v') )
{
Expand Down
10 changes: 5 additions & 5 deletions starsky/starsky.feature.search/ViewModels/SearchViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -546,15 +546,15 @@ private static SearchViewModel PropertySearchStringType(
model.FileIndexItems = model.FileIndexItems!.Where(
p => p.GetType().GetProperty(property.Name)?.Name == property.Name
&& ! // not
p.GetType().GetProperty(property.Name)!.GetValue(p, null)!
.ToString()!.ToLowerInvariant().Contains(searchForQuery)
p.GetType().GetProperty(property.Name)!.GetValue(p, null)?
.ToString()?.ToLowerInvariant().Contains(searchForQuery) == true
).ToList();
break;
default:
model.FileIndexItems = model.FileIndexItems!
model.FileIndexItems = model.FileIndexItems?
.Where(p => p.GetType().GetProperty(property.Name)?.Name == property.Name
&& p.GetType().GetProperty(property.Name)!.GetValue(p, null)!
.ToString()!.ToLowerInvariant().Contains(searchForQuery)
&& p.GetType().GetProperty(property.Name)!.GetValue(p, null)?
.ToString()?.ToLowerInvariant().Contains(searchForQuery) == true
).ToList();
break;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ public void BuilderDb(string? foundationDatabaseName = "")
if ( _logger != null && _appSettings.IsVerbose() )
{
_logger.LogInformation($"Database connection: {_appSettings.DatabaseConnection}");
_logger?.LogInformation($"Application Insights Database tracking is {IsDatabaseTrackingEnabled()}" );
_logger.LogInformation($"Application Insights Database tracking is {IsDatabaseTrackingEnabled()}" );
}

#if ENABLE_DEFAULT_DATABASE
Expand Down
3 changes: 2 additions & 1 deletion starsky/starsky.foundation.database/Models/FileIndexItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -481,7 +481,8 @@ public static List<string> FileIndexPropList()
var fileIndexPropList = new List<string>();
// only for types String in FileIndexItem()

foreach (var propertyInfo in new FileIndexItem().GetType().GetProperties())
var allProperties = new FileIndexItem().GetType().GetProperties();
foreach (var propertyInfo in allProperties)
{
if ((
propertyInfo.PropertyType == typeof(bool) ||
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ private static FileIndexItem GetDataNullNameSpaceTypes(IXmpMeta xmp, FileIndexIt
!string.IsNullOrEmpty(property.Value) &&
string.IsNullOrEmpty(property.Namespace) )
{
StringBuilder tagsStringBuilder = new StringBuilder();
var tagsStringBuilder = new StringBuilder();
tagsStringBuilder.Append(item.Tags);
tagsStringBuilder.Append(", ");
tagsStringBuilder.Append(property.Value);
Expand Down
4 changes: 2 additions & 2 deletions starsky/starsky/clientapp/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
"start": "vite --port 3000",
"build": "tsc -p tsconfig.prod.json && vite build",
"spell": "cspell --config cspell.json \"src/**/*.{ts,tsx,js,md}\" --exclude build",
"lint": "eslint . --ext ts,tsx --report-unused-disable-directives --max-warnings 800",
"lint:fix": "eslint --fix . --ext ts,tsx --report-unused-disable-directives --max-warnings 800",
"lint": "eslint . --ext ts,tsx --report-unused-disable-directives --max-warnings 810",
"lint:fix": "eslint --fix . --ext ts,tsx --report-unused-disable-directives --max-warnings 810",
"format": "prettier --write './**/*.{js,jsx,ts,tsx,css,md,json}'",
"test": "jest --watch",
"test:ci": "jest --ci --coverage --silent",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@ import { memo } from "react";
import { IFileIndexItem } from "../../../interfaces/IFileIndexItem";

interface IDetailViewInfoMakeModelApertureProps {
fileIndexItem: IFileIndexItem;
fileIndexItem: Readonly<IFileIndexItem>;
}

function ShowISOIfExistComponent(fileIndexItemInside: IFileIndexItem) {
function ShowISOIfExistComponent(
fileIndexItemInside: Readonly<IFileIndexItem>
) {
return (
<>
{fileIndexItemInside.isoSpeed !== 0 ? (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,9 @@ import PanAndZoomImage from "./pan-and-zoom-image";

export interface IFileHashImageProps {
setError?: React.Dispatch<React.SetStateAction<boolean>>;
isError: boolean;
setIsLoading?: React.Dispatch<React.SetStateAction<boolean>>;
fileHash: string;
orientation?: Orientation;
tags?: string;
id?: string; // filepath to know when image is changed
onWheelCallback?(z: number): void;
onResetCallback?(): void;
Expand Down
44 changes: 21 additions & 23 deletions starsky/starsky/clientapp/src/components/atoms/modal/modal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -66,33 +66,31 @@ export default function Modal({

if (modal.current) {
return ReactDOM.createPortal(
<>
<div
onClick={(event) => ifModalOpenHandleExit(event, handleExit)}
data-test={dataTest}
className={`modal-bg ${
isOpen ? ` ${ModalOpenClassName} ` + className : ""
}`}
>
<div
onClick={(event) => ifModalOpenHandleExit(event, handleExit)}
data-test={dataTest}
className={`modal-bg ${
isOpen ? ` ${ModalOpenClassName} ` + className : ""
}`}
className={`modal-content ${isOpen ? " modal-content--show" : ""}`}
>
<div
className={`modal-content ${isOpen ? " modal-content--show" : ""}`}
>
<div className="modal-close-bar">
<button
className={`modal-exit-button ${
isOpen ? " modal-exit-button--showing" : ""
}`}
ref={exitButton}
data-test="modal-exit-button"
onClick={handleExit}
>
{MessageCloseDialog}
</button>
</div>
{children}
<div className="modal-close-bar">
<button
className={`modal-exit-button ${
isOpen ? " modal-exit-button--showing" : ""
}`}
ref={exitButton}
data-test="modal-exit-button"
onClick={handleExit}
>
{MessageCloseDialog}
</button>
</div>
{children}
</div>
</>,
</div>,
modal.current
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export interface ISwitchButtonProps {
"data-test"?: string;
}

function SwitchButton(props: ISwitchButtonProps) {
function SwitchButton(props: Readonly<ISwitchButtonProps>) {
const [random, setRandom] = useState(0);

useEffect(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,14 +93,12 @@ const SearchPagination: React.FunctionComponent<IRelativeLink> = memo(
}

return (
<>
<div className="relativelink" data-test="search-pagination">
<h4 className="nextprev">
{prev()}
{next()}
</h4>
</div>
</>
<div className="relativelink" data-test="search-pagination">
<h4 className="nextprev">
{prev()}
{next()}
</h4>
</div>
);
}
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ const DetailViewInfoDateTime: React.FunctionComponent<IDetailViewInfoDateTimePro
"is at an unknown time"
);

const [isModalDatetimeOpen, setModalDatetimeOpen] = React.useState(false);
const [modalDatetimeOpen, setModalDatetimeOpen] = React.useState(false);

function handleExit(result: IFileIndexItem[] | null) {
setModalDatetimeOpen(false);
Expand All @@ -44,7 +44,7 @@ const DetailViewInfoDateTime: React.FunctionComponent<IDetailViewInfoDateTimePro
return (
<>
{/* dateTime when the image is created */}
{isModalDatetimeOpen ? (
{modalDatetimeOpen ? (
<ModalDatetime
subPath={fileIndexItem.filePath}
dateTime={fileIndexItem.dateTime}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ const DetailViewInfoLocation: React.FunctionComponent<IDetailViewInfoLocationPro

const MessageLocation = language.text("locatie", "location");

const [isLocationOpen, setLocationOpen] = React.useState(
const [locationOpen, setLocationOpen] = React.useState(
history.location.search?.includes("&modal=geo")
);

Expand Down Expand Up @@ -80,7 +80,7 @@ const DetailViewInfoLocation: React.FunctionComponent<IDetailViewInfoLocationPro
return (
<>
{/* loation when the image is created */}
{isLocationOpen ? (
{locationOpen ? (
<ModalGeo
latitude={latitude}
longitude={longitude}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,19 @@ const MenuDefault: React.FunctionComponent<IMenuDefaultProps> = () => {
const [hamburgerMenu, setHamburgerMenu] = useState(false);

return (
<>
<header className={"header header--main"}>
<div className="wrapper">
<HamburgerMenuToggle
select={false}
hamburgerMenu={hamburgerMenu}
setHamburgerMenu={setHamburgerMenu}
/>
<header className={"header header--main"}>
<div className="wrapper">
<HamburgerMenuToggle
select={false}
hamburgerMenu={hamburgerMenu}
setHamburgerMenu={setHamburgerMenu}
/>

<NavContainer hamburgerMenu={hamburgerMenu}>
<MenuSearchBar callback={() => setHamburgerMenu(!hamburgerMenu)} />
</NavContainer>
</div>
</header>
</>
<NavContainer hamburgerMenu={hamburgerMenu}>
<MenuSearchBar callback={() => setHamburgerMenu(!hamburgerMenu)} />
</NavContainer>
</div>
</header>
);
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -199,9 +199,7 @@ const ModalDownload: React.FunctionComponent<IModalExportProps> = (props) => {
) : null}

{isProcessing === ProcessingState.server ? (
<>
<div className="preloader preloader--inside"></div>
</>
<div className="preloader preloader--inside"></div>
) : null}

{isProcessing === ProcessingState.fail
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -218,9 +218,7 @@ const ModalPublish: React.FunctionComponent<IModalPublishProps> = (props) => {
) : null}

{isProcessing === ProcessingState.server ? (
<>
<div className="preloader preloader--inside"></div>
</>
<div className="preloader preloader--inside"></div>
) : null}

{isProcessing === ProcessingState.fail ? (
Expand Down
Loading

0 comments on commit 1434516

Please sign in to comment.