Skip to content

Commit

Permalink
Showcase new features (#946)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
IgnisDa authored Aug 6, 2024
1 parent 9d09100 commit ba13ecb
Show file tree
Hide file tree
Showing 6 changed files with 70 additions and 5 deletions.
6 changes: 6 additions & 0 deletions apps/backend/src/users.rs
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,7 @@ pub enum DashboardElementLot {
Upcoming,
InProgress,
Summary,
Recommendations,
}

#[skip_serializing_none]
Expand Down Expand Up @@ -316,6 +317,11 @@ impl Default for UserGeneralPreferences {
hidden: false,
num_elements: None,
},
UserGeneralDashboardElement {
section: DashboardElementLot::Recommendations,
hidden: false,
num_elements: Some(8),
},
],
persist_queries: true,
disable_integrations: false,
Expand Down
11 changes: 10 additions & 1 deletion apps/frontend/app/routes/_dashboard._index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ import { Fragment, type ReactNode } from "react";
import { $path } from "remix-routes";
import invariant from "tiny-invariant";
import { match } from "ts-pattern";
import { ApplicationGrid } from "~/components/common";
import { ApplicationGrid, ProRequiredAlert } from "~/components/common";
import { displayWeightWithUnit } from "~/components/fitness";
import {
DisplayCollectionEntity,
Expand Down Expand Up @@ -161,6 +161,15 @@ export default function Page() {
</Section>
) : null,
)
.with([DashboardElementLot.Recommendations, false], () => (
<Section
key={DashboardElementLot.Recommendations}
lot={DashboardElementLot.Recommendations}
>
<Title>Recommendations</Title>
<ProRequiredAlert tooltipLabel="Get new recommendations every hour" />
</Section>
))
.with([DashboardElementLot.Summary, false], () => (
<Section
key={DashboardElementLot.Summary}
Expand Down
14 changes: 10 additions & 4 deletions apps/frontend/app/routes/_dashboard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -799,11 +799,13 @@ const MetadataProgressUpdateForm = ({
onSubmit={onSubmit}
metadataDetails={metadataDetails}
metadataToUpdate={metadataToUpdate}
history={userMetadataDetails.history}
/>
);
};

type InProgress = UserMetadataDetailsQuery["userMetadataDetails"]["inProgress"];
type History = UserMetadataDetailsQuery["userMetadataDetails"]["history"];

const MetadataInProgressUpdateForm = ({
onSubmit,
Expand Down Expand Up @@ -910,10 +912,10 @@ const MetadataInProgressUpdateForm = ({
</>
) : null}
<Select
data={userPreferences.general.watchProviders}
label={`Where did you ${getVerb(Verb.Read, metadataDetails.lot)} it?`}
name="providerWatchedOn"
defaultValue={inProgress.providerWatchedOn}
data={userPreferences.general.watchProviders}
label={`Where did you ${getVerb(Verb.Read, metadataDetails.lot)} it?`}
/>
<Button variant="outline" type="submit">
Update
Expand All @@ -927,10 +929,12 @@ const NewProgressUpdateForm = ({
onSubmit,
metadataDetails,
metadataToUpdate,
history,
}: {
onSubmit: (e: FormEvent<HTMLFormElement>) => void;
metadataToUpdate: UpdateProgressData;
metadataDetails: MetadataDetailsQuery["metadataDetails"];
history: History;
}) => {
const userPreferences = useUserPreferences();
const [_, setMetadataToUpdate] = useMetadataProgressUpdate();
Expand All @@ -940,6 +944,7 @@ const NewProgressUpdateForm = ({
);
const [watchTime, setWatchTime] =
useState<(typeof WATCH_TIMES)[number]>("Just Right Now");
const lastProviderWatchedOn = history[0]?.providerWatchedOn;

return (
<Form
Expand Down Expand Up @@ -1128,9 +1133,10 @@ const NewProgressUpdateForm = ({
/>
) : null}
<Select
label={`Where did you ${getVerb(Verb.Read, metadataDetails.lot)} it?`}
data={userPreferences.general.watchProviders}
name="providerWatchedOn"
defaultValue={lastProviderWatchedOn}
data={userPreferences.general.watchProviders}
label={`Where did you ${getVerb(Verb.Read, metadataDetails.lot)} it?`}
/>
{selectedDate ? (
<input
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
use sea_orm_migration::prelude::*;

#[derive(DeriveMigrationName)]
pub struct Migration;

#[async_trait::async_trait]
impl MigrationTrait for Migration {
async fn up(&self, manager: &SchemaManager) -> Result<(), DbErr> {
let db = manager.get_connection();
db.execute_unprepared(
r#"
UPDATE "user"
SET preferences = jsonb_set(
preferences,
'{general, dashboard}',
(
CASE
WHEN NOT EXISTS (
SELECT 1
FROM jsonb_array_elements(COALESCE(preferences->'general'->'dashboard', '[]'::jsonb)) AS elem
WHERE elem->>'section' = 'RECOMMENDATIONS'
)
THEN COALESCE(preferences->'general'->'dashboard', '[]'::jsonb) ||
jsonb_build_array(jsonb_build_object('hidden', false, 'section', 'RECOMMENDATIONS', 'numElements', 8))
ELSE COALESCE(preferences->'general'->'dashboard', '[]'::jsonb)
END
)::jsonb,
true
)
WHERE preferences->'general'->'dashboard' IS NOT NULL;
"#,
)
.await?;

Ok(())
}

async fn down(&self, _manager: &SchemaManager) -> Result<(), DbErr> {
Ok(())
}
}
2 changes: 2 additions & 0 deletions libs/database/src/migrations/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ mod m20240723_remove_integration_columns_from_user_table;
mod m20240724_add_new_columns_to_collection_to_entity;
mod m20240724_zzz_new_generated_collection_to_entity_columns;
mod m20240730_changes_for_push_integrations;
mod m20240805_add_new_section_to_dashboard;

pub use m20230410_create_metadata::Metadata as AliasedMetadata;
pub use m20230413_create_person::Person as AliasedPerson;
Expand Down Expand Up @@ -107,6 +108,7 @@ impl MigratorTrait for Migrator {
Box::new(m20240724_add_new_columns_to_collection_to_entity::Migration),
Box::new(m20240724_zzz_new_generated_collection_to_entity_columns::Migration),
Box::new(m20240730_changes_for_push_integrations::Migration),
Box::new(m20240805_add_new_section_to_dashboard::Migration),
]
}
}
1 change: 1 addition & 0 deletions libs/generated/src/graphql/backend/graphql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,7 @@ export type CreateUserNotificationPlatformInput = {

export enum DashboardElementLot {
InProgress = 'IN_PROGRESS',
Recommendations = 'RECOMMENDATIONS',
Summary = 'SUMMARY',
Upcoming = 'UPCOMING'
}
Expand Down

0 comments on commit ba13ecb

Please sign in to comment.