Skip to content

Commit

Permalink
✨ Allow disabling job overlay (#542)
Browse files Browse the repository at this point in the history
* ✨ Allow disabling job overlay

Resolves #531

* 🗃️ Add migration
  • Loading branch information
aaronleopold authored Dec 26, 2024
1 parent 21cced8 commit 821c1bc
Show file tree
Hide file tree
Showing 10 changed files with 105 additions and 3 deletions.
2 changes: 2 additions & 0 deletions apps/server/src/routers/api/v1/user.rs
Original file line number Diff line number Diff line change
Expand Up @@ -400,6 +400,7 @@ async fn update_preferences(
input.enable_replace_primary_sidebar,
),
user_preferences::enable_hide_scrollbar::set(input.enable_hide_scrollbar),
user_preferences::enable_job_overlay::set(input.enable_job_overlay),
user_preferences::prefer_accent_color::set(input.prefer_accent_color),
user_preferences::show_thumbnails_in_headers::set(
input.show_thumbnails_in_headers,
Expand Down Expand Up @@ -572,6 +573,7 @@ pub struct UpdateUserPreferences {
pub enable_double_sidebar: bool,
pub enable_replace_primary_sidebar: bool,
pub enable_hide_scrollbar: bool,
pub enable_job_overlay: bool,
pub prefer_accent_color: bool,
pub show_thumbnails_in_headers: bool,
}
Expand Down
1 change: 1 addition & 0 deletions apps/server/src/utils/test_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ pub fn create_prisma_user(user: &User, hashed_pass: String) -> user::Data {
enable_replace_primary_sidebar: user_preferences
.enable_replace_primary_sidebar,
enable_hide_scrollbar: user_preferences.enable_hide_scrollbar,
enable_job_overlay: user_preferences.enable_job_overlay,
prefer_accent_color: user_preferences.prefer_accent_color,
show_thumbnails_in_headers: user_preferences.show_thumbnails_in_headers,
navigation_arrangement: None,
Expand Down
22 changes: 22 additions & 0 deletions core/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,34 @@ The `core` crate contains Stump's core functionalities, including the database s

## Structure 📦

At the root of the crate, you will find a `prisma` directory, which contains the database schema and models.

The `src` directory contains the following modules:

- `config`: Configuration for the any apps consuming the core, including environment variables and tracing
- `db`: Database client, models, and utilities
- `filesystem`: Anything related to the filesystem and handling of files
- `image`: Image processing and utilities
- `media`: Media processing and utilities
- `scanner`: The bulk of the indexing and scanning logic
- `job` (AGPL-3.0): Background job processing and execution
- `opds`: OPDS feed generation and XML utilities

## Database 🗄

Stump uses [Prisma](https://www.prisma.io/) as its ORM. Whenever you make changes to the database schema, you will need to re-generate your local client and then update any exported TypeScript types. To do this, you may run the following commands:

```bash
# Generate the Prisma client
cargo prisma generate --schema=./core/prisma/schema.prisma

# Export the TypeScript types
cargo codegen -- --skip-prisma

# Optionally, if a migration is needed
cargo prisma migrate dev --schema=./core/prisma/schema.prisma
```

## License 📝

This crate is licensed under the [MIT License](https://www.tldrlegal.com/license/mit-license), with the exception of the `job` module, which is licensed under the [AGPL-3.0 License](<https://www.tldrlegal.com/license/gnu-affero-general-public-license-v3-(agpl-3.0)>). The `job` module could not be possible without the work of, primarily, two other open source projects which had a significant influence on the design and implementation of the module. Therefore, I would consider it derivative work of those projects collectively:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
-- RedefineTables
PRAGMA foreign_keys=OFF;
CREATE TABLE "new_user_preferences" (
"id" TEXT NOT NULL PRIMARY KEY,
"preferred_layout_mode" TEXT NOT NULL DEFAULT 'GRID',
"locale" TEXT NOT NULL DEFAULT 'en',
"app_theme" TEXT NOT NULL DEFAULT 'LIGHT',
"app_font" TEXT NOT NULL DEFAULT 'inter',
"primary_navigation_mode" TEXT NOT NULL DEFAULT 'SIDEBAR',
"layout_max_width_px" INTEGER DEFAULT 1280,
"show_query_indicator" BOOLEAN NOT NULL DEFAULT false,
"enable_live_refetch" BOOLEAN NOT NULL DEFAULT false,
"enable_discord_presence" BOOLEAN NOT NULL DEFAULT false,
"enable_compact_display" BOOLEAN NOT NULL DEFAULT false,
"enable_gradients" BOOLEAN NOT NULL DEFAULT false,
"enable_double_sidebar" BOOLEAN NOT NULL DEFAULT true,
"enable_replace_primary_sidebar" BOOLEAN NOT NULL DEFAULT false,
"enable_hide_scrollbar" BOOLEAN NOT NULL DEFAULT false,
"prefer_accent_color" BOOLEAN NOT NULL DEFAULT true,
"show_thumbnails_in_headers" BOOLEAN NOT NULL DEFAULT false,
"enable_job_overlay" BOOLEAN NOT NULL DEFAULT true,
"navigation_arrangement" BLOB,
"home_arrangement" BLOB,
"user_id" TEXT
);
INSERT INTO "new_user_preferences" ("app_font", "app_theme", "enable_compact_display", "enable_discord_presence", "enable_double_sidebar", "enable_gradients", "enable_hide_scrollbar", "enable_live_refetch", "enable_replace_primary_sidebar", "home_arrangement", "id", "layout_max_width_px", "locale", "navigation_arrangement", "prefer_accent_color", "preferred_layout_mode", "primary_navigation_mode", "show_query_indicator", "show_thumbnails_in_headers", "user_id") SELECT "app_font", "app_theme", "enable_compact_display", "enable_discord_presence", "enable_double_sidebar", "enable_gradients", "enable_hide_scrollbar", "enable_live_refetch", "enable_replace_primary_sidebar", "home_arrangement", "id", "layout_max_width_px", "locale", "navigation_arrangement", "prefer_accent_color", "preferred_layout_mode", "primary_navigation_mode", "show_query_indicator", "show_thumbnails_in_headers", "user_id" FROM "user_preferences";
DROP TABLE "user_preferences";
ALTER TABLE "new_user_preferences" RENAME TO "user_preferences";
CREATE UNIQUE INDEX "user_preferences_user_id_key" ON "user_preferences"("user_id");
PRAGMA foreign_key_check;
PRAGMA foreign_keys=ON;
1 change: 1 addition & 0 deletions core/prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -767,6 +767,7 @@ model UserPreferences {
enable_hide_scrollbar Boolean @default(false)
prefer_accent_color Boolean @default(true)
show_thumbnails_in_headers Boolean @default(false)
enable_job_overlay Boolean @default(true)
navigation_arrangement Bytes?
home_arrangement Bytes?
Expand Down
4 changes: 4 additions & 0 deletions core/src/db/entity/user/preferences.rs
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,8 @@ pub struct UserPreferences {
pub prefer_accent_color: bool,
#[serde(default)]
pub show_thumbnails_in_headers: bool,
#[serde(default = "default_true")]
pub enable_job_overlay: bool,

#[serde(default = "Arrangement::<NavigationItem>::default_navigation")]
pub navigation_arrangement: Arrangement<NavigationItem>,
Expand All @@ -232,6 +234,7 @@ impl Default for UserPreferences {
enable_double_sidebar: true,
enable_replace_primary_sidebar: false,
enable_hide_scrollbar: false,
enable_job_overlay: true,
prefer_accent_color: true,
show_thumbnails_in_headers: false,
navigation_arrangement: Arrangement::<NavigationItem>::default_navigation(),
Expand Down Expand Up @@ -285,6 +288,7 @@ impl From<prisma::user_preferences::Data> for UserPreferences {
enable_double_sidebar: data.enable_double_sidebar,
enable_replace_primary_sidebar: data.enable_replace_primary_sidebar,
enable_hide_scrollbar: data.enable_hide_scrollbar,
enable_job_overlay: data.enable_job_overlay,
prefer_accent_color: data.prefer_accent_color,
show_thumbnails_in_headers: data.show_thumbnails_in_headers,
navigation_arrangement,
Expand Down
5 changes: 4 additions & 1 deletion packages/browser/src/AppLayout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ export function AppLayout() {
})

const hideScrollBar = storeUser?.user_preferences?.enable_hide_scrollbar ?? false
const jobOverlayEnabled = storeUser?.user_preferences?.enable_job_overlay ?? true
const showJobOverlay = jobOverlayEnabled && !location.pathname.match(/\/settings\/jobs/)

const isRefSet = !!mainRef.current
/**
* An effect to initialize the overlay scrollbars
Expand Down Expand Up @@ -232,7 +235,7 @@ export function AppLayout() {
</div>

{/* {platform !== 'browser' && <ServerStatusOverlay />} */}
{!location.pathname.match(/\/settings\/jobs/) && <JobOverlay />}
{showJobOverlay && <JobOverlay />}
</Suspense>
</AppContext.Provider>
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { Helmet } from 'react-helmet'
import { Container, ContentContainer } from '@/components/container'

import DisplaySpacingPreference from './DisplaySpacingPreference'
import EnableJobOverlayToggle from './EnableJobOverlayToggle'
import FontSelect from './FontSelect'
import GradientToggle from './GradientToggle'
import HideScrollbarToggle from './HideScrollbarToggle'
Expand Down Expand Up @@ -54,6 +55,7 @@ export default function AppearanceSettingsScene() {
<HideScrollbarToggle />
<QueryIndicatorToggle />
<LiveRefetchToggle />
<EnableJobOverlayToggle />
</div>
</ContentContainer>
</Container>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import { useUpdatePreferences } from '@stump/client'
import { UpdateUserPreferences } from '@stump/sdk'

import { useUserStore } from '@/stores'

import PreferenceToggle from '../../PreferenceToggle'

export default function EnableJobOverlayToggle() {
const { preferences, setPreferences } = useUserStore((state) => ({
preferences: state.userPreferences,
setPreferences: state.setUserPreferences,
}))

const { update } = useUpdatePreferences({
onSuccess: setPreferences,
})

const handleChange = () => {
if (preferences) {
update({
...preferences,
enable_job_overlay: !preferences.enable_job_overlay,
} as UpdateUserPreferences)
}
}

return (
<PreferenceToggle
formId="enable_job_overlay"
label="Job overlay"
description="Show a floating overlay while a job is running"
isChecked={preferences?.enable_job_overlay}
onToggle={handleChange}
/>
)
}
4 changes: 2 additions & 2 deletions packages/sdk/src/types/generated.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ export type ArrangementItem<I> = { item: I; visible?: boolean }

export type Arrangement<I> = { locked: boolean; items: ArrangementItem<I>[] }

export type UserPreferences = { id: string; locale: string; app_theme: string; enable_gradients?: boolean; app_font?: SupportedFont; show_query_indicator?: boolean; enable_live_refetch?: boolean; preferred_layout_mode?: string; primary_navigation_mode?: string; layout_max_width_px?: number | null; enable_discord_presence?: boolean; enable_compact_display?: boolean; enable_double_sidebar?: boolean; enable_hide_scrollbar?: boolean; enable_replace_primary_sidebar?: boolean; prefer_accent_color?: boolean; show_thumbnails_in_headers?: boolean; navigation_arrangement?: Arrangement<NavigationItem>; home_arrangement?: Arrangement<HomeItem> }
export type UserPreferences = { id: string; locale: string; app_theme: string; enable_gradients?: boolean; app_font?: SupportedFont; show_query_indicator?: boolean; enable_live_refetch?: boolean; preferred_layout_mode?: string; primary_navigation_mode?: string; layout_max_width_px?: number | null; enable_discord_presence?: boolean; enable_compact_display?: boolean; enable_double_sidebar?: boolean; enable_hide_scrollbar?: boolean; enable_replace_primary_sidebar?: boolean; prefer_accent_color?: boolean; show_thumbnails_in_headers?: boolean; enable_job_overlay?: boolean; navigation_arrangement?: Arrangement<NavigationItem>; home_arrangement?: Arrangement<HomeItem> }

export type LoginActivity = { id: string; ip_address: string; user_agent: string; authentication_successful: boolean; timestamp: string; user?: User | null }

Expand Down Expand Up @@ -351,7 +351,7 @@ export type CreateUser = { username: string; password: string; permissions?: Use

export type UpdateUser = { username: string; password: string | null; avatar_url: string | null; permissions?: UserPermission[]; age_restriction: AgeRestriction | null; max_sessions_allowed?: number | null }

export type UpdateUserPreferences = { id: string; locale: string; preferred_layout_mode: string; primary_navigation_mode: string; layout_max_width_px: number | null; app_theme: string; enable_gradients: boolean; app_font: SupportedFont; show_query_indicator: boolean; enable_live_refetch: boolean; enable_discord_presence: boolean; enable_compact_display: boolean; enable_double_sidebar: boolean; enable_replace_primary_sidebar: boolean; enable_hide_scrollbar: boolean; prefer_accent_color: boolean; show_thumbnails_in_headers: boolean }
export type UpdateUserPreferences = { id: string; locale: string; preferred_layout_mode: string; primary_navigation_mode: string; layout_max_width_px: number | null; app_theme: string; enable_gradients: boolean; app_font: SupportedFont; show_query_indicator: boolean; enable_live_refetch: boolean; enable_discord_presence: boolean; enable_compact_display: boolean; enable_double_sidebar: boolean; enable_replace_primary_sidebar: boolean; enable_hide_scrollbar: boolean; enable_job_overlay: boolean; prefer_accent_color: boolean; show_thumbnails_in_headers: boolean }

export type DeleteUser = { hard_delete: boolean | null }

Expand Down

0 comments on commit 821c1bc

Please sign in to comment.