mirror of
https://github.com/Sonny93/my-links.git
synced 2025-12-10 07:25:35 +00:00
feat: add multiple way to show collections and links
This commit is contained in:
26
app/user/controllers/display_preferences_controller.ts
Normal file
26
app/user/controllers/display_preferences_controller.ts
Normal file
@@ -0,0 +1,26 @@
|
||||
import { getDisplayPreferences } from '#shared/lib/display_preferences';
|
||||
import { updateDisplayPreferencesValidator } from '#user/validators/update_display_preferences';
|
||||
import { HttpContext } from '@adonisjs/core/http';
|
||||
|
||||
export default class DisplayPreferencesController {
|
||||
async update({ request, response, auth }: HttpContext) {
|
||||
const { displayPreferences } = await request.validateUsing(
|
||||
updateDisplayPreferencesValidator
|
||||
);
|
||||
const userPrefs = auth.user!.displayPreferences ?? {};
|
||||
const mergedPrefs = {
|
||||
linkListDisplay:
|
||||
displayPreferences.linkListDisplay ??
|
||||
userPrefs.linkListDisplay ??
|
||||
getDisplayPreferences().linkListDisplay,
|
||||
collectionListDisplay:
|
||||
displayPreferences.collectionListDisplay ??
|
||||
userPrefs.collectionListDisplay ??
|
||||
getDisplayPreferences().collectionListDisplay,
|
||||
};
|
||||
auth.user!.displayPreferences = mergedPrefs;
|
||||
console.log(auth.user!.displayPreferences);
|
||||
await auth.user!.save();
|
||||
return response.redirect().withQs().back();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user