Skip to content

Commit

Permalink
updates
Browse files Browse the repository at this point in the history
  • Loading branch information
qdraw committed Feb 25, 2024
1 parent 3f49be5 commit 48b8e18
Show file tree
Hide file tree
Showing 3 changed files with 98 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,50 @@ import React, { ChangeEvent, useState } from "react";
import useFetch from "../../../hooks/use-fetch";
import useGlobalSettings from "../../../hooks/use-global-settings";
import { IAppSettings } from "../../../interfaces/IAppSettings";
import { IAppSettingsDefaultEditorApplication } from "../../../interfaces/IAppSettingsDefaultEditorApplication";
import { RawJpegMode } from "../../../interfaces/ICollectionsOpenType";
import { ImageFormat } from "../../../interfaces/IFileIndexItem";
import localization from "../../../localization/localization.json";
import FetchPost from "../../../shared/fetch/fetch-post";
import { Language } from "../../../shared/language";
import { UrlQuery } from "../../../shared/url-query";
import FormControl from "../../atoms/form-control/form-control";
import SwitchButton from "../../atoms/switch-button/switch-button";

const defaultEditorApplication = {
imageFormats: [ImageFormat.jpg, ImageFormat.png, ImageFormat.bmp, ImageFormat.tiff]
} as IAppSettingsDefaultEditorApplication;

async function updateDefaultEditorPhotos(

Check warning on line 19 in starsky/starsky/clientapp/src/components/organisms/preference-app-settings-desktop/preference-app-settings-desktop.tsx

View check run for this annotation

Codecov / codecov/patch

starsky/starsky/clientapp/src/components/organisms/preference-app-settings-desktop/preference-app-settings-desktop.tsx#L19

Added line #L19 was not covered by tests
event: ChangeEvent<HTMLDivElement>,
setIsMessage: React.Dispatch<React.SetStateAction<string>>
setIsMessage: React.Dispatch<React.SetStateAction<string>>,
defaultDesktopEditor?: IAppSettingsDefaultEditorApplication[]
) {
if (!defaultDesktopEditor) {
setIsMessage("FAIL");
return;

Check warning on line 26 in starsky/starsky/clientapp/src/components/organisms/preference-app-settings-desktop/preference-app-settings-desktop.tsx

View check run for this annotation

Codecov / codecov/patch

starsky/starsky/clientapp/src/components/organisms/preference-app-settings-desktop/preference-app-settings-desktop.tsx#L25-L26

Added lines #L25 - L26 were not covered by tests
}
const bodyParams = new URLSearchParams();

Check warning on line 28 in starsky/starsky/clientapp/src/components/organisms/preference-app-settings-desktop/preference-app-settings-desktop.tsx

View check run for this annotation

Codecov / codecov/patch

starsky/starsky/clientapp/src/components/organisms/preference-app-settings-desktop/preference-app-settings-desktop.tsx#L28

Added line #L28 was not covered by tests
bodyParams.set("desktopC1111ollectionsOpen", event.target.innerText);

defaultEditorApplication.applicationPath = event.target.innerText;
const index = defaultDesktopEditor.findIndex(

Check warning on line 31 in starsky/starsky/clientapp/src/components/organisms/preference-app-settings-desktop/preference-app-settings-desktop.tsx

View check run for this annotation

Codecov / codecov/patch

starsky/starsky/clientapp/src/components/organisms/preference-app-settings-desktop/preference-app-settings-desktop.tsx#L30-L31

Added lines #L30 - L31 were not covered by tests
(p) => p.imageFormats.includes(ImageFormat.jpg) || p.imageFormats.includes(ImageFormat.tiff)
);
if (index === -1) {
defaultDesktopEditor.push(defaultEditorApplication);

Check warning on line 35 in starsky/starsky/clientapp/src/components/organisms/preference-app-settings-desktop/preference-app-settings-desktop.tsx

View check run for this annotation

Codecov / codecov/patch

starsky/starsky/clientapp/src/components/organisms/preference-app-settings-desktop/preference-app-settings-desktop.tsx#L35

Added line #L35 was not covered by tests
} else {
defaultDesktopEditor[index] = defaultEditorApplication;

Check warning on line 37 in starsky/starsky/clientapp/src/components/organisms/preference-app-settings-desktop/preference-app-settings-desktop.tsx

View check run for this annotation

Codecov / codecov/patch

starsky/starsky/clientapp/src/components/organisms/preference-app-settings-desktop/preference-app-settings-desktop.tsx#L37

Added line #L37 was not covered by tests
}

defaultDesktopEditor.forEach((editorApp, index) => {
defaultEditorApplication.imageFormats.forEach((imageFormat, idx) => {
bodyParams.append(

Check warning on line 42 in starsky/starsky/clientapp/src/components/organisms/preference-app-settings-desktop/preference-app-settings-desktop.tsx

View check run for this annotation

Codecov / codecov/patch

starsky/starsky/clientapp/src/components/organisms/preference-app-settings-desktop/preference-app-settings-desktop.tsx#L40-L42

Added lines #L40 - L42 were not covered by tests
`DefaultDesktopEditor[${index}].ImageFormats[${idx}]`,
imageFormat.toString()
);
});
bodyParams.append(`DefaultDesktopEditor[${index}].ApplicationPath`, editorApp.applicationPath);

Check warning on line 47 in starsky/starsky/clientapp/src/components/organisms/preference-app-settings-desktop/preference-app-settings-desktop.tsx

View check run for this annotation

Codecov / codecov/patch

starsky/starsky/clientapp/src/components/organisms/preference-app-settings-desktop/preference-app-settings-desktop.tsx#L47

Added line #L47 was not covered by tests
});

const result = await FetchPost(new UrlQuery().UrlApiAppSettings(), bodyParams.toString());

Check warning on line 50 in starsky/starsky/clientapp/src/components/organisms/preference-app-settings-desktop/preference-app-settings-desktop.tsx

View check run for this annotation

Codecov / codecov/patch

starsky/starsky/clientapp/src/components/organisms/preference-app-settings-desktop/preference-app-settings-desktop.tsx#L50

Added line #L50 was not covered by tests
if (result.statusCode != 200) {
Expand Down Expand Up @@ -48,43 +78,64 @@ const PreferencesAppSettingsDesktop: React.FunctionComponent = () => {

const settings = useGlobalSettings();

const imageDefaultEditor = appSettings?.defaultDesktopEditor.find(
(p) => p.imageFormats.includes(ImageFormat.jpg) || p.imageFormats.includes(ImageFormat.tiff)
);

const language = new Language(settings.language);
const MessageSwitchButtonDesktopCollectionsRawOn = language.key(
localization.MessageSwitchButtonDesktopCollectionsRawOn
);
const MessageSwitchButtonDesktopCollectionsJpegDefaultOff = language.key(
localization.MessageSwitchButtonDesktopCollectionsJpegDefaultOff
);

// appSettings?.desktopCollectionsOpen
// List<AppSettingsDefaultEditorApplication> DefaultDesktopEditor
// CollectionsOpenType.RawJpegMode DesktopCollectionsOpen
const MessageSwitchButtonDesktopApplication = language.key(
localization.MessageSwitchButtonDesktopApplication
);
const MessageSwitchButtonDesktopApplicationDescription = language.key(
localization.MessageSwitchButtonDesktopApplicationDescription
);
const MessageAppSettingDefaultEditorPhotos = language.key(
localization.MessageAppSettingDefaultEditorPhotos
);
const MessageAppSettingDefaultEditorPhotosDescription = language.key(
localization.MessageAppSettingDefaultEditorPhotosDescription
);

// for showing a notification
const [isMessage, setIsMessage] = useState("");

return (
<>
<p>Desktop</p>
Only used when using Starsky as desktop
{isMessage !== "" ? (
<div className="warning-box warning-box--optional">{isMessage}</div>
) : null}
<SwitchButton
isOn={appSettings?.desktopCollectionsOpen === RawJpegMode.Raw}
data-test="desktop-collections-open-toggle"
isEnabled={true}
leftLabel={MessageSwitchButtonDesktopCollectionsJpegDefaultOff}
onToggle={(value) => toggleCollections(value, setIsMessage)}
rightLabel={MessageSwitchButtonDesktopCollectionsRawOn}
/>
<h4>Default application to edit photos:</h4>
<FormControl
spellcheck={true}
onInput={(value) => updateDefaultEditorPhotos(value, setIsMessage)}
name="tags"
contentEditable={true}
></FormControl>
<div className="content--subheader">{MessageSwitchButtonDesktopApplication}</div>
<div className="content--text no-left-padding">
<p>{MessageSwitchButtonDesktopApplicationDescription}</p>

{isMessage !== "" ? (
<div className="warning-box warning-box--optional">{isMessage}</div>
) : null}
<SwitchButton
isOn={appSettings?.desktopCollectionsOpen === RawJpegMode.Raw}
data-test="desktop-collections-open-toggle"
isEnabled={true}
leftLabel={MessageSwitchButtonDesktopCollectionsJpegDefaultOff}
onToggle={(value) => toggleCollections(value, setIsMessage)}

Check warning on line 122 in starsky/starsky/clientapp/src/components/organisms/preference-app-settings-desktop/preference-app-settings-desktop.tsx

View check run for this annotation

Codecov / codecov/patch

starsky/starsky/clientapp/src/components/organisms/preference-app-settings-desktop/preference-app-settings-desktop.tsx#L122

Added line #L122 was not covered by tests
rightLabel={MessageSwitchButtonDesktopCollectionsRawOn}
/>

<h3>{MessageAppSettingDefaultEditorPhotos}</h3>
<p>{MessageAppSettingDefaultEditorPhotosDescription} </p>
<FormControl
spellcheck={true}
onBlur={(value) =>
updateDefaultEditorPhotos(value, setIsMessage, appSettings?.defaultDesktopEditor)

Check warning on line 131 in starsky/starsky/clientapp/src/components/organisms/preference-app-settings-desktop/preference-app-settings-desktop.tsx

View check run for this annotation

Codecov / codecov/patch

starsky/starsky/clientapp/src/components/organisms/preference-app-settings-desktop/preference-app-settings-desktop.tsx#L130-L131

Added lines #L130 - L131 were not covered by tests
}
name="tags"
contentEditable={true}
>
{imageDefaultEditor?.applicationPath}
</FormControl>
</div>
</>
);
};
Expand Down
17 changes: 16 additions & 1 deletion starsky/starsky/clientapp/src/localization/localization.json
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,22 @@
"en": "Jpeg first",
"nl": "Jpeg eerst"
},

"MessageSwitchButtonDesktopApplication": {
"en": "AppSettings: Desktop application",
"nl": "AppSettings: Desktop applicatie"
},
"MessageSwitchButtonDesktopApplicationDescription": {
"en": "These settings are only available when using as Desktop application",
"nl": "Deze instellingen zijn alleen beschikbaar als desktop applicatie"
},
"MessageAppSettingDefaultEditorPhotos": {
"en": "Default application to edit photos:",
"nl": "Standaardtoepassing om foto's te bewerken:"
},
"MessageAppSettingDefaultEditorPhotosDescription": {
"en": "Keep emthy to use the default system application ",
"nl": "Hou leeg om de standaardtoepassing van het systeem te gebruiken"
},
"temp1": {
"en": "",
"nl": ""
Expand Down
5 changes: 5 additions & 0 deletions starsky/starsky/clientapp/src/style/css/20-content.css
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,11 @@
.content--text {
padding: 10px;
}

.content--text.no-left-padding {
padding-left: 0px;
}

.content--text .date {
display: inline-block;
margin-right: 10px;
Expand Down

0 comments on commit 48b8e18

Please sign in to comment.