Skip to content

Commit 8db9cb9

Browse files
authored
Migrate over remaining attributes (#715)
* fix(migrations): add migration to change attributes i forgot * fix(frontend): do not show section in summary if not enabled * build(backend): bump version * fix(frontend): display correct collection contents on dashboard * fix(frontend): hide stat if not applicable
1 parent 47484c8 commit 8db9cb9

File tree

5 files changed

+99
-63
lines changed

5 files changed

+99
-63
lines changed

Cargo.lock

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

apps/backend/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "ryot"
3-
version = "4.3.5"
3+
version = "4.3.6"
44
edition = "2021"
55
repository = "https://github.com/IgnisDa/ryot"
66
license = "GPL-3.0"

apps/frontend/app/routes/_dashboard._index.tsx

+71-61
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import {
2828
MetadataLot,
2929
type UserMediaFeaturesEnabledPreferences,
3030
UserUpcomingCalendarEventsDocument,
31+
type UserPreferences,
3132
} from "@ryot/generated/graphql/backend/graphql";
3233
import { displayWeightWithUnit, humanizeDuration } from "@ryot/ts-utils";
3334
import {
@@ -61,24 +62,28 @@ import {
6162

6263
const cookieName = ApplicationKey.CurrentWorkout;
6364

65+
const getTake = (prefs: UserPreferences, el: DashboardElementLot) => {
66+
const t = prefs.general.dashboard.find(
67+
(de) => de.section === el,
68+
)?.numElements;
69+
invariant(t, `No take found for ${el}`);
70+
return t;
71+
};
72+
6473
export const loader = async ({ request }: LoaderFunctionArgs) => {
65-
const userPreferences = await getUserPreferences(request);
66-
const getTake = (el: DashboardElementLot) => {
67-
const t = userPreferences.general.dashboard.find(
68-
(de) => de.section === el,
69-
)?.numElements;
70-
invariant(t, `No take found for ${el}`);
71-
return t;
72-
};
73-
const takeUpcoming = getTake(DashboardElementLot.Upcoming);
74-
const takeInProgress = getTake(DashboardElementLot.InProgress);
74+
const prefs = await getUserPreferences(request);
75+
const takeUpcoming = getTake(prefs, DashboardElementLot.Upcoming);
76+
const takeInProgress = getTake(prefs, DashboardElementLot.InProgress);
7577
const userCollectionsList = await getUserCollectionsList(request);
76-
const collectionId = userCollectionsList[0].id;
78+
const foundCollection = userCollectionsList.find(
79+
(c) => c.name === "In Progress",
80+
);
81+
invariant(foundCollection, 'No collection found for "In Progress"');
7782
const { collectionContents } = await gqlClient.request(
7883
CollectionContentsDocument,
7984
{
8085
input: {
81-
collectionId,
86+
collectionId: foundCollection.id,
8287
take: takeInProgress,
8388
sort: { order: GraphqlSortOrder.Desc },
8489
},
@@ -100,11 +105,11 @@ export const loader = async ({ request }: LoaderFunctionArgs) => {
100105
return json({
101106
workoutInProgress,
102107
userPreferences: {
103-
reviewScale: userPreferences.general.reviewScale,
104-
dashboard: userPreferences.general.dashboard,
105-
media: userPreferences.featuresEnabled.media,
106-
fitness: userPreferences.featuresEnabled.fitness,
107-
unitSystem: userPreferences.fitness.exercises.unitSystem,
108+
reviewScale: prefs.general.reviewScale,
109+
dashboard: prefs.general.dashboard,
110+
media: prefs.featuresEnabled.media,
111+
fitness: prefs.featuresEnabled.fitness,
112+
unitSystem: prefs.fitness.exercises.unitSystem,
108113
},
109114
latestUserSummary,
110115
userUpcomingCalendarEvents,
@@ -362,51 +367,55 @@ export default function Page() {
362367
]}
363368
/>
364369
{loaderData.userPreferences.media.enabled ? (
365-
<ActualDisplayStat
366-
icon={<IconServer />}
367-
lot="Metadata stats"
368-
color={theme.colors.grape[8]}
369-
data={[
370-
{
371-
label: "Media",
372-
value:
373-
loaderData.latestUserSummary.media.metadataOverall
374-
.interactedWith,
375-
type: "number",
376-
},
377-
{
378-
label: "Reviews",
379-
value:
380-
loaderData.latestUserSummary.media.metadataOverall
381-
.reviewed,
382-
type: "number",
383-
hideIfZero: true,
384-
},
385-
]}
386-
/>
370+
<>
371+
<ActualDisplayStat
372+
icon={<IconServer />}
373+
lot="Metadata stats"
374+
color={theme.colors.grape[8]}
375+
data={[
376+
{
377+
label: "Media",
378+
value:
379+
loaderData.latestUserSummary.media.metadataOverall
380+
.interactedWith,
381+
type: "number",
382+
},
383+
{
384+
label: "Reviews",
385+
value:
386+
loaderData.latestUserSummary.media.metadataOverall
387+
.reviewed,
388+
type: "number",
389+
hideIfZero: true,
390+
},
391+
]}
392+
/>
393+
{loaderData.userPreferences.media.people ? (
394+
<ActualDisplayStat
395+
icon={<IconFriends />}
396+
lot="People stats"
397+
color={theme.colors.red[9]}
398+
data={[
399+
{
400+
label: "People",
401+
value:
402+
loaderData.latestUserSummary.media.peopleOverall
403+
.interactedWith,
404+
type: "number",
405+
},
406+
{
407+
label: "Reviews",
408+
value:
409+
loaderData.latestUserSummary.media.peopleOverall
410+
.reviewed,
411+
type: "number",
412+
hideIfZero: true,
413+
},
414+
]}
415+
/>
416+
) : null}
417+
</>
387418
) : null}
388-
<ActualDisplayStat
389-
icon={<IconFriends />}
390-
lot="People stats"
391-
color={theme.colors.red[9]}
392-
data={[
393-
{
394-
label: "People",
395-
value:
396-
loaderData.latestUserSummary.media.peopleOverall
397-
.interactedWith,
398-
type: "number",
399-
},
400-
{
401-
label: "Reviews",
402-
value:
403-
loaderData.latestUserSummary.media.peopleOverall
404-
.reviewed,
405-
type: "number",
406-
hideIfZero: true,
407-
},
408-
]}
409-
/>
410419
{loaderData.userPreferences.fitness.enabled &&
411420
loaderData.latestUserSummary.fitness.workouts.duration +
412421
loaderData.latestUserSummary.fitness.workouts.recorded >
@@ -461,6 +470,7 @@ export default function Page() {
461470
loaderData.latestUserSummary.fitness
462471
.measurementsRecorded,
463472
type: "number",
473+
hideIfZero: true,
464474
},
465475
{
466476
label: "Exercises",
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
use sea_orm_migration::prelude::*;
2+
3+
#[derive(DeriveMigrationName)]
4+
pub struct Migration;
5+
6+
#[async_trait::async_trait]
7+
impl MigrationTrait for Migration {
8+
async fn up(&self, manager: &SchemaManager) -> Result<(), DbErr> {
9+
let db = manager.get_connection();
10+
// for user preferences
11+
db.execute_unprepared(
12+
r#"
13+
UPDATE "user"
14+
SET preferences = jsonb_set(preferences, '{general, disable_navigation_animation}', 'false', true);
15+
"#,
16+
)
17+
.await?;
18+
Ok(())
19+
}
20+
21+
async fn down(&self, _manager: &SchemaManager) -> Result<(), DbErr> {
22+
Ok(())
23+
}
24+
}

libs/database/src/migrations/mod.rs

+2
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ mod m20240307_add_column_to_metadata_for_watch_providers;
6262
mod m20240309_change_generic_to_media_json;
6363
mod m20240310_add_source_specifics_field_to_person;
6464
mod m20240324_perform_v4_migration;
65+
mod m20240325_add_correct_attribute_to_user_preferences;
6566

6667
pub use m20230410_create_metadata::Metadata as AliasedMetadata;
6768
pub use m20230413_create_person::Person as AliasedPerson;
@@ -141,6 +142,7 @@ impl MigratorTrait for Migrator {
141142
Box::new(m20240309_change_generic_to_media_json::Migration),
142143
Box::new(m20240310_add_source_specifics_field_to_person::Migration),
143144
Box::new(m20240324_perform_v4_migration::Migration),
145+
Box::new(m20240325_add_correct_attribute_to_user_preferences::Migration),
144146
]
145147
}
146148
}

0 commit comments

Comments
 (0)