-
Notifications
You must be signed in to change notification settings - Fork 13
Fix last card being cut off in mobile view #68
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
Open
wcypierre
wants to merge
5
commits into
relvacode:master
Choose a base branch
from
wcypierre:bugfix/last-card-cut-off
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
dcaaadd
Fix last card being cut off in mobile view
wcypierre b8abd37
Initial plan
Copilot 5eb46ac
Add PreferencesService for storing user filter preferences in localSt…
Copilot 822dc5a
Add type safety with SortField type and validation for stored prefere…
Copilot 08b8e52
Merge pull request #1 from wcypierre/copilot/store-user-preferences-l…
wcypierre File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -56,7 +56,7 @@ | |
| } | ||
|
|
||
| .layout-content { | ||
| padding: 1rem; | ||
| padding: 1rem 1rem 5rem 1rem; | ||
| } | ||
| } | ||
|
|
||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,116 @@ | ||
| import {TestBed} from '@angular/core/testing'; | ||
|
|
||
| import {PreferencesService, UserPreferences} from './preferences.service'; | ||
|
|
||
| describe('PreferencesService', () => { | ||
| let service: PreferencesService; | ||
|
|
||
| beforeEach(() => { | ||
| TestBed.configureTestingModule({}); | ||
| service = TestBed.inject(PreferencesService); | ||
| localStorage.clear(); | ||
| }); | ||
|
|
||
| afterEach(() => { | ||
| localStorage.clear(); | ||
| }); | ||
|
|
||
| it('should be created', () => { | ||
| expect(service).toBeTruthy(); | ||
| }); | ||
|
|
||
| describe('load', () => { | ||
| it('should return default preferences when no preferences are saved', () => { | ||
| const prefs = service.load(); | ||
| expect(prefs.sortByField).toBeNull(); | ||
| expect(prefs.sortReverse).toBe(false); | ||
| expect(prefs.filterState).toBeNull(); | ||
| }); | ||
|
|
||
| it('should return saved preferences', () => { | ||
| const saved: UserPreferences = { | ||
| sortByField: 'Name', | ||
| sortReverse: true, | ||
| filterState: 'Downloading', | ||
| }; | ||
| localStorage.setItem('storm_preferences', JSON.stringify(saved)); | ||
|
|
||
| const prefs = service.load(); | ||
| expect(prefs.sortByField).toBe('Name'); | ||
| expect(prefs.sortReverse).toBe(true); | ||
| expect(prefs.filterState).toBe('Downloading'); | ||
| }); | ||
|
|
||
| it('should return default preferences when localStorage contains invalid JSON', () => { | ||
| localStorage.setItem('storm_preferences', 'invalid json'); | ||
|
|
||
| const prefs = service.load(); | ||
| expect(prefs.sortByField).toBeNull(); | ||
| expect(prefs.sortReverse).toBe(false); | ||
| expect(prefs.filterState).toBeNull(); | ||
| }); | ||
|
|
||
| it('should merge saved preferences with defaults for missing fields', () => { | ||
| localStorage.setItem('storm_preferences', JSON.stringify({sortByField: 'State'})); | ||
|
|
||
| const prefs = service.load(); | ||
| expect(prefs.sortByField).toBe('State'); | ||
| expect(prefs.sortReverse).toBe(false); | ||
| expect(prefs.filterState).toBeNull(); | ||
| }); | ||
|
|
||
| it('should return default values for invalid sort fields', () => { | ||
| localStorage.setItem('storm_preferences', JSON.stringify({sortByField: 'InvalidField'})); | ||
|
|
||
| const prefs = service.load(); | ||
| expect(prefs.sortByField).toBeNull(); | ||
| }); | ||
|
|
||
| it('should return default values for invalid filter states', () => { | ||
| localStorage.setItem('storm_preferences', JSON.stringify({filterState: 'InvalidState'})); | ||
|
|
||
| const prefs = service.load(); | ||
| expect(prefs.filterState).toBeNull(); | ||
| }); | ||
|
|
||
| it('should return default values for invalid sortReverse type', () => { | ||
| localStorage.setItem('storm_preferences', JSON.stringify({sortReverse: 'yes'})); | ||
|
|
||
| const prefs = service.load(); | ||
| expect(prefs.sortReverse).toBe(false); | ||
| }); | ||
| }); | ||
|
|
||
| describe('save', () => { | ||
| it('should save preferences to localStorage', () => { | ||
| service.save({sortByField: 'Progress', sortReverse: true}); | ||
|
|
||
| const stored = localStorage.getItem('storm_preferences'); | ||
| expect(stored).toBeTruthy(); | ||
|
|
||
| const parsed = JSON.parse(stored); | ||
| expect(parsed.sortByField).toBe('Progress'); | ||
| expect(parsed.sortReverse).toBe(true); | ||
| }); | ||
|
|
||
| it('should merge new preferences with existing preferences', () => { | ||
| service.save({sortByField: 'Name'}); | ||
| service.save({filterState: 'Seeding'}); | ||
|
|
||
| const stored = localStorage.getItem('storm_preferences'); | ||
| const parsed = JSON.parse(stored); | ||
| expect(parsed.sortByField).toBe('Name'); | ||
| expect(parsed.filterState).toBe('Seeding'); | ||
| }); | ||
| }); | ||
|
|
||
| describe('clear', () => { | ||
| it('should remove preferences from localStorage', () => { | ||
| service.save({sortByField: 'Name'}); | ||
| expect(localStorage.getItem('storm_preferences')).toBeTruthy(); | ||
|
|
||
| service.clear(); | ||
| expect(localStorage.getItem('storm_preferences')).toBeNull(); | ||
| }); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,89 @@ | ||
| import {Injectable} from '@angular/core'; | ||
| import {State, Torrent} from './api.service'; | ||
|
|
||
| /** | ||
| * Valid sort field values for torrents | ||
| */ | ||
| export type SortField = 'State' | 'TimeAdded' | 'Progress' | 'ETA' | 'Name' | 'TotalSize' | 'Ratio' | 'SeedingTime'; | ||
|
|
||
| /** | ||
| * User preferences for filtering and sorting torrents | ||
| */ | ||
| export interface UserPreferences { | ||
| sortByField: SortField | null; | ||
| sortReverse: boolean; | ||
| filterState: State | null; | ||
| } | ||
|
|
||
| const STORAGE_KEY = 'storm_preferences'; | ||
|
|
||
| const VALID_SORT_FIELDS: SortField[] = ['State', 'TimeAdded', 'Progress', 'ETA', 'Name', 'TotalSize', 'Ratio', 'SeedingTime']; | ||
| const VALID_FILTER_STATES: (State | null)[] = [null, 'Active', 'Queued', 'Downloading', 'Seeding', 'Paused', 'Error']; | ||
|
|
||
| const DEFAULT_PREFERENCES: UserPreferences = { | ||
| sortByField: null, | ||
| sortReverse: false, | ||
| filterState: null, | ||
| }; | ||
|
|
||
| @Injectable({ | ||
| providedIn: 'root' | ||
| }) | ||
| export class PreferencesService { | ||
|
|
||
| constructor() { | ||
| } | ||
|
|
||
| /** | ||
| * Load user preferences from localStorage | ||
| * @returns The saved preferences or default preferences if none exist | ||
| */ | ||
| public load(): UserPreferences { | ||
| try { | ||
| const stored = localStorage.getItem(STORAGE_KEY); | ||
| if (stored) { | ||
| const parsed = JSON.parse(stored); | ||
| // Validate and sanitize stored values | ||
| const sortByField = VALID_SORT_FIELDS.includes(parsed.sortByField) ? parsed.sortByField : null; | ||
| const sortReverse = typeof parsed.sortReverse === 'boolean' ? parsed.sortReverse : false; | ||
| const filterState = VALID_FILTER_STATES.includes(parsed.filterState) ? parsed.filterState : null; | ||
| return { | ||
| sortByField, | ||
| sortReverse, | ||
| filterState, | ||
| }; | ||
| } | ||
| } catch (e) { | ||
| console.error('Failed to load preferences from localStorage', e); | ||
| } | ||
| return {...DEFAULT_PREFERENCES}; | ||
| } | ||
|
|
||
| /** | ||
| * Save user preferences to localStorage | ||
| * @param preferences The preferences to save | ||
| */ | ||
| public save(preferences: Partial<UserPreferences>): void { | ||
| try { | ||
| const current = this.load(); | ||
| const updated = { | ||
| ...current, | ||
| ...preferences, | ||
| }; | ||
| localStorage.setItem(STORAGE_KEY, JSON.stringify(updated)); | ||
| } catch (e) { | ||
| console.error('Failed to save preferences to localStorage', e); | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Clear all saved preferences | ||
| */ | ||
| public clear(): void { | ||
| try { | ||
| localStorage.removeItem(STORAGE_KEY); | ||
| } catch (e) { | ||
| console.error('Failed to clear preferences from localStorage', e); | ||
| } | ||
| } | ||
| } |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.