Skip to content

Commit ba13ecb

Browse files
authored
Showcase new features (#946)
* feat(database): add new section * chore(backend): add section to prefs for new users * feat(frontend): add pro required label * chore(frontend): order of props * feat(frontend): choose a default provider for new progress updates
1 parent 9d09100 commit ba13ecb

File tree

6 files changed

+70
-5
lines changed

6 files changed

+70
-5
lines changed

apps/backend/src/users.rs

+6
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,7 @@ pub enum DashboardElementLot {
266266
Upcoming,
267267
InProgress,
268268
Summary,
269+
Recommendations,
269270
}
270271

271272
#[skip_serializing_none]
@@ -316,6 +317,11 @@ impl Default for UserGeneralPreferences {
316317
hidden: false,
317318
num_elements: None,
318319
},
320+
UserGeneralDashboardElement {
321+
section: DashboardElementLot::Recommendations,
322+
hidden: false,
323+
num_elements: Some(8),
324+
},
319325
],
320326
persist_queries: true,
321327
disable_integrations: false,

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

+10-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ import { Fragment, type ReactNode } from "react";
3636
import { $path } from "remix-routes";
3737
import invariant from "tiny-invariant";
3838
import { match } from "ts-pattern";
39-
import { ApplicationGrid } from "~/components/common";
39+
import { ApplicationGrid, ProRequiredAlert } from "~/components/common";
4040
import { displayWeightWithUnit } from "~/components/fitness";
4141
import {
4242
DisplayCollectionEntity,
@@ -161,6 +161,15 @@ export default function Page() {
161161
</Section>
162162
) : null,
163163
)
164+
.with([DashboardElementLot.Recommendations, false], () => (
165+
<Section
166+
key={DashboardElementLot.Recommendations}
167+
lot={DashboardElementLot.Recommendations}
168+
>
169+
<Title>Recommendations</Title>
170+
<ProRequiredAlert tooltipLabel="Get new recommendations every hour" />
171+
</Section>
172+
))
164173
.with([DashboardElementLot.Summary, false], () => (
165174
<Section
166175
key={DashboardElementLot.Summary}

apps/frontend/app/routes/_dashboard.tsx

+10-4
Original file line numberDiff line numberDiff line change
@@ -799,11 +799,13 @@ const MetadataProgressUpdateForm = ({
799799
onSubmit={onSubmit}
800800
metadataDetails={metadataDetails}
801801
metadataToUpdate={metadataToUpdate}
802+
history={userMetadataDetails.history}
802803
/>
803804
);
804805
};
805806

806807
type InProgress = UserMetadataDetailsQuery["userMetadataDetails"]["inProgress"];
808+
type History = UserMetadataDetailsQuery["userMetadataDetails"]["history"];
807809

808810
const MetadataInProgressUpdateForm = ({
809811
onSubmit,
@@ -910,10 +912,10 @@ const MetadataInProgressUpdateForm = ({
910912
</>
911913
) : null}
912914
<Select
913-
data={userPreferences.general.watchProviders}
914-
label={`Where did you ${getVerb(Verb.Read, metadataDetails.lot)} it?`}
915915
name="providerWatchedOn"
916916
defaultValue={inProgress.providerWatchedOn}
917+
data={userPreferences.general.watchProviders}
918+
label={`Where did you ${getVerb(Verb.Read, metadataDetails.lot)} it?`}
917919
/>
918920
<Button variant="outline" type="submit">
919921
Update
@@ -927,10 +929,12 @@ const NewProgressUpdateForm = ({
927929
onSubmit,
928930
metadataDetails,
929931
metadataToUpdate,
932+
history,
930933
}: {
931934
onSubmit: (e: FormEvent<HTMLFormElement>) => void;
932935
metadataToUpdate: UpdateProgressData;
933936
metadataDetails: MetadataDetailsQuery["metadataDetails"];
937+
history: History;
934938
}) => {
935939
const userPreferences = useUserPreferences();
936940
const [_, setMetadataToUpdate] = useMetadataProgressUpdate();
@@ -940,6 +944,7 @@ const NewProgressUpdateForm = ({
940944
);
941945
const [watchTime, setWatchTime] =
942946
useState<(typeof WATCH_TIMES)[number]>("Just Right Now");
947+
const lastProviderWatchedOn = history[0]?.providerWatchedOn;
943948

944949
return (
945950
<Form
@@ -1128,9 +1133,10 @@ const NewProgressUpdateForm = ({
11281133
/>
11291134
) : null}
11301135
<Select
1131-
label={`Where did you ${getVerb(Verb.Read, metadataDetails.lot)} it?`}
1132-
data={userPreferences.general.watchProviders}
11331136
name="providerWatchedOn"
1137+
defaultValue={lastProviderWatchedOn}
1138+
data={userPreferences.general.watchProviders}
1139+
label={`Where did you ${getVerb(Verb.Read, metadataDetails.lot)} it?`}
11341140
/>
11351141
{selectedDate ? (
11361142
<input
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
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+
db.execute_unprepared(
11+
r#"
12+
UPDATE "user"
13+
SET preferences = jsonb_set(
14+
preferences,
15+
'{general, dashboard}',
16+
(
17+
CASE
18+
WHEN NOT EXISTS (
19+
SELECT 1
20+
FROM jsonb_array_elements(COALESCE(preferences->'general'->'dashboard', '[]'::jsonb)) AS elem
21+
WHERE elem->>'section' = 'RECOMMENDATIONS'
22+
)
23+
THEN COALESCE(preferences->'general'->'dashboard', '[]'::jsonb) ||
24+
jsonb_build_array(jsonb_build_object('hidden', false, 'section', 'RECOMMENDATIONS', 'numElements', 8))
25+
ELSE COALESCE(preferences->'general'->'dashboard', '[]'::jsonb)
26+
END
27+
)::jsonb,
28+
true
29+
)
30+
WHERE preferences->'general'->'dashboard' IS NOT NULL;
31+
"#,
32+
)
33+
.await?;
34+
35+
Ok(())
36+
}
37+
38+
async fn down(&self, _manager: &SchemaManager) -> Result<(), DbErr> {
39+
Ok(())
40+
}
41+
}

libs/database/src/migrations/mod.rs

+2
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ mod m20240723_remove_integration_columns_from_user_table;
4343
mod m20240724_add_new_columns_to_collection_to_entity;
4444
mod m20240724_zzz_new_generated_collection_to_entity_columns;
4545
mod m20240730_changes_for_push_integrations;
46+
mod m20240805_add_new_section_to_dashboard;
4647

4748
pub use m20230410_create_metadata::Metadata as AliasedMetadata;
4849
pub use m20230413_create_person::Person as AliasedPerson;
@@ -107,6 +108,7 @@ impl MigratorTrait for Migrator {
107108
Box::new(m20240724_add_new_columns_to_collection_to_entity::Migration),
108109
Box::new(m20240724_zzz_new_generated_collection_to_entity_columns::Migration),
109110
Box::new(m20240730_changes_for_push_integrations::Migration),
111+
Box::new(m20240805_add_new_section_to_dashboard::Migration),
110112
]
111113
}
112114
}

libs/generated/src/graphql/backend/graphql.ts

+1
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,7 @@ export type CreateUserNotificationPlatformInput = {
263263

264264
export enum DashboardElementLot {
265265
InProgress = 'IN_PROGRESS',
266+
Recommendations = 'RECOMMENDATIONS',
266267
Summary = 'SUMMARY',
267268
Upcoming = 'UPCOMING'
268269
}

0 commit comments

Comments
 (0)