Skip to content
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

Allow updating custom metadata #1149

Merged
merged 53 commits into from
Dec 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
53 commits
Select commit Hold shift + click to select a range
476c5fb
feat(backend): add mutation to update a custom metadata
IgnisDa Dec 24, 2024
7a7c7ee
feat(migrations): add column to metadata for created by user id
IgnisDa Dec 24, 2024
79bbe7f
feat(migrations): update new column for existing metadata items
IgnisDa Dec 24, 2024
fc4fbf7
feat(models/database): add new column to tables
IgnisDa Dec 24, 2024
5ccde06
feat(backend): respect new column
IgnisDa Dec 24, 2024
4e26578
feat(services/miscellaneous): add validation before allowing to updat…
IgnisDa Dec 24, 2024
11cc609
feat(services/miscellaneous): add validation before updating custom m…
IgnisDa Dec 24, 2024
23a6f95
feat(backend): send details about created by user id for metadata det…
IgnisDa Dec 24, 2024
2f9ee1d
feat(frontend): add button to edit metadata
IgnisDa Dec 24, 2024
b47a45c
feat(frontend): change name of page
IgnisDa Dec 24, 2024
84db86d
chore(frontend): add action to schema
IgnisDa Dec 24, 2024
95e8097
chore(frontend): change name of page
IgnisDa Dec 24, 2024
672066e
fix(services/miscellaneous): delete old images
IgnisDa Dec 24, 2024
11b0de4
fix(services/miscellaneous): delete old videos
IgnisDa Dec 24, 2024
e78bc59
fix(services/miscellaneous): set correct id for updating custom metadata
IgnisDa Dec 24, 2024
80963a7
feat(frontend): allow updating metadata
IgnisDa Dec 24, 2024
a795444
ci: Run CI
IgnisDa Dec 24, 2024
ace4d17
feat(frontend): add loading when image is uploading
IgnisDa Dec 25, 2024
a405fe3
fix(services/fitness): do not discard user exercise settings during w…
IgnisDa Dec 25, 2024
e57d220
chore(backend): require entire setting when updating exercise settings
IgnisDa Dec 25, 2024
111a83a
feat(frontend): update exercise settings from the frontend
IgnisDa Dec 25, 2024
9c91cd9
refactor(frontend): change variable names
IgnisDa Dec 25, 2024
f6c75b4
feat(backend): accept entire user preferences when updating it
IgnisDa Dec 25, 2024
528a6a2
feat(frontend): update preferences from the client side
IgnisDa Dec 25, 2024
3f47da0
ci: Run CI
IgnisDa Dec 25, 2024
d2ca9e6
refactor(frontend): change name of action
IgnisDa Dec 25, 2024
73f1186
perf(frontend): display season episodes in separate modal
IgnisDa Dec 25, 2024
692f3d8
perf(frontend): display show seasons using virtualized list
IgnisDa Dec 25, 2024
f9ccfe5
build(frontend): mantine modal deps
IgnisDa Dec 25, 2024
25e0bbc
feat(frontend): add mantine modals provider
IgnisDa Dec 25, 2024
c4ab9d4
refactor(frontend): change name of file
IgnisDa Dec 25, 2024
15cb70e
refactor(frontend): remove nested if
IgnisDa Dec 25, 2024
152e9f4
fix(frontend): do not hard reload when navigating to log workout
IgnisDa Dec 25, 2024
a3735e8
feat(frontend): open confirmation modal using mantine
IgnisDa Dec 25, 2024
7f86536
chore(frontend): remove react confirm code
IgnisDa Dec 25, 2024
26a3deb
ci: Run CI
IgnisDa Dec 25, 2024
6423142
refactor(frontend): move form inside component
IgnisDa Dec 25, 2024
9820681
feat(frontend): ask for confirmation before deploying job
IgnisDa Dec 25, 2024
9af5fe8
refactor(frontend): remove useless if checks for confirmations
IgnisDa Dec 25, 2024
e3704ab
feat(backend): add mutation to refresh user recommendation key
IgnisDa Dec 25, 2024
7a3d2a5
feat(services/user): change recommendations if cache key is present
IgnisDa Dec 25, 2024
291eb45
feat(frontend): allow refreshing recommendations
IgnisDa Dec 25, 2024
4ac69eb
ci: Run CI
IgnisDa Dec 25, 2024
3bd1be1
fix(frontend): make all section titles the same size on mobile screens
IgnisDa Dec 25, 2024
a0f96ed
feat(backend): add crate for lock service
IgnisDa Dec 26, 2024
0a9ec67
feat(services/lock): add implementation to lock service
IgnisDa Dec 26, 2024
8cf130b
feat(backend): remove lock service
IgnisDa Dec 26, 2024
7627892
feat(backend): acquire lock correctly
IgnisDa Dec 26, 2024
753a1ab
chore(utils/common): remove useless imports
IgnisDa Dec 26, 2024
36335d1
refactor(backend): remove stuff
IgnisDa Dec 26, 2024
57693a0
feat(backend): extract async function to sleep in tokio
IgnisDa Dec 26, 2024
f54919e
fix(utils/dependent): do not sleep while updating
IgnisDa Dec 26, 2024
e548506
refactor(frontend): different modal for season episodes
IgnisDa Dec 26, 2024
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
9 changes: 5 additions & 4 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ serde_with = { version = "=3.11.0", features = ["chrono_0_4"] }
serde-xml-rs = "=0.6.0"
slug = "=0.1.6"
sonarr-api-rs = "=3.0.0"
sqlx = { version = "=0.8.2", default-features = false, features = ["postgres"] }
strum = { version = "=0.26.3", features = ["derive"] }
struson = { version = "=0.6.0", features = ["serde"] }
reqwest = { version = "=0.12.9", features = ["json", "stream"] }
Expand Down
60 changes: 29 additions & 31 deletions apps/frontend/app/components/common.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ import {
convertDecimalToThreePointSmiley,
dayjsLib,
getSurroundingElements,
openConfirmationModal,
reviewYellow,
} from "~/lib/generals";
import {
Expand All @@ -88,7 +89,6 @@ import {
import { useReviewEntity } from "~/lib/state/media";
import type { action } from "~/routes/actions";
import classes from "~/styles/common.module.css";
import { confirmWrapper } from "./confirmation";
import {
ExerciseDisplayItem,
WorkoutDisplayItem,
Expand Down Expand Up @@ -541,24 +541,24 @@ export const ReviewItemDisplay = (props: {
<IconEdit size={16} />
</ActionIcon>
<ActionIcon
onClick={async () => {
const conf = await confirmWrapper({
confirmation:
"Are you sure you want to delete this review? This action cannot be undone.",
});
if (conf)
deleteReviewFetcher.submit(
{
shouldDelete: "true",
reviewId: props.review.id || null,
},
{
method: "post",
action: $path("/actions", {
intent: "performReviewAction",
}),
},
);
onClick={() => {
openConfirmationModal(
"Are you sure you want to delete this review? This action cannot be undone.",
() => {
deleteReviewFetcher.submit(
{
shouldDelete: "true",
reviewId: props.review.id || null,
},
{
method: "post",
action: $path("/actions", {
intent: "performReviewAction",
}),
},
);
},
);
}}
color="red"
>
Expand Down Expand Up @@ -732,14 +732,13 @@ export const ReviewItemDisplay = (props: {
<ActionIcon
color="red"
type="submit"
onClick={async (e) => {
onClick={(e) => {
const form = e.currentTarget.form;
e.preventDefault();
const conf = await confirmWrapper({
confirmation:
"Are you sure you want to delete this comment?",
});
if (conf && form) submit(form);
openConfirmationModal(
"Are you sure you want to delete this comment?",
() => submit(form),
);
}}
>
<IconTrash size={16} />
Expand Down Expand Up @@ -886,14 +885,13 @@ export const DisplayCollection = (props: {
/>
<ActionIcon
size={16}
onClick={async (e) => {
onClick={(e) => {
const form = e.currentTarget.form;
e.preventDefault();
const conf = await confirmWrapper({
confirmation:
"Are you sure you want to remove this media from this collection?",
});
if (conf && form) submit(form);
openConfirmationModal(
"Are you sure you want to remove this media from this collection?",
() => submit(form),
);
}}
>
<IconX />
Expand Down
59 changes: 0 additions & 59 deletions apps/frontend/app/components/confirmation.tsx

This file was deleted.

16 changes: 7 additions & 9 deletions apps/frontend/app/components/media.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,10 @@ import {
DisplayThreePointReview,
MEDIA_DETAILS_HEIGHT,
} from "~/components/common";
import { confirmWrapper } from "~/components/confirmation";
import {
clientGqlService,
getPartialMetadataDetailsQuery,
openConfirmationModal,
queryFactory,
reviewYellow,
} from "~/lib/generals";
Expand Down Expand Up @@ -397,14 +397,12 @@ export const ToggleMediaMonitorMenuItem = (props: {
const form = e.currentTarget.form;
if (form) {
e.preventDefault();
if (isMonitored) {
const conf = await confirmWrapper({
confirmation: "Are you sure you want to stop monitoring?",
});
if (conf) submit(form);
} else {
submit(form);
}
if (isMonitored)
openConfirmationModal(
"Are you sure you want to stop monitoring?",
() => submit(form),
);
else submit(form);
}
}}
>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ import {
createQueryKeys,
mergeQueryKeys,
} from "@lukemorales/query-key-factory";
import type { MantineColor } from "@mantine/core";
import { type MantineColor, Text } from "@mantine/core";
import { modals } from "@mantine/modals";
import {
MediaLot,
MediaSource,
Expand Down Expand Up @@ -306,10 +307,10 @@ export const getStringAsciiValue = (input: string) => {
return total;
};

export const selectRandomElement = <T>(array: T[], input: string): T => {
export function selectRandomElement<T>(array: T[], input: string): T {
// taken from https://stackoverflow.com/questions/44975435/using-mod-operator-in-javascript-to-wrap-around#comment76926119_44975435
return array[(getStringAsciiValue(input) + array.length) % array.length];
};
}

export const getMetadataIcon = (lot: MediaLot) =>
match(lot)
Expand Down Expand Up @@ -338,16 +339,16 @@ export const clientGqlService = new GraphQLClient(
},
);

export const getSurroundingElements = <T>(
export function getSurroundingElements<T>(
array: Array<T>,
elementIndex: number,
): Array<number> => {
): Array<number> {
if (array.length === 1) return [0];
const lastIndex = array.length - 1;
if (elementIndex === 0) return [lastIndex, elementIndex, elementIndex + 1];
if (elementIndex === lastIndex) return [elementIndex - 1, elementIndex, 0];
return [elementIndex - 1, elementIndex, elementIndex + 1];
};
}

const mediaQueryKeys = createQueryKeys("media", {
metadataPartialDetails: (metadataId: string) => ({
Expand Down Expand Up @@ -488,3 +489,11 @@ export const MediaColors: EntityColor = {
REVIEW: "green.5",
USER_MEASUREMENT: "indigo",
};

export const openConfirmationModal = (title: string, onConfirm: () => void) =>
modals.openConfirmModal({
title: "Confirmation",
onConfirm: onConfirm,
children: <Text size="sm">{title}</Text>,
labels: { confirm: "Confirm", cancel: "Cancel" },
});
25 changes: 6 additions & 19 deletions apps/frontend/app/lib/hooks.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { useComputedColorScheme, useMantineTheme } from "@mantine/core";
import { useForceUpdate, useListState } from "@mantine/hooks";
import { useForceUpdate } from "@mantine/hooks";
import {
useNavigate,
useRevalidator,
useRouteLoaderData,
useSearchParams,
Expand Down Expand Up @@ -86,20 +87,22 @@ export const useAppSearchParam = (cookieKey: string) => {

export const useConfirmSubmit = () => {
const submit = useSubmit();
const fn = (e: FormEvent<HTMLFormElement> | HTMLFormElement) => {
const fn = (e: FormEvent<HTMLFormElement> | HTMLFormElement | null) => {
if (!e) return;
if (e.preventDefault) e.preventDefault();
submit(e.currentTarget || e, { navigate: false });
};
return fn;
};

export const useGetWorkoutStarter = () => {
const navigate = useNavigate();
const revalidator = useRevalidator();
const [_, setCurrentWorkout] = useCurrentWorkout();

const fn = (wkt: InProgressWorkout, action: FitnessAction) => {
setCurrentWorkout(wkt);
window.location.href = $path("/fitness/:action", { action });
navigate($path("/fitness/:action", { action }), { flushSync: true });
revalidator.revalidate();
};
return fn;
Expand Down Expand Up @@ -187,22 +190,6 @@ export const useGetWatchProviders = (mediaLot: MediaLot) => {
return watchProviders;
};

export const useComplexJsonUpdate = () => {
const [toUpdatePreferences, updateUserPreferencesHandler] = useListState<
[string, string]
>([]);

const reset = () => updateUserPreferencesHandler.setState([]);

const appendPref = (property: string, value: string) => {
const index = toUpdatePreferences.findIndex((p) => p[0] === property);
if (index !== -1) updateUserPreferencesHandler.remove(index);
updateUserPreferencesHandler.append([property, value]);
};

return { reset, appendPref, toUpdatePreferences };
};

export const useIsFitnessActionActive = () => {
const [currentWorkout] = useCurrentWorkout();
const action = currentWorkout?.currentActionOrCompleted;
Expand Down
2 changes: 1 addition & 1 deletion apps/frontend/app/lib/state/fitness.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ export const useGetSetAtIndex = (exerciseIdx: number, setIdx: number) => {
export const getDefaultWorkout = (
fitnessEntity: FitnessAction,
): InProgressWorkout => {
const date = dayjsLib().add(4, "second");
const date = dayjsLib().add(3, "second");
return {
images: [],
videos: [],
Expand Down
Loading
Loading