mirror of
https://github.com/Sonny93/my-links.git
synced 2025-12-08 22:53:25 +00:00
Compare commits
17 Commits
56b52adac0
...
44c187acaf
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
44c187acaf | ||
|
|
a076560285 | ||
|
|
3d986bd662 | ||
|
|
8537eeb375 | ||
|
|
7672a719ea | ||
|
|
23ad1fda75 | ||
|
|
4ef2b639b6 | ||
|
|
18fe979069 | ||
|
|
5f7fad26fa | ||
|
|
87ced07d20 | ||
|
|
ac0605caf5 | ||
|
|
11df24128f | ||
|
|
42f391d99a | ||
|
|
1d1e182523 | ||
|
|
81d02d3d80 | ||
|
|
d57f3ec486 | ||
|
|
9ff3ca112c |
@@ -99,7 +99,7 @@ type FaviconGetHead = {
|
|||||||
type LinksCreateGetHead = {
|
type LinksCreateGetHead = {
|
||||||
request: unknown;
|
request: unknown;
|
||||||
response: MakeTuyauResponse<
|
response: MakeTuyauResponse<
|
||||||
import('../app/links/controllers/links_controller.ts').default['showCreatePage'],
|
import('../app/links/controllers/delete_link_controller.js').default['showCreatePage'],
|
||||||
false
|
false
|
||||||
>;
|
>;
|
||||||
};
|
};
|
||||||
@@ -110,14 +110,14 @@ type LinksPost = {
|
|||||||
>
|
>
|
||||||
>;
|
>;
|
||||||
response: MakeTuyauResponse<
|
response: MakeTuyauResponse<
|
||||||
import('../app/links/controllers/links_controller.ts').default['store'],
|
import('../app/links/controllers/delete_link_controller.js').default['store'],
|
||||||
true
|
true
|
||||||
>;
|
>;
|
||||||
};
|
};
|
||||||
type LinksEditGetHead = {
|
type LinksEditGetHead = {
|
||||||
request: unknown;
|
request: unknown;
|
||||||
response: MakeTuyauResponse<
|
response: MakeTuyauResponse<
|
||||||
import('../app/links/controllers/links_controller.ts').default['showEditPage'],
|
import('../app/links/controllers/delete_link_controller.js').default['showEditPage'],
|
||||||
false
|
false
|
||||||
>;
|
>;
|
||||||
};
|
};
|
||||||
@@ -128,7 +128,7 @@ type LinksIdPut = {
|
|||||||
>
|
>
|
||||||
>;
|
>;
|
||||||
response: MakeTuyauResponse<
|
response: MakeTuyauResponse<
|
||||||
import('../app/links/controllers/links_controller.ts').default['update'],
|
import('../app/links/controllers/delete_link_controller.js').default['update'],
|
||||||
true
|
true
|
||||||
>;
|
>;
|
||||||
};
|
};
|
||||||
@@ -139,14 +139,14 @@ type LinksIdFavoritePut = {
|
|||||||
>
|
>
|
||||||
>;
|
>;
|
||||||
response: MakeTuyauResponse<
|
response: MakeTuyauResponse<
|
||||||
import('../app/links/controllers/links_controller.ts').default['toggleFavorite'],
|
import('../app/links/controllers/delete_link_controller.js').default['toggleFavorite'],
|
||||||
true
|
true
|
||||||
>;
|
>;
|
||||||
};
|
};
|
||||||
type LinksDeleteGetHead = {
|
type LinksDeleteGetHead = {
|
||||||
request: unknown;
|
request: unknown;
|
||||||
response: MakeTuyauResponse<
|
response: MakeTuyauResponse<
|
||||||
import('../app/links/controllers/links_controller.ts').default['showDeletePage'],
|
import('../app/links/controllers/delete_link_controller.js').default['showDeletePage'],
|
||||||
false
|
false
|
||||||
>;
|
>;
|
||||||
};
|
};
|
||||||
@@ -157,7 +157,7 @@ type LinksIdDelete = {
|
|||||||
>
|
>
|
||||||
>;
|
>;
|
||||||
response: MakeTuyauResponse<
|
response: MakeTuyauResponse<
|
||||||
import('../app/links/controllers/links_controller.ts').default['delete'],
|
import('../app/links/controllers/delete_link_controller.js').default['execute'],
|
||||||
true
|
true
|
||||||
>;
|
>;
|
||||||
};
|
};
|
||||||
|
|||||||
14
.env.example
14
.env.example
@@ -1,16 +1,22 @@
|
|||||||
# node ace generate:key
|
# App
|
||||||
APP_KEY=soY8ZAtItT_fCkNUADfgffZUUo675lOj
|
|
||||||
TZ=UTC
|
TZ=UTC
|
||||||
PORT=3333
|
PORT=3333
|
||||||
HOST=localhost
|
HOST=localhost
|
||||||
LOG_LEVEL=info
|
LOG_LEVEL=debug
|
||||||
|
APP_KEY=soY8ZAtItT_fCkNUADfgffZUUo675lOj # node ace generate:key
|
||||||
NODE_ENV=development
|
NODE_ENV=development
|
||||||
SESSION_DRIVER=cookie
|
SESSION_DRIVER=cookie
|
||||||
|
|
||||||
|
# App url
|
||||||
|
APP_URL=http://localhost:3333
|
||||||
|
|
||||||
|
# Database
|
||||||
DB_HOST=127.0.0.1
|
DB_HOST=127.0.0.1
|
||||||
DB_PORT=5432
|
DB_PORT=5432
|
||||||
DB_USER=root
|
DB_USER=root
|
||||||
DB_PASSWORD=root
|
DB_PASSWORD=root
|
||||||
DB_DATABASE=app
|
DB_DATABASE=app
|
||||||
|
|
||||||
|
# Google
|
||||||
GOOGLE_CLIENT_ID=
|
GOOGLE_CLIENT_ID=
|
||||||
GOOGLE_CLIENT_SECRET=
|
GOOGLE_CLIENT_SECRET=
|
||||||
GOOGLE_CLIENT_CALLBACK_URL=http://localhost:3333/auth/callback
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
# Source : https://github.com/adonisjs-community/adonis-packages/blob/main/Dockerfile
|
# Source : https://github.com/adonisjs-community/adonis-packages/blob/main/Dockerfile
|
||||||
|
|
||||||
FROM node:24.1-alpine3.20 AS base
|
FROM node:24.6-alpine3.22 AS base
|
||||||
|
|
||||||
RUN apk --no-cache add curl
|
RUN apk --no-cache add curl
|
||||||
RUN corepack enable
|
RUN corepack enable
|
||||||
@@ -34,9 +34,9 @@ ENV DB_PORT=5432
|
|||||||
ENV DB_USER=db_user
|
ENV DB_USER=db_user
|
||||||
ENV DB_PASSWORD=db_password
|
ENV DB_PASSWORD=db_password
|
||||||
ENV DB_DATABASE=db_db
|
ENV DB_DATABASE=db_db
|
||||||
|
ENV APP_URL=http://localhost:3333
|
||||||
ENV GOOGLE_CLIENT_ID=client_id
|
ENV GOOGLE_CLIENT_ID=client_id
|
||||||
ENV GOOGLE_CLIENT_SECRET=client_secret
|
ENV GOOGLE_CLIENT_SECRET=client_secret
|
||||||
ENV GOOGLE_CLIENT_CALLBACK_URL=http://localhost:3333/auth/callback
|
|
||||||
|
|
||||||
RUN node ace izzy:routes
|
RUN node ace izzy:routes
|
||||||
RUN node ace build
|
RUN node ace build
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import AuthController from '#auth/controllers/auth_controller';
|
import AuthController from '#auth/controllers/auth_controller';
|
||||||
import CollectionsController from '#collections/controllers/show_collections_controller';
|
import { CollectionService } from '#collections/services/collection_service';
|
||||||
import LinksController from '#links/controllers/links_controller';
|
import LinksController from '#links/controllers/delete_link_controller';
|
||||||
import User from '#user/models/user';
|
import User from '#user/models/user';
|
||||||
import { inject } from '@adonisjs/core';
|
import { inject } from '@adonisjs/core';
|
||||||
import { HttpContext } from '@adonisjs/core/http';
|
import { HttpContext } from '@adonisjs/core/http';
|
||||||
@@ -28,14 +28,14 @@ export default class AdminController {
|
|||||||
constructor(
|
constructor(
|
||||||
protected usersController: AuthController,
|
protected usersController: AuthController,
|
||||||
protected linksController: LinksController,
|
protected linksController: LinksController,
|
||||||
protected collectionsController: CollectionsController
|
protected collectionService: CollectionService
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
async index({ inertia }: HttpContext) {
|
async index({ inertia }: HttpContext) {
|
||||||
const users = await this.usersController.getAllUsersWithTotalRelations();
|
const users = await this.usersController.getAllUsersWithTotalRelations();
|
||||||
const linksCount = await this.linksController.getTotalLinksCount();
|
const linksCount = await this.linksController.getTotalLinksCount();
|
||||||
const collectionsCount =
|
const collectionsCount =
|
||||||
await this.collectionsController.getTotalCollectionsCount();
|
await this.collectionService.getTotalCollectionsCount();
|
||||||
|
|
||||||
return inertia.render('admin/dashboard', {
|
return inertia.render('admin/dashboard', {
|
||||||
users: users.map((user) => new UserWithRelationCountDto(user).toJson()),
|
users: users.map((user) => new UserWithRelationCountDto(user).toJson()),
|
||||||
|
|||||||
@@ -1,32 +0,0 @@
|
|||||||
import Collection from '#collections/models/collection';
|
|
||||||
import { HttpContext } from '@adonisjs/core/http';
|
|
||||||
import vine from '@vinejs/vine';
|
|
||||||
|
|
||||||
export default class BaseCollectionController {
|
|
||||||
protected collectionIdValidator = vine.compile(
|
|
||||||
vine.object({
|
|
||||||
collectionId: vine.number().positive().optional(),
|
|
||||||
})
|
|
||||||
);
|
|
||||||
|
|
||||||
async validateCollectionId(collectionIdRequired: boolean = true) {
|
|
||||||
const ctx = HttpContext.getOrFail();
|
|
||||||
const { collectionId } = await ctx.request.validateUsing(
|
|
||||||
this.collectionIdValidator
|
|
||||||
);
|
|
||||||
if (!collectionId && collectionIdRequired) {
|
|
||||||
console.log('redirecting to dashboard');
|
|
||||||
ctx.response.redirectToNamedRoute('dashboard');
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
console.log('collectionId', collectionId);
|
|
||||||
return collectionId;
|
|
||||||
}
|
|
||||||
|
|
||||||
redirectToCollectionId(collectionId: Collection['id']) {
|
|
||||||
const ctx = HttpContext.getOrFail();
|
|
||||||
return ctx.response.redirectToNamedRoute('dashboard', {
|
|
||||||
qs: { collectionId },
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,17 +1,15 @@
|
|||||||
import BaseCollectionController from '#collections/controllers/base_collection_controller';
|
|
||||||
import { CollectionService } from '#collections/services/collection_service';
|
import { CollectionService } from '#collections/services/collection_service';
|
||||||
import { createCollectionValidator } from '#collections/validators/create_collection_validator';
|
import { createCollectionValidator } from '#collections/validators/create_collection_validator';
|
||||||
import { inject } from '@adonisjs/core';
|
import { inject } from '@adonisjs/core';
|
||||||
import { type HttpContext } from '@adonisjs/core/http';
|
import { type HttpContext } from '@adonisjs/core/http';
|
||||||
|
|
||||||
@inject()
|
@inject()
|
||||||
export default class CreateCollectionController extends BaseCollectionController {
|
export default class CreateCollectionController {
|
||||||
constructor(private collectionService: CollectionService) {
|
constructor(private collectionService: CollectionService) {}
|
||||||
super();
|
|
||||||
}
|
|
||||||
|
|
||||||
async render({ inertia }: HttpContext) {
|
async render({ inertia }: HttpContext) {
|
||||||
const collections = await this.collectionService.getCollectionsByAuthorId();
|
const collections =
|
||||||
|
await this.collectionService.getCollectionsForAuthenticatedUser();
|
||||||
return inertia.render('collections/create', {
|
return inertia.render('collections/create', {
|
||||||
disableHomeLink: collections.length === 0,
|
disableHomeLink: collections.length === 0,
|
||||||
});
|
});
|
||||||
@@ -20,6 +18,6 @@ export default class CreateCollectionController extends BaseCollectionController
|
|||||||
async execute({ request }: HttpContext) {
|
async execute({ request }: HttpContext) {
|
||||||
const payload = await request.validateUsing(createCollectionValidator);
|
const payload = await request.validateUsing(createCollectionValidator);
|
||||||
const collection = await this.collectionService.createCollection(payload);
|
const collection = await this.collectionService.createCollection(payload);
|
||||||
return this.redirectToCollectionId(collection.id);
|
return this.collectionService.redirectToCollectionId(collection.id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,17 +1,14 @@
|
|||||||
import BaseCollectionController from '#collections/controllers/base_collection_controller';
|
|
||||||
import { CollectionService } from '#collections/services/collection_service';
|
import { CollectionService } from '#collections/services/collection_service';
|
||||||
import { deleteCollectionValidator } from '#collections/validators/delete_collection_validator';
|
import { deleteCollectionValidator } from '#collections/validators/delete_collection_validator';
|
||||||
import { inject } from '@adonisjs/core';
|
import { inject } from '@adonisjs/core';
|
||||||
import { HttpContext } from '@adonisjs/core/http';
|
import { HttpContext } from '@adonisjs/core/http';
|
||||||
|
|
||||||
@inject()
|
@inject()
|
||||||
export default class DeleteCollectionController extends BaseCollectionController {
|
export default class DeleteCollectionController {
|
||||||
constructor(private collectionService: CollectionService) {
|
constructor(private collectionService: CollectionService) {}
|
||||||
super();
|
|
||||||
}
|
|
||||||
|
|
||||||
async render({ inertia }: HttpContext) {
|
async render({ inertia }: HttpContext) {
|
||||||
const collectionId = await this.validateCollectionId();
|
const collectionId = await this.collectionService.validateCollectionId();
|
||||||
if (!collectionId) return;
|
if (!collectionId) return;
|
||||||
|
|
||||||
const collection =
|
const collection =
|
||||||
|
|||||||
@@ -1,21 +1,23 @@
|
|||||||
import BaseCollectionController from '#collections/controllers/base_collection_controller';
|
|
||||||
import { CollectionService } from '#collections/services/collection_service';
|
import { CollectionService } from '#collections/services/collection_service';
|
||||||
|
import { LinkService } from '#links/services/link_service';
|
||||||
import { inject } from '@adonisjs/core';
|
import { inject } from '@adonisjs/core';
|
||||||
import type { HttpContext } from '@adonisjs/core/http';
|
import type { HttpContext } from '@adonisjs/core/http';
|
||||||
|
|
||||||
@inject()
|
@inject()
|
||||||
export default class ShowCollectionsController extends BaseCollectionController {
|
export default class ShowCollectionsController {
|
||||||
constructor(private collectionService: CollectionService) {
|
constructor(
|
||||||
super();
|
private collectionService: CollectionService,
|
||||||
}
|
private linkService: LinkService
|
||||||
|
) {}
|
||||||
|
|
||||||
// Dashboard
|
// Dashboard
|
||||||
async render({ inertia, response }: HttpContext) {
|
async render({ inertia, response }: HttpContext) {
|
||||||
const activeCollectionId = await this.validateCollectionId(false);
|
const activeCollectionId =
|
||||||
const collections = await this.collectionService.getCollectionsByAuthorId();
|
await this.collectionService.validateCollectionId(false);
|
||||||
if (collections.length === 0) {
|
const [collections, favoriteLinks] = await Promise.all([
|
||||||
return response.redirectToNamedRoute('collection.create-form');
|
this.collectionService.getCollectionsForAuthenticatedUser(),
|
||||||
}
|
this.linkService.getFavoriteLinksForAuthenticatedUser(),
|
||||||
|
]);
|
||||||
|
|
||||||
const activeCollection = collections.find(
|
const activeCollection = collections.find(
|
||||||
(c) => c.id === activeCollectionId
|
(c) => c.id === activeCollectionId
|
||||||
@@ -27,8 +29,8 @@ export default class ShowCollectionsController extends BaseCollectionController
|
|||||||
|
|
||||||
return inertia.render('dashboard', {
|
return inertia.render('dashboard', {
|
||||||
collections: collections.map((collection) => collection.serialize()),
|
collections: collections.map((collection) => collection.serialize()),
|
||||||
activeCollection:
|
favoriteLinks: favoriteLinks.map((link) => link.serialize()),
|
||||||
activeCollection?.serialize() || collections[0].serialize(),
|
activeCollection: activeCollection?.serialize(),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,22 +1,19 @@
|
|||||||
import BaseCollectionController from '#collections/controllers/base_collection_controller';
|
|
||||||
import { CollectionService } from '#collections/services/collection_service';
|
import { CollectionService } from '#collections/services/collection_service';
|
||||||
import { updateCollectionValidator } from '#collections/validators/update_collection_validator';
|
import { updateCollectionValidator } from '#collections/validators/update_collection_validator';
|
||||||
import { inject } from '@adonisjs/core';
|
import { inject } from '@adonisjs/core';
|
||||||
import { HttpContext } from '@adonisjs/core/http';
|
import { HttpContext } from '@adonisjs/core/http';
|
||||||
|
|
||||||
@inject()
|
@inject()
|
||||||
export default class UpdateCollectionController extends BaseCollectionController {
|
export default class UpdateCollectionController {
|
||||||
constructor(private collectionService: CollectionService) {
|
constructor(private collectionService: CollectionService) {}
|
||||||
super();
|
|
||||||
}
|
|
||||||
|
|
||||||
async render({ inertia }: HttpContext) {
|
async render({ inertia }: HttpContext) {
|
||||||
const collectionId = await this.validateCollectionId();
|
const collectionId = await this.collectionService.validateCollectionId();
|
||||||
if (!collectionId) return;
|
if (!collectionId) return;
|
||||||
|
|
||||||
const collection =
|
const collection =
|
||||||
await this.collectionService.getCollectionById(collectionId);
|
await this.collectionService.getCollectionById(collectionId);
|
||||||
return inertia.render('collections/update', {
|
return inertia.render('collections/edit', {
|
||||||
collection: collection.serialize(),
|
collection: collection.serialize(),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -28,6 +25,6 @@ export default class UpdateCollectionController extends BaseCollectionController
|
|||||||
} = await request.validateUsing(updateCollectionValidator);
|
} = await request.validateUsing(updateCollectionValidator);
|
||||||
|
|
||||||
await this.collectionService.updateCollection(collectionId, payload);
|
await this.collectionService.updateCollection(collectionId, payload);
|
||||||
return this.redirectToCollectionId(collectionId);
|
return this.collectionService.redirectToCollectionId(collectionId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
import { Visibility } from '#collections/enums/visibility';
|
import { Visibility } from '#collections/enums/visibility';
|
||||||
import Collection from '#collections/models/collection';
|
import Collection from '#collections/models/collection';
|
||||||
|
import { collectionIdValidator } from '#collections/validators/collection_id_validator';
|
||||||
import { HttpContext } from '@adonisjs/core/http';
|
import { HttpContext } from '@adonisjs/core/http';
|
||||||
import db from '@adonisjs/lucid/services/db';
|
import db from '@adonisjs/lucid/services/db';
|
||||||
|
|
||||||
@@ -20,12 +21,12 @@ export class CollectionService {
|
|||||||
.firstOrFail();
|
.firstOrFail();
|
||||||
}
|
}
|
||||||
|
|
||||||
async getCollectionsByAuthorId() {
|
async getCollectionsForAuthenticatedUser() {
|
||||||
const context = this.getAuthContext();
|
const context = this.getAuthContext();
|
||||||
return await Collection.query()
|
return await Collection.query()
|
||||||
.where('author_id', context.auth.user!.id)
|
.where('author_id', context.auth.user!.id)
|
||||||
.orderBy('created_at')
|
.orderBy('created_at')
|
||||||
.preload('links');
|
.preload('links', (q) => q.orderBy('favorite', 'desc'));
|
||||||
}
|
}
|
||||||
|
|
||||||
async getTotalCollectionsCount() {
|
async getTotalCollectionsCount() {
|
||||||
@@ -60,11 +61,44 @@ export class CollectionService {
|
|||||||
.delete();
|
.delete();
|
||||||
}
|
}
|
||||||
|
|
||||||
getAuthContext() {
|
getPublicCollectionById(id: Collection['id']) {
|
||||||
|
return Collection.query()
|
||||||
|
.where('id', id)
|
||||||
|
.andWhere('visibility', Visibility.PUBLIC)
|
||||||
|
.preload('links')
|
||||||
|
.preload('author')
|
||||||
|
.firstOrFail();
|
||||||
|
}
|
||||||
|
|
||||||
|
private getAuthContext() {
|
||||||
const context = HttpContext.getOrFail();
|
const context = HttpContext.getOrFail();
|
||||||
if (!context.auth.user || !context.auth.user.id) {
|
if (!context.auth.user || !context.auth.user.id) {
|
||||||
throw new Error('User not authenticated');
|
throw new Error('User not authenticated');
|
||||||
}
|
}
|
||||||
return context;
|
return context;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async validateCollectionId(collectionIdRequired: boolean = true) {
|
||||||
|
const ctx = HttpContext.getOrFail();
|
||||||
|
const { collectionId } = await ctx.request.validateUsing(
|
||||||
|
collectionIdValidator
|
||||||
|
);
|
||||||
|
if (!collectionId && collectionIdRequired) {
|
||||||
|
this.redirectToDashboard();
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return collectionId;
|
||||||
|
}
|
||||||
|
|
||||||
|
redirectToCollectionId(collectionId: Collection['id']) {
|
||||||
|
const ctx = HttpContext.getOrFail();
|
||||||
|
return ctx.response.redirectToNamedRoute('dashboard', {
|
||||||
|
qs: { collectionId },
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
redirectToDashboard() {
|
||||||
|
const ctx = HttpContext.getOrFail();
|
||||||
|
return ctx.response.redirectToNamedRoute('dashboard');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
7
app/collections/validators/collection_id_validator.ts
Normal file
7
app/collections/validators/collection_id_validator.ts
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
import vine from '@vinejs/vine';
|
||||||
|
|
||||||
|
export const collectionIdValidator = vine.compile(
|
||||||
|
vine.object({
|
||||||
|
collectionId: vine.number().positive().optional(),
|
||||||
|
})
|
||||||
|
);
|
||||||
30
app/links/controllers/create_link_controller.ts
Normal file
30
app/links/controllers/create_link_controller.ts
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
import { CollectionService } from '#collections/services/collection_service';
|
||||||
|
import { LinkService } from '#links/services/link_service';
|
||||||
|
import { createLinkValidator } from '#links/validators/create_link_validator';
|
||||||
|
import { inject } from '@adonisjs/core';
|
||||||
|
import { HttpContext } from '@adonisjs/core/http';
|
||||||
|
|
||||||
|
@inject()
|
||||||
|
export default class CreateLinkController {
|
||||||
|
constructor(
|
||||||
|
private linkService: LinkService,
|
||||||
|
private collectionsService: CollectionService
|
||||||
|
) {}
|
||||||
|
|
||||||
|
async render({ inertia }: HttpContext) {
|
||||||
|
const collections =
|
||||||
|
await this.collectionsService.getCollectionsForAuthenticatedUser();
|
||||||
|
return inertia.render('links/create', { collections });
|
||||||
|
}
|
||||||
|
|
||||||
|
async execute({ request }: HttpContext) {
|
||||||
|
const { collectionId, ...payload } =
|
||||||
|
await request.validateUsing(createLinkValidator);
|
||||||
|
|
||||||
|
await this.linkService.createLink({
|
||||||
|
...payload,
|
||||||
|
collectionId,
|
||||||
|
});
|
||||||
|
return this.collectionsService.redirectToCollectionId(collectionId);
|
||||||
|
}
|
||||||
|
}
|
||||||
39
app/links/controllers/delete_link_controller.ts
Normal file
39
app/links/controllers/delete_link_controller.ts
Normal file
@@ -0,0 +1,39 @@
|
|||||||
|
import { CollectionService } from '#collections/services/collection_service';
|
||||||
|
import { LinkService } from '#links/services/link_service';
|
||||||
|
import { deleteLinkValidator } from '#links/validators/delete_link_validator';
|
||||||
|
import { inject } from '@adonisjs/core';
|
||||||
|
import { HttpContext } from '@adonisjs/core/http';
|
||||||
|
import db from '@adonisjs/lucid/services/db';
|
||||||
|
|
||||||
|
@inject()
|
||||||
|
export default class DeleteLinkController {
|
||||||
|
constructor(
|
||||||
|
protected collectionsService: CollectionService,
|
||||||
|
protected linkService: LinkService
|
||||||
|
) {}
|
||||||
|
|
||||||
|
async render({ auth, inertia, request }: HttpContext) {
|
||||||
|
const linkId = request.qs()?.linkId;
|
||||||
|
if (!linkId) {
|
||||||
|
return this.collectionsService.redirectToDashboard();
|
||||||
|
}
|
||||||
|
|
||||||
|
const link = await this.linkService.getLinkById(linkId, auth.user!.id);
|
||||||
|
await link.load('collection');
|
||||||
|
return inertia.render('links/delete', { link });
|
||||||
|
}
|
||||||
|
|
||||||
|
async execute({ request, auth }: HttpContext) {
|
||||||
|
const { params } = await request.validateUsing(deleteLinkValidator);
|
||||||
|
|
||||||
|
const link = await this.linkService.getLinkById(params.id, auth.user!.id);
|
||||||
|
await this.linkService.deleteLink(params.id);
|
||||||
|
|
||||||
|
return this.collectionsService.redirectToCollectionId(link.collectionId);
|
||||||
|
}
|
||||||
|
|
||||||
|
async getTotalLinksCount() {
|
||||||
|
const totalCount = await db.from('links').count('* as total');
|
||||||
|
return Number(totalCount[0].total);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,129 +0,0 @@
|
|||||||
import CollectionsController from '#collections/controllers/show_collections_controller';
|
|
||||||
import Link from '#links/models/link';
|
|
||||||
import { createLinkValidator } from '#links/validators/create_link_validator';
|
|
||||||
import { deleteLinkValidator } from '#links/validators/delete_link_validator';
|
|
||||||
import { updateLinkFavoriteStatusValidator } from '#links/validators/update_favorite_link_validator';
|
|
||||||
import { updateLinkValidator } from '#links/validators/update_link_validator';
|
|
||||||
import { inject } from '@adonisjs/core';
|
|
||||||
import { HttpContext } from '@adonisjs/core/http';
|
|
||||||
import db from '@adonisjs/lucid/services/db';
|
|
||||||
|
|
||||||
@inject()
|
|
||||||
export default class LinksController {
|
|
||||||
constructor(protected collectionsController: CollectionsController) {}
|
|
||||||
|
|
||||||
async showCreatePage({ auth, inertia }: HttpContext) {
|
|
||||||
const collections =
|
|
||||||
await this.collectionsController.getCollectionsByAuthorId(auth.user!.id);
|
|
||||||
return inertia.render('links/create', { collections });
|
|
||||||
}
|
|
||||||
|
|
||||||
async store({ auth, request, response }: HttpContext) {
|
|
||||||
const { collectionId, ...payload } =
|
|
||||||
await request.validateUsing(createLinkValidator);
|
|
||||||
|
|
||||||
await this.collectionsController.getCollectionById(
|
|
||||||
collectionId,
|
|
||||||
auth.user!.id
|
|
||||||
);
|
|
||||||
await Link.create({
|
|
||||||
...payload,
|
|
||||||
collectionId,
|
|
||||||
authorId: auth.user?.id!,
|
|
||||||
});
|
|
||||||
return this.collectionsController.redirectToCollectionId(
|
|
||||||
response,
|
|
||||||
collectionId
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
async showEditPage({ auth, inertia, request, response }: HttpContext) {
|
|
||||||
const linkId = request.qs()?.linkId;
|
|
||||||
if (!linkId) {
|
|
||||||
return response.redirectToNamedRoute('dashboard');
|
|
||||||
}
|
|
||||||
|
|
||||||
const userId = auth.user!.id;
|
|
||||||
const collections =
|
|
||||||
await this.collectionsController.getCollectionsByAuthorId(userId);
|
|
||||||
const link = await this.getLinkById(linkId, userId);
|
|
||||||
|
|
||||||
return inertia.render('links/edit', { collections, link });
|
|
||||||
}
|
|
||||||
|
|
||||||
async update({ request, auth, response }: HttpContext) {
|
|
||||||
const { params, ...payload } =
|
|
||||||
await request.validateUsing(updateLinkValidator);
|
|
||||||
|
|
||||||
// Throw if invalid link id provided
|
|
||||||
await this.getLinkById(params.id, auth.user!.id);
|
|
||||||
|
|
||||||
await Link.updateOrCreate(
|
|
||||||
{
|
|
||||||
id: params.id,
|
|
||||||
},
|
|
||||||
payload
|
|
||||||
);
|
|
||||||
|
|
||||||
return response.redirectToNamedRoute('dashboard', {
|
|
||||||
qs: { collectionId: payload.collectionId },
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
async toggleFavorite({ request, auth, response }: HttpContext) {
|
|
||||||
const { params, favorite } = await request.validateUsing(
|
|
||||||
updateLinkFavoriteStatusValidator
|
|
||||||
);
|
|
||||||
|
|
||||||
// Throw if invalid link id provided
|
|
||||||
await this.getLinkById(params.id, auth.user!.id);
|
|
||||||
|
|
||||||
await Link.updateOrCreate(
|
|
||||||
{
|
|
||||||
id: params.id,
|
|
||||||
},
|
|
||||||
{ favorite }
|
|
||||||
);
|
|
||||||
|
|
||||||
return response.json({ status: 'ok' });
|
|
||||||
}
|
|
||||||
|
|
||||||
async showDeletePage({ auth, inertia, request, response }: HttpContext) {
|
|
||||||
const linkId = request.qs()?.linkId;
|
|
||||||
if (!linkId) {
|
|
||||||
return response.redirectToNamedRoute('dashboard');
|
|
||||||
}
|
|
||||||
|
|
||||||
const link = await this.getLinkById(linkId, auth.user!.id);
|
|
||||||
await link.load('collection');
|
|
||||||
return inertia.render('links/delete', { link });
|
|
||||||
}
|
|
||||||
|
|
||||||
async delete({ request, auth, response }: HttpContext) {
|
|
||||||
const { params } = await request.validateUsing(deleteLinkValidator);
|
|
||||||
|
|
||||||
const link = await this.getLinkById(params.id, auth.user!.id);
|
|
||||||
await link.delete();
|
|
||||||
|
|
||||||
return response.redirectToNamedRoute('dashboard', {
|
|
||||||
qs: { collectionId: link.id },
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
async getTotalLinksCount() {
|
|
||||||
const totalCount = await db.from('links').count('* as total');
|
|
||||||
return Number(totalCount[0].total);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get link by id.
|
|
||||||
*
|
|
||||||
* /!\ Only return private link (create by the current user)
|
|
||||||
*/
|
|
||||||
private async getLinkById(id: Link['id'], userId: Link['id']) {
|
|
||||||
return await Link.query()
|
|
||||||
.where('id', id)
|
|
||||||
.andWhere('author_id', userId)
|
|
||||||
.firstOrFail();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
19
app/links/controllers/toggle_favorite_controller.ts
Normal file
19
app/links/controllers/toggle_favorite_controller.ts
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
import { LinkService } from '#links/services/link_service';
|
||||||
|
import { updateLinkFavoriteStatusValidator } from '#links/validators/update_favorite_link_validator';
|
||||||
|
import { inject } from '@adonisjs/core';
|
||||||
|
import { HttpContext } from '@adonisjs/core/http';
|
||||||
|
|
||||||
|
@inject()
|
||||||
|
export default class ToggleFavoriteController {
|
||||||
|
constructor(private linkService: LinkService) {}
|
||||||
|
|
||||||
|
async toggleFavorite({ request, response }: HttpContext) {
|
||||||
|
const { params, favorite } = await request.validateUsing(
|
||||||
|
updateLinkFavoriteStatusValidator
|
||||||
|
);
|
||||||
|
|
||||||
|
await this.linkService.updateFavorite(params.id, favorite);
|
||||||
|
|
||||||
|
return response.json({ status: 'ok' });
|
||||||
|
}
|
||||||
|
}
|
||||||
34
app/links/controllers/update_link_controller.ts
Normal file
34
app/links/controllers/update_link_controller.ts
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
import { CollectionService } from '#collections/services/collection_service';
|
||||||
|
import { LinkService } from '#links/services/link_service';
|
||||||
|
import { updateLinkValidator } from '#links/validators/update_link_validator';
|
||||||
|
import { inject } from '@adonisjs/core';
|
||||||
|
import { HttpContext } from '@adonisjs/core/http';
|
||||||
|
|
||||||
|
@inject()
|
||||||
|
export default class UpdateLinkController {
|
||||||
|
constructor(
|
||||||
|
private linkService: LinkService,
|
||||||
|
private collectionsService: CollectionService
|
||||||
|
) {}
|
||||||
|
|
||||||
|
async render({ auth, inertia, request, response }: HttpContext) {
|
||||||
|
const linkId = request.qs()?.linkId;
|
||||||
|
if (!linkId) {
|
||||||
|
return response.redirectToNamedRoute('dashboard');
|
||||||
|
}
|
||||||
|
|
||||||
|
const collections =
|
||||||
|
await this.collectionsService.getCollectionsForAuthenticatedUser();
|
||||||
|
const link = await this.linkService.getLinkById(linkId, auth.user!.id);
|
||||||
|
|
||||||
|
return inertia.render('links/edit', { collections, link });
|
||||||
|
}
|
||||||
|
|
||||||
|
async execute({ request }: HttpContext) {
|
||||||
|
const { params, ...payload } =
|
||||||
|
await request.validateUsing(updateLinkValidator);
|
||||||
|
|
||||||
|
await this.linkService.updateLink(params.id, payload);
|
||||||
|
return this.collectionsService.redirectToCollectionId(payload.collectionId);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,6 +1,14 @@
|
|||||||
import { middleware } from '#start/kernel';
|
import { middleware } from '#start/kernel';
|
||||||
import router from '@adonisjs/core/services/router';
|
import router from '@adonisjs/core/services/router';
|
||||||
const LinksController = () => import('#links/controllers/links_controller');
|
|
||||||
|
const CreateLinkController = () =>
|
||||||
|
import('#links/controllers/create_link_controller');
|
||||||
|
const DeleteLinkController = () =>
|
||||||
|
import('#links/controllers/delete_link_controller');
|
||||||
|
const UpdateLinkController = () =>
|
||||||
|
import('#links/controllers/update_link_controller');
|
||||||
|
const ToggleFavoriteController = () =>
|
||||||
|
import('#links/controllers/toggle_favorite_controller');
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Routes for authenticated users
|
* Routes for authenticated users
|
||||||
@@ -8,21 +16,21 @@ const LinksController = () => import('#links/controllers/links_controller');
|
|||||||
router
|
router
|
||||||
.group(() => {
|
.group(() => {
|
||||||
router
|
router
|
||||||
.get('/create', [LinksController, 'showCreatePage'])
|
.get('/create', [CreateLinkController, 'render'])
|
||||||
.as('link.create-form');
|
.as('link.create-form');
|
||||||
router.post('/', [LinksController, 'store']).as('link.create');
|
router.post('/', [CreateLinkController, 'execute']).as('link.create');
|
||||||
|
|
||||||
router.get('/edit', [LinksController, 'showEditPage']).as('link.edit-form');
|
router.get('/edit', [UpdateLinkController, 'render']).as('link.edit-form');
|
||||||
router.put('/:id', [LinksController, 'update']).as('link.edit');
|
router.put('/:id', [UpdateLinkController, 'execute']).as('link.edit');
|
||||||
|
|
||||||
router
|
router
|
||||||
.put('/:id/favorite', [LinksController, 'toggleFavorite'])
|
.put('/:id/favorite', [ToggleFavoriteController, 'toggleFavorite'])
|
||||||
.as('link.toggle-favorite');
|
.as('link.toggle-favorite');
|
||||||
|
|
||||||
router
|
router
|
||||||
.get('/delete', [LinksController, 'showDeletePage'])
|
.get('/delete', [DeleteLinkController, 'render'])
|
||||||
.as('link.delete-form');
|
.as('link.delete-form');
|
||||||
router.delete('/:id', [LinksController, 'delete']).as('link.delete');
|
router.delete('/:id', [DeleteLinkController, 'execute']).as('link.delete');
|
||||||
})
|
})
|
||||||
.middleware([middleware.auth()])
|
.middleware([middleware.auth()])
|
||||||
.prefix('/links');
|
.prefix('/links');
|
||||||
|
|||||||
68
app/links/services/link_service.ts
Normal file
68
app/links/services/link_service.ts
Normal file
@@ -0,0 +1,68 @@
|
|||||||
|
import Link from '#links/models/link';
|
||||||
|
import { HttpContext } from '@adonisjs/core/http';
|
||||||
|
|
||||||
|
type CreateLinkPayload = {
|
||||||
|
name: string;
|
||||||
|
description?: string;
|
||||||
|
url: string;
|
||||||
|
favorite: boolean;
|
||||||
|
collectionId: number;
|
||||||
|
};
|
||||||
|
|
||||||
|
type UpdateLinkPayload = CreateLinkPayload;
|
||||||
|
|
||||||
|
export class LinkService {
|
||||||
|
createLink(payload: CreateLinkPayload) {
|
||||||
|
const context = this.getAuthContext();
|
||||||
|
return Link.create({
|
||||||
|
...payload,
|
||||||
|
authorId: context.auth.user!.id,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
updateLink(id: number, payload: UpdateLinkPayload) {
|
||||||
|
const context = this.getAuthContext();
|
||||||
|
return Link.query()
|
||||||
|
.where('id', id)
|
||||||
|
.andWhere('author_id', context.auth.user!.id)
|
||||||
|
.update(payload);
|
||||||
|
}
|
||||||
|
|
||||||
|
deleteLink(id: number) {
|
||||||
|
const context = this.getAuthContext();
|
||||||
|
return Link.query()
|
||||||
|
.where('id', id)
|
||||||
|
.andWhere('author_id', context.auth.user!.id)
|
||||||
|
.delete();
|
||||||
|
}
|
||||||
|
|
||||||
|
async getLinkById(id: Link['id'], userId: Link['id']) {
|
||||||
|
return await Link.query()
|
||||||
|
.where('id', id)
|
||||||
|
.andWhere('author_id', userId)
|
||||||
|
.firstOrFail();
|
||||||
|
}
|
||||||
|
|
||||||
|
updateFavorite(id: number, favorite: boolean) {
|
||||||
|
return Link.query()
|
||||||
|
.where('id', id)
|
||||||
|
.andWhere('author_id', this.getAuthContext().auth.user!.id)
|
||||||
|
.update({ favorite });
|
||||||
|
}
|
||||||
|
|
||||||
|
async getFavoriteLinksForAuthenticatedUser() {
|
||||||
|
const context = this.getAuthContext();
|
||||||
|
return await Link.query()
|
||||||
|
.where('author_id', context.auth.user!.id)
|
||||||
|
.where('favorite', true)
|
||||||
|
.orderBy('created_at');
|
||||||
|
}
|
||||||
|
|
||||||
|
getAuthContext() {
|
||||||
|
const context = HttpContext.getOrFail();
|
||||||
|
if (!context.auth.user || !context.auth.user.id) {
|
||||||
|
throw new Error('User not authenticated');
|
||||||
|
}
|
||||||
|
return context;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,61 +1,19 @@
|
|||||||
import { Visibility } from '#collections/enums/visibility';
|
import { CollectionService } from '#collections/services/collection_service';
|
||||||
import Collection from '#collections/models/collection';
|
import { inject } from '@adonisjs/core';
|
||||||
import Link from '#links/models/link';
|
|
||||||
import User from '#user/models/user';
|
|
||||||
import type { HttpContext } from '@adonisjs/core/http';
|
import type { HttpContext } from '@adonisjs/core/http';
|
||||||
import { getSharedCollectionValidator } from '../validators/shared_collection.js';
|
import { getSharedCollectionValidator } from '../validators/shared_collection.js';
|
||||||
|
|
||||||
class LinkWithoutFavoriteDto {
|
@inject()
|
||||||
constructor(private link: Link) {}
|
|
||||||
|
|
||||||
toJson = () => ({
|
|
||||||
id: this.link.id,
|
|
||||||
name: this.link.name,
|
|
||||||
description: this.link.description,
|
|
||||||
url: this.link.url,
|
|
||||||
collectionId: this.link.collectionId,
|
|
||||||
createdAt: this.link.createdAt.toString(),
|
|
||||||
updatedAt: this.link.updatedAt.toString(),
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
class UserWithoutEmailDto {
|
|
||||||
constructor(private user: User) {}
|
|
||||||
|
|
||||||
toJson = () => ({
|
|
||||||
id: this.user.id,
|
|
||||||
fullname: this.user.name,
|
|
||||||
avatarUrl: this.user.avatarUrl,
|
|
||||||
isAdmin: this.user.isAdmin,
|
|
||||||
createdAt: this.user.createdAt.toString(),
|
|
||||||
updatedAt: this.user.updatedAt.toString(),
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
export default class SharedCollectionsController {
|
export default class SharedCollectionsController {
|
||||||
|
constructor(private collectionService: CollectionService) {}
|
||||||
|
|
||||||
async index({ request, inertia }: HttpContext) {
|
async index({ request, inertia }: HttpContext) {
|
||||||
const { params } = await request.validateUsing(
|
const { params } = await request.validateUsing(
|
||||||
getSharedCollectionValidator
|
getSharedCollectionValidator
|
||||||
);
|
);
|
||||||
|
|
||||||
const collection = await this.getSharedCollectionById(params.id);
|
const activeCollection =
|
||||||
return inertia.render('shared', { collection });
|
await this.collectionService.getPublicCollectionById(params.id);
|
||||||
}
|
return inertia.render('shared', { activeCollection });
|
||||||
|
|
||||||
private async getSharedCollectionById(id: Collection['id']) {
|
|
||||||
const collection = await Collection.query()
|
|
||||||
.where('id', id)
|
|
||||||
.andWhere('visibility', Visibility.PUBLIC)
|
|
||||||
.preload('links')
|
|
||||||
.preload('author')
|
|
||||||
.firstOrFail();
|
|
||||||
|
|
||||||
return {
|
|
||||||
...collection.serialize(),
|
|
||||||
links: collection.links.map((link) =>
|
|
||||||
new LinkWithoutFavoriteDto(link).toJson()
|
|
||||||
),
|
|
||||||
author: new UserWithoutEmailDto(collection.author).toJson(),
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
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();
|
||||||
|
}
|
||||||
|
}
|
||||||
12
app/user/lib/index.ts
Normal file
12
app/user/lib/index.ts
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
import { type DisplayPreferences } from '#shared/types/index';
|
||||||
|
import User from '#user/models/user';
|
||||||
|
|
||||||
|
export function ensureDisplayPreferences(user: User): DisplayPreferences {
|
||||||
|
const defaults: DisplayPreferences = {
|
||||||
|
linkListDisplay: 'grid',
|
||||||
|
collectionListDisplay: 'list',
|
||||||
|
};
|
||||||
|
|
||||||
|
user.displayPreferences = { ...defaults, ...user.displayPreferences };
|
||||||
|
return user.displayPreferences;
|
||||||
|
}
|
||||||
@@ -1,6 +1,8 @@
|
|||||||
import Collection from '#collections/models/collection';
|
import Collection from '#collections/models/collection';
|
||||||
import AppBaseModel from '#core/models/app_base_model';
|
import AppBaseModel from '#core/models/app_base_model';
|
||||||
import Link from '#links/models/link';
|
import Link from '#links/models/link';
|
||||||
|
import { type DisplayPreferences } from '#shared/types/index';
|
||||||
|
import { ensureDisplayPreferences } from '#user/lib/index';
|
||||||
import type { GoogleToken } from '@adonisjs/ally/types';
|
import type { GoogleToken } from '@adonisjs/ally/types';
|
||||||
import { column, computed, hasMany } from '@adonisjs/lucid/orm';
|
import { column, computed, hasMany } from '@adonisjs/lucid/orm';
|
||||||
import type { HasMany } from '@adonisjs/lucid/types/relations';
|
import type { HasMany } from '@adonisjs/lucid/types/relations';
|
||||||
@@ -51,4 +53,15 @@ export default class User extends AppBaseModel {
|
|||||||
autoUpdate: true,
|
autoUpdate: true,
|
||||||
})
|
})
|
||||||
declare lastSeenAt: DateTime;
|
declare lastSeenAt: DateTime;
|
||||||
|
|
||||||
|
@column({
|
||||||
|
serialize: (value) => {
|
||||||
|
if (typeof value === 'string') {
|
||||||
|
return ensureDisplayPreferences(JSON.parse(value));
|
||||||
|
}
|
||||||
|
return value;
|
||||||
|
},
|
||||||
|
prepare: (value) => JSON.stringify(value),
|
||||||
|
})
|
||||||
|
declare displayPreferences: DisplayPreferences;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1 +1,2 @@
|
|||||||
|
import './user_display_preferences_route.js';
|
||||||
import './user_theme_route.js';
|
import './user_theme_route.js';
|
||||||
|
|||||||
10
app/user/routes/user_display_preferences_route.ts
Normal file
10
app/user/routes/user_display_preferences_route.ts
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
import { middleware } from '#start/kernel';
|
||||||
|
import router from '@adonisjs/core/services/router';
|
||||||
|
|
||||||
|
const DisplayPreferencesController = () =>
|
||||||
|
import('#user/controllers/display_preferences_controller');
|
||||||
|
|
||||||
|
router
|
||||||
|
.post('/user/display-preferences', [DisplayPreferencesController, 'update'])
|
||||||
|
.as('user.update-display-preferences')
|
||||||
|
.middleware([middleware.auth()]);
|
||||||
26
app/user/validators/update_display_preferences.ts
Normal file
26
app/user/validators/update_display_preferences.ts
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
import {
|
||||||
|
COLLECTION_LIST_DISPLAYS,
|
||||||
|
DEFAULT_LIST_DISPLAY_PREFERENCES,
|
||||||
|
LINK_LIST_DISPLAYS,
|
||||||
|
} from '#shared/lib/display_preferences';
|
||||||
|
import vine from '@vinejs/vine';
|
||||||
|
|
||||||
|
export const updateDisplayPreferencesValidator = vine.compile(
|
||||||
|
vine.object({
|
||||||
|
displayPreferences: vine.object({
|
||||||
|
linkListDisplay: vine
|
||||||
|
.enum(LINK_LIST_DISPLAYS)
|
||||||
|
.optional()
|
||||||
|
.transform(
|
||||||
|
(value) => value ?? DEFAULT_LIST_DISPLAY_PREFERENCES.linkListDisplay
|
||||||
|
),
|
||||||
|
collectionListDisplay: vine
|
||||||
|
.enum(COLLECTION_LIST_DISPLAYS)
|
||||||
|
.optional()
|
||||||
|
.transform(
|
||||||
|
(value) =>
|
||||||
|
value ?? DEFAULT_LIST_DISPLAY_PREFERENCES.collectionListDisplay
|
||||||
|
),
|
||||||
|
}),
|
||||||
|
})
|
||||||
|
);
|
||||||
@@ -5,7 +5,7 @@ const allyConfig = defineConfig({
|
|||||||
google: services.google({
|
google: services.google({
|
||||||
clientId: env.get('GOOGLE_CLIENT_ID'),
|
clientId: env.get('GOOGLE_CLIENT_ID'),
|
||||||
clientSecret: env.get('GOOGLE_CLIENT_SECRET'),
|
clientSecret: env.get('GOOGLE_CLIENT_SECRET'),
|
||||||
callbackUrl: env.get('GOOGLE_CLIENT_CALLBACK_URL'),
|
callbackUrl: env.get('APP_URL') + '/auth/callback',
|
||||||
prompt: 'select_account',
|
prompt: 'select_account',
|
||||||
display: 'page',
|
display: 'page',
|
||||||
scopes: ['userinfo.email', 'userinfo.profile'],
|
scopes: ['userinfo.email', 'userinfo.profile'],
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
import { isSSREnableForPage } from '#config/ssr';
|
import { isSSREnableForPage } from '#config/ssr';
|
||||||
|
import env from '#start/env';
|
||||||
import { DEFAULT_USER_THEME, KEY_USER_THEME } from '#user/constants/theme';
|
import { DEFAULT_USER_THEME, KEY_USER_THEME } from '#user/constants/theme';
|
||||||
import logger from '@adonisjs/core/services/logger';
|
import logger from '@adonisjs/core/services/logger';
|
||||||
import { defineConfig } from '@adonisjs/inertia';
|
import { defineConfig } from '@adonisjs/inertia';
|
||||||
@@ -24,6 +25,7 @@ export default defineConfig({
|
|||||||
isAuthenticated: ctx.auth?.isAuthenticated || false,
|
isAuthenticated: ctx.auth?.isAuthenticated || false,
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
|
appUrl: env.get('APP_URL'),
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -0,0 +1,17 @@
|
|||||||
|
import { BaseSchema } from '@adonisjs/lucid/schema';
|
||||||
|
|
||||||
|
export default class extends BaseSchema {
|
||||||
|
protected tableName = 'users';
|
||||||
|
|
||||||
|
async up() {
|
||||||
|
this.schema.alterTable(this.tableName, (table) => {
|
||||||
|
table.jsonb('display_preferences').defaultTo('{}');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
async down() {
|
||||||
|
this.schema.alterTable(this.tableName, (table) => {
|
||||||
|
table.dropColumn('display_preferences');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -20,9 +20,11 @@ createInertiaApp({
|
|||||||
import.meta.glob('../pages/**/*.tsx')
|
import.meta.glob('../pages/**/*.tsx')
|
||||||
);
|
);
|
||||||
|
|
||||||
currentPage.default.layout =
|
if (currentPage?.default) {
|
||||||
currentPage.default.layout ||
|
currentPage.default.layout =
|
||||||
((p: any) => <DefaultLayout children={p} />);
|
currentPage.default.layout ||
|
||||||
|
((p: any) => <DefaultLayout children={p} />);
|
||||||
|
}
|
||||||
|
|
||||||
return currentPage;
|
return currentPage;
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -9,9 +9,13 @@ export default function render(page: any) {
|
|||||||
resolve: (name) => {
|
resolve: (name) => {
|
||||||
const pages = import.meta.glob('../pages/**/*.tsx', { eager: true });
|
const pages = import.meta.glob('../pages/**/*.tsx', { eager: true });
|
||||||
let pageComponent: any = pages[`../pages/${name}.tsx`];
|
let pageComponent: any = pages[`../pages/${name}.tsx`];
|
||||||
pageComponent.default.layout =
|
|
||||||
pageComponent?.default?.layout ||
|
if (pageComponent?.default) {
|
||||||
((pageChildren: any) => <DefaultLayout children={pageChildren} />);
|
pageComponent.default.layout =
|
||||||
|
pageComponent.default.layout ||
|
||||||
|
((pageChildren: any) => <DefaultLayout children={pageChildren} />);
|
||||||
|
}
|
||||||
|
|
||||||
return pageComponent;
|
return pageComponent;
|
||||||
},
|
},
|
||||||
setup: ({ App, props }) => <App {...props} />,
|
setup: ({ App, props }) => <App {...props} />,
|
||||||
|
|||||||
66
inertia/components/common/combo_list/combo_list.tsx
Normal file
66
inertia/components/common/combo_list/combo_list.tsx
Normal file
@@ -0,0 +1,66 @@
|
|||||||
|
import { Combobox, Input, InputBase, useCombobox } from '@mantine/core';
|
||||||
|
import { ComboListItem } from '~/components/common/combo_list/combo_list_item';
|
||||||
|
|
||||||
|
export type ValueWithIcon = {
|
||||||
|
label: string;
|
||||||
|
value: string;
|
||||||
|
icon: React.ReactNode;
|
||||||
|
};
|
||||||
|
|
||||||
|
export function ComboList({
|
||||||
|
selectedValue,
|
||||||
|
values,
|
||||||
|
setValue,
|
||||||
|
}: {
|
||||||
|
selectedValue: string;
|
||||||
|
values: ValueWithIcon[];
|
||||||
|
setValue: (value: string) => void;
|
||||||
|
}) {
|
||||||
|
const combobox = useCombobox({
|
||||||
|
onDropdownClose: () => combobox.resetSelectedOption(),
|
||||||
|
});
|
||||||
|
|
||||||
|
const selectedOption = values.find((item) => item.value === selectedValue);
|
||||||
|
|
||||||
|
const options = values.map((item) => (
|
||||||
|
<Combobox.Option value={item.value} key={item.value}>
|
||||||
|
<ComboListItem emoji={item.icon} label={item.label} />
|
||||||
|
</Combobox.Option>
|
||||||
|
));
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Combobox
|
||||||
|
store={combobox}
|
||||||
|
withinPortal={false}
|
||||||
|
onOptionSubmit={(val) => {
|
||||||
|
setValue(val as string);
|
||||||
|
combobox.closeDropdown();
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<Combobox.Target>
|
||||||
|
<InputBase
|
||||||
|
component="button"
|
||||||
|
type="button"
|
||||||
|
pointer
|
||||||
|
rightSection={<Combobox.Chevron />}
|
||||||
|
onClick={() => combobox.toggleDropdown()}
|
||||||
|
rightSectionPointerEvents="none"
|
||||||
|
multiline
|
||||||
|
>
|
||||||
|
{selectedOption ? (
|
||||||
|
<ComboListItem
|
||||||
|
emoji={selectedOption.icon}
|
||||||
|
label={selectedOption.label}
|
||||||
|
/>
|
||||||
|
) : (
|
||||||
|
<Input.Placeholder>Pick value</Input.Placeholder>
|
||||||
|
)}
|
||||||
|
</InputBase>
|
||||||
|
</Combobox.Target>
|
||||||
|
|
||||||
|
<Combobox.Dropdown>
|
||||||
|
<Combobox.Options>{options}</Combobox.Options>
|
||||||
|
</Combobox.Dropdown>
|
||||||
|
</Combobox>
|
||||||
|
);
|
||||||
|
}
|
||||||
16
inertia/components/common/combo_list/combo_list_item.tsx
Normal file
16
inertia/components/common/combo_list/combo_list_item.tsx
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
import { Group, Text } from '@mantine/core';
|
||||||
|
|
||||||
|
export const ComboListItem = ({
|
||||||
|
emoji,
|
||||||
|
label,
|
||||||
|
}: {
|
||||||
|
emoji: React.ReactNode;
|
||||||
|
label: string;
|
||||||
|
}) => (
|
||||||
|
<Group gap="xs" align="center">
|
||||||
|
{emoji}
|
||||||
|
<Text fz="sm" fw={500}>
|
||||||
|
{label}
|
||||||
|
</Text>
|
||||||
|
</Group>
|
||||||
|
);
|
||||||
@@ -19,6 +19,8 @@ import { useEffect } from 'react';
|
|||||||
import { UserDropdown } from '~/components/common/floating_navbar/user_dropdown';
|
import { UserDropdown } from '~/components/common/floating_navbar/user_dropdown';
|
||||||
import { ExternalLinkUnstyled } from '~/components/common/links/external_link_unstyled';
|
import { ExternalLinkUnstyled } from '~/components/common/links/external_link_unstyled';
|
||||||
import { InternalLink } from '~/components/common/links/internal_link';
|
import { InternalLink } from '~/components/common/links/internal_link';
|
||||||
|
import { LocaleSwitcher } from '~/components/common/locale_switcher';
|
||||||
|
import { ThemeSwitcher } from '~/components/common/theme_switcher';
|
||||||
import { useAuth } from '~/hooks/use_auth';
|
import { useAuth } from '~/hooks/use_auth';
|
||||||
import classes from './floating_navbar.module.css';
|
import classes from './floating_navbar.module.css';
|
||||||
|
|
||||||
@@ -40,9 +42,11 @@ export function FloatingNavbar({ width }: FloatingNavbarProps) {
|
|||||||
|
|
||||||
const links = (
|
const links = (
|
||||||
<>
|
<>
|
||||||
<InternalLink route="dashboard" style={{ fontSize: rem(16) }}>
|
{auth.isAuthenticated && (
|
||||||
Dashboard
|
<InternalLink route="dashboard" style={{ fontSize: rem(16) }}>
|
||||||
</InternalLink>
|
Dashboard
|
||||||
|
</InternalLink>
|
||||||
|
)}
|
||||||
<ExternalLinkUnstyled
|
<ExternalLinkUnstyled
|
||||||
href={PROJECT_REPO_GITHUB_URL}
|
href={PROJECT_REPO_GITHUB_URL}
|
||||||
style={{ fontSize: rem(16) }}
|
style={{ fontSize: rem(16) }}
|
||||||
@@ -74,8 +78,8 @@ export function FloatingNavbar({ width }: FloatingNavbarProps) {
|
|||||||
</Group>
|
</Group>
|
||||||
<Group>
|
<Group>
|
||||||
{!isMobile && <Group>{links}</Group>}
|
{!isMobile && <Group>{links}</Group>}
|
||||||
{isMobile && <Burger opened={opened} onClick={handler.toggle} />}
|
|
||||||
{auth.isAuthenticated && <UserDropdown />}
|
{auth.isAuthenticated && <UserDropdown />}
|
||||||
|
{isMobile && <Burger opened={opened} onClick={handler.toggle} />}
|
||||||
{!auth.isAuthenticated && (
|
{!auth.isAuthenticated && (
|
||||||
<Button
|
<Button
|
||||||
variant="default"
|
variant="default"
|
||||||
@@ -101,6 +105,10 @@ export function FloatingNavbar({ width }: FloatingNavbarProps) {
|
|||||||
<Flex direction="column" gap="md">
|
<Flex direction="column" gap="md">
|
||||||
{links}
|
{links}
|
||||||
</Flex>
|
</Flex>
|
||||||
|
<Group mt="md">
|
||||||
|
<ThemeSwitcher />
|
||||||
|
<LocaleSwitcher />
|
||||||
|
</Group>
|
||||||
</Drawer>
|
</Drawer>
|
||||||
</Box>
|
</Box>
|
||||||
</>
|
</>
|
||||||
|
|||||||
@@ -10,10 +10,6 @@
|
|||||||
var(--mantine-color-dark-8)
|
var(--mantine-color-dark-8)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@media (max-width: 768px) {
|
|
||||||
display: none;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
.userActive {
|
.userActive {
|
||||||
|
|||||||
@@ -1,10 +1,11 @@
|
|||||||
import { Avatar, Group, Menu, Text, UnstyledButton } from '@mantine/core';
|
import { Avatar, Group, Menu, Text, UnstyledButton } from '@mantine/core';
|
||||||
import { useDisclosure } from '@mantine/hooks';
|
import { useDisclosure } from '@mantine/hooks';
|
||||||
|
import { modals } from '@mantine/modals';
|
||||||
import cx from 'clsx';
|
import cx from 'clsx';
|
||||||
import { useTranslation } from 'react-i18next';
|
import { useTranslation } from 'react-i18next';
|
||||||
import { TbChevronDown, TbLogout, TbUser } from 'react-icons/tb';
|
import { TbChevronDown, TbLogout, TbSettings, TbShield } from 'react-icons/tb';
|
||||||
import { InternalLink } from '~/components/common/links/internal_link';
|
|
||||||
import { InternalLinkUnstyled } from '~/components/common/links/internal_link_unstyled';
|
import { InternalLinkUnstyled } from '~/components/common/links/internal_link_unstyled';
|
||||||
|
import { UserPreferences } from '~/components/common/user_preferences/user_preferences';
|
||||||
import { useAuth } from '~/hooks/use_auth';
|
import { useAuth } from '~/hooks/use_auth';
|
||||||
import classes from './user_dropdown.module.css';
|
import classes from './user_dropdown.module.css';
|
||||||
|
|
||||||
@@ -13,6 +14,14 @@ export function UserDropdown() {
|
|||||||
const [userMenuOpened, { open: openUserMenu, close: closeUserMenu }] =
|
const [userMenuOpened, { open: openUserMenu, close: closeUserMenu }] =
|
||||||
useDisclosure(false);
|
useDisclosure(false);
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
|
|
||||||
|
const handlePreferencesModal = () => {
|
||||||
|
modals.open({
|
||||||
|
title: t('user-preferences'),
|
||||||
|
children: <UserPreferences />,
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Menu
|
<Menu
|
||||||
width={260}
|
width={260}
|
||||||
@@ -41,29 +50,31 @@ export function UserDropdown() {
|
|||||||
</UnstyledButton>
|
</UnstyledButton>
|
||||||
</Menu.Target>
|
</Menu.Target>
|
||||||
<Menu.Dropdown>
|
<Menu.Dropdown>
|
||||||
<Menu.Label>{t('common:user')}</Menu.Label>
|
|
||||||
<Menu.Item
|
|
||||||
leftSection={<TbUser size={16} />}
|
|
||||||
component={InternalLinkUnstyled}
|
|
||||||
href={`/user/${auth.user?.fullname}`}
|
|
||||||
color="inherit"
|
|
||||||
>
|
|
||||||
{t('common:profile')}
|
|
||||||
</Menu.Item>
|
|
||||||
|
|
||||||
{auth.user?.isAdmin && (
|
{auth.user?.isAdmin && (
|
||||||
<>
|
<>
|
||||||
<Menu.Label>{t('common:admin')}</Menu.Label>
|
<Menu.Label>{t('common:admin')}</Menu.Label>
|
||||||
<InternalLink href="/admin">{t('common:admin')}</InternalLink>
|
<Menu.Item
|
||||||
|
leftSection={<TbShield size={16} />}
|
||||||
|
component={InternalLinkUnstyled}
|
||||||
|
href="/admin"
|
||||||
|
color="red"
|
||||||
|
>
|
||||||
|
{t('common:manage-users')}
|
||||||
|
</Menu.Item>
|
||||||
</>
|
</>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
<Menu.Label>{t('common:settings')}</Menu.Label>
|
<Menu.Label>{t('common:settings')}</Menu.Label>
|
||||||
|
<Menu.Item
|
||||||
|
leftSection={<TbSettings size={16} />}
|
||||||
|
onClick={handlePreferencesModal}
|
||||||
|
>
|
||||||
|
{t('common:preferences')}
|
||||||
|
</Menu.Item>
|
||||||
<Menu.Item
|
<Menu.Item
|
||||||
leftSection={<TbLogout size={16} />}
|
leftSection={<TbLogout size={16} />}
|
||||||
component={InternalLinkUnstyled}
|
component={InternalLinkUnstyled}
|
||||||
href="/auth/logout"
|
href="/auth/logout"
|
||||||
color="inherit"
|
|
||||||
>
|
>
|
||||||
{t('common:logout')}
|
{t('common:logout')}
|
||||||
</Menu.Item>
|
</Menu.Item>
|
||||||
|
|||||||
@@ -0,0 +1,43 @@
|
|||||||
|
import { LinkListDisplay } from '#shared/types/index';
|
||||||
|
import { Fieldset, Stack, Text } from '@mantine/core';
|
||||||
|
import { useTranslation } from 'react-i18next';
|
||||||
|
import { ComboList } from '~/components/common/combo_list/combo_list';
|
||||||
|
import { CollectionListSelector } from '~/components/dashboard/collection/collection_list_selector';
|
||||||
|
import { useDisplayPreferences } from '~/hooks/use_display_preferences';
|
||||||
|
import { useIsMobile } from '~/hooks/use_is_mobile';
|
||||||
|
import { getLinkListDisplayOptions } from '~/lib/display_preferences';
|
||||||
|
|
||||||
|
export function UserPreferences() {
|
||||||
|
const { displayPreferences, handleUpdateDisplayPreferences } =
|
||||||
|
useDisplayPreferences();
|
||||||
|
const { t } = useTranslation();
|
||||||
|
const isMobile = useIsMobile();
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Fieldset legend={t('preferences')}>
|
||||||
|
{isMobile && (
|
||||||
|
<Text size="xs" c="orange" mb="sm">
|
||||||
|
{t('preferences-description')}
|
||||||
|
</Text>
|
||||||
|
)}
|
||||||
|
<Stack>
|
||||||
|
<Text size="sm" c="dimmed">
|
||||||
|
{t('display-preferences.collection-list-display')}
|
||||||
|
</Text>
|
||||||
|
<CollectionListSelector />
|
||||||
|
<Text size="sm" c="dimmed">
|
||||||
|
{t('display-preferences.link-list-display')}
|
||||||
|
</Text>
|
||||||
|
<ComboList
|
||||||
|
selectedValue={displayPreferences.linkListDisplay}
|
||||||
|
values={getLinkListDisplayOptions()}
|
||||||
|
setValue={(value) =>
|
||||||
|
handleUpdateDisplayPreferences({
|
||||||
|
linkListDisplay: value as LinkListDisplay,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
/>
|
||||||
|
</Stack>
|
||||||
|
</Fieldset>
|
||||||
|
);
|
||||||
|
}
|
||||||
29
inertia/components/dashboard/collection/collection_list.tsx
Normal file
29
inertia/components/dashboard/collection/collection_list.tsx
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
import { ScrollArea, Stack, Text } from '@mantine/core';
|
||||||
|
import { useTranslation } from 'react-i18next';
|
||||||
|
import { CollectionFavoriteItem } from '~/components/dashboard/collection/item/collection_favorite_item';
|
||||||
|
import { CollectionItem } from '~/components/dashboard/collection/item/collection_item';
|
||||||
|
import { useCollections } from '~/hooks/collections/use_collections';
|
||||||
|
import { useIsMobile } from '~/hooks/use_is_mobile';
|
||||||
|
import styles from './list/collection_list.module.css';
|
||||||
|
|
||||||
|
export function CollectionList() {
|
||||||
|
const { t } = useTranslation();
|
||||||
|
const collections = useCollections();
|
||||||
|
const isMobile = useIsMobile();
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Stack gap="xs" h="100%" w={isMobile ? '100%' : '350px'}>
|
||||||
|
<div style={{ display: 'flex', flexDirection: 'column' }}>
|
||||||
|
<Text c="dimmed" ml="md" mb="sm">
|
||||||
|
{t('collection.collections')} • {collections.length}
|
||||||
|
</Text>
|
||||||
|
<ScrollArea className={styles.collectionList}>
|
||||||
|
<CollectionFavoriteItem />
|
||||||
|
{collections.map((collection) => (
|
||||||
|
<CollectionItem collection={collection} />
|
||||||
|
))}
|
||||||
|
</ScrollArea>
|
||||||
|
</div>
|
||||||
|
</Stack>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -0,0 +1,20 @@
|
|||||||
|
import { CollectionListDisplay } from '#shared/types/index';
|
||||||
|
import { ComboList } from '~/components/common/combo_list/combo_list';
|
||||||
|
import { useDisplayPreferences } from '~/hooks/use_display_preferences';
|
||||||
|
import { getCollectionListDisplayOptions } from '~/lib/display_preferences';
|
||||||
|
|
||||||
|
export function CollectionListSelector() {
|
||||||
|
const { displayPreferences, handleUpdateDisplayPreferences } =
|
||||||
|
useDisplayPreferences();
|
||||||
|
return (
|
||||||
|
<ComboList
|
||||||
|
selectedValue={displayPreferences.collectionListDisplay}
|
||||||
|
values={getCollectionListDisplayOptions()}
|
||||||
|
setValue={(value) =>
|
||||||
|
handleUpdateDisplayPreferences({
|
||||||
|
collectionListDisplay: value as CollectionListDisplay,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -0,0 +1,58 @@
|
|||||||
|
import { router } from '@inertiajs/react';
|
||||||
|
import { route } from '@izzyjs/route/client';
|
||||||
|
import { Chip, Group, Text } from '@mantine/core';
|
||||||
|
import { useTranslation } from 'react-i18next';
|
||||||
|
import { useActiveCollection } from '~/hooks/collections/use_active_collection';
|
||||||
|
import { useCollections } from '~/hooks/collections/use_collections';
|
||||||
|
import { appendCollectionId } from '~/lib/navigation';
|
||||||
|
|
||||||
|
export function InlineCollectionList() {
|
||||||
|
const { t } = useTranslation();
|
||||||
|
const collections = useCollections();
|
||||||
|
const activeCollection = useActiveCollection();
|
||||||
|
|
||||||
|
const handleCollectionChange = (value?: string) => {
|
||||||
|
if (value) {
|
||||||
|
router.visit(appendCollectionId(route('dashboard').path, Number(value)));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
router.visit(route('dashboard').path);
|
||||||
|
};
|
||||||
|
|
||||||
|
const fields = [
|
||||||
|
{
|
||||||
|
label: t('common:favorite'),
|
||||||
|
value: 'favorite',
|
||||||
|
},
|
||||||
|
...collections.map((c) => ({
|
||||||
|
label: (
|
||||||
|
<Group gap="xs" wrap="nowrap">
|
||||||
|
<>{c.name}</>
|
||||||
|
<Text size="xs" c="dimmed">
|
||||||
|
{c.links.length}
|
||||||
|
</Text>
|
||||||
|
</Group>
|
||||||
|
),
|
||||||
|
value: c.id.toString(),
|
||||||
|
})),
|
||||||
|
];
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Group gap="xs" w="100%">
|
||||||
|
{fields.map((field) => (
|
||||||
|
<Chip
|
||||||
|
key={field.value}
|
||||||
|
checked={
|
||||||
|
activeCollection?.id
|
||||||
|
? activeCollection.id === Number(field.value)
|
||||||
|
: field.value === 'favorite'
|
||||||
|
}
|
||||||
|
variant="light"
|
||||||
|
onClick={() => handleCollectionChange(field.value)}
|
||||||
|
>
|
||||||
|
{field.label}
|
||||||
|
</Chip>
|
||||||
|
))}
|
||||||
|
</Group>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -0,0 +1,29 @@
|
|||||||
|
import { Link } from '@inertiajs/react';
|
||||||
|
import { route } from '@izzyjs/route/client';
|
||||||
|
import { Text } from '@mantine/core';
|
||||||
|
import { useTranslation } from 'react-i18next';
|
||||||
|
import { TbStar, TbStarFilled } from 'react-icons/tb';
|
||||||
|
import { useActiveCollection } from '~/hooks/collections/use_active_collection';
|
||||||
|
import classes from './collection_item.module.css';
|
||||||
|
|
||||||
|
export function CollectionFavoriteItem() {
|
||||||
|
const { t } = useTranslation();
|
||||||
|
const activeCollection = useActiveCollection();
|
||||||
|
const isActiveCollection = !activeCollection?.id;
|
||||||
|
const FolderIcon = isActiveCollection ? TbStarFilled : TbStar;
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Link
|
||||||
|
className={classes.link}
|
||||||
|
data-active={isActiveCollection || undefined}
|
||||||
|
href={route('dashboard').path}
|
||||||
|
key="favorite"
|
||||||
|
title="Favorite"
|
||||||
|
>
|
||||||
|
<FolderIcon className={classes.linkIcon} />
|
||||||
|
<Text maw={'200px'} style={{ wordBreak: 'break-all' }}>
|
||||||
|
{t('favorite')}
|
||||||
|
</Text>
|
||||||
|
</Link>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -3,18 +3,18 @@ import { route } from '@izzyjs/route/client';
|
|||||||
import { Text } from '@mantine/core';
|
import { Text } from '@mantine/core';
|
||||||
import { useEffect, useRef } from 'react';
|
import { useEffect, useRef } from 'react';
|
||||||
import { AiFillFolderOpen, AiOutlineFolder } from 'react-icons/ai';
|
import { AiFillFolderOpen, AiOutlineFolder } from 'react-icons/ai';
|
||||||
|
import { useActiveCollection } from '~/hooks/collections/use_active_collection';
|
||||||
import { appendCollectionId } from '~/lib/navigation';
|
import { appendCollectionId } from '~/lib/navigation';
|
||||||
import { useActiveCollection } from '~/stores/collection_store';
|
|
||||||
import { CollectionWithLinks } from '~/types/app';
|
import { CollectionWithLinks } from '~/types/app';
|
||||||
import classes from './collection_item.module.css';
|
import classes from './collection_item.module.css';
|
||||||
|
|
||||||
export default function CollectionItem({
|
interface CollectionItemProps {
|
||||||
collection,
|
|
||||||
}: {
|
|
||||||
collection: CollectionWithLinks;
|
collection: CollectionWithLinks;
|
||||||
}) {
|
}
|
||||||
|
|
||||||
|
export function CollectionItem({ collection }: CollectionItemProps) {
|
||||||
const itemRef = useRef<HTMLAnchorElement>(null);
|
const itemRef = useRef<HTMLAnchorElement>(null);
|
||||||
const { activeCollection } = useActiveCollection();
|
const activeCollection = useActiveCollection();
|
||||||
const isActiveCollection = collection.id === activeCollection?.id;
|
const isActiveCollection = collection.id === activeCollection?.id;
|
||||||
const FolderIcon = isActiveCollection ? AiFillFolderOpen : AiOutlineFolder;
|
const FolderIcon = isActiveCollection ? AiFillFolderOpen : AiOutlineFolder;
|
||||||
|
|
||||||
@@ -34,7 +34,10 @@ export default function CollectionItem({
|
|||||||
title={collection.name}
|
title={collection.name}
|
||||||
>
|
>
|
||||||
<FolderIcon className={classes.linkIcon} />
|
<FolderIcon className={classes.linkIcon} />
|
||||||
<Text lineClamp={1} maw={'200px'} style={{ wordBreak: 'break-all' }}>
|
<Text
|
||||||
|
lineClamp={1}
|
||||||
|
style={{ wordBreak: 'break-all', whiteSpace: 'pre-line' }}
|
||||||
|
>
|
||||||
{collection.name}
|
{collection.name}
|
||||||
</Text>
|
</Text>
|
||||||
</Link>
|
</Link>
|
||||||
|
|||||||
@@ -1,50 +1,12 @@
|
|||||||
import { router } from '@inertiajs/react';
|
|
||||||
import { route } from '@izzyjs/route/client';
|
|
||||||
import { Box, ScrollArea, Text } from '@mantine/core';
|
import { Box, ScrollArea, Text } from '@mantine/core';
|
||||||
import { useTranslation } from 'react-i18next';
|
import { useTranslation } from 'react-i18next';
|
||||||
import CollectionItem from '~/components/dashboard/collection/item/collection_item';
|
import CollectionItem from '~/components/dashboard/collection/item/collection_item';
|
||||||
import useShortcut from '~/hooks/use_shortcut';
|
import { useCollections } from '~/hooks/collections/use_collections';
|
||||||
import { appendCollectionId } from '~/lib/navigation';
|
|
||||||
import { useActiveCollection, useCollections } from '~/stores/collection_store';
|
|
||||||
import styles from './collection_list.module.css';
|
import styles from './collection_list.module.css';
|
||||||
|
|
||||||
export default function CollectionList() {
|
export default function CollectionList() {
|
||||||
const { t } = useTranslation('common');
|
const { t } = useTranslation('common');
|
||||||
const { collections } = useCollections();
|
const collections = useCollections();
|
||||||
const { activeCollection, setActiveCollection } = useActiveCollection();
|
|
||||||
|
|
||||||
const replaceUrl = (collectionId: number) =>
|
|
||||||
router.get(appendCollectionId(route('dashboard').path, collectionId));
|
|
||||||
|
|
||||||
const goToPreviousCollection = () => {
|
|
||||||
const currentCategoryIndex = collections.findIndex(
|
|
||||||
({ id }) => id === activeCollection?.id
|
|
||||||
);
|
|
||||||
if (currentCategoryIndex === -1 || currentCategoryIndex === 0) return;
|
|
||||||
|
|
||||||
const collection = collections[currentCategoryIndex - 1];
|
|
||||||
replaceUrl(collection.id);
|
|
||||||
setActiveCollection(collection);
|
|
||||||
};
|
|
||||||
|
|
||||||
const goToNextCollection = () => {
|
|
||||||
const currentCategoryIndex = collections.findIndex(
|
|
||||||
({ id }) => id === activeCollection?.id
|
|
||||||
);
|
|
||||||
if (
|
|
||||||
currentCategoryIndex === -1 ||
|
|
||||||
currentCategoryIndex === collections.length - 1
|
|
||||||
)
|
|
||||||
return;
|
|
||||||
|
|
||||||
const collection = collections[currentCategoryIndex + 1];
|
|
||||||
replaceUrl(collection.id);
|
|
||||||
setActiveCollection(collection);
|
|
||||||
};
|
|
||||||
|
|
||||||
useShortcut('ARROW_UP', goToPreviousCollection);
|
|
||||||
useShortcut('ARROW_DOWN', goToNextCollection);
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Box className={styles.sideMenu}>
|
<Box className={styles.sideMenu}>
|
||||||
<Box className={styles.listContainer}>
|
<Box className={styles.listContainer}>
|
||||||
|
|||||||
@@ -0,0 +1,50 @@
|
|||||||
|
import { Button, Drawer, Portal, rem, Text } from '@mantine/core';
|
||||||
|
import { useDisclosure, useHeadroom } from '@mantine/hooks';
|
||||||
|
import { useTranslation } from 'react-i18next';
|
||||||
|
import { TbFolder } from 'react-icons/tb';
|
||||||
|
import { CollectionFavoriteItem } from '~/components/dashboard/collection/item/collection_favorite_item';
|
||||||
|
import { useCollections } from '~/hooks/collections/use_collections';
|
||||||
|
import { CollectionItem } from './item/collection_item';
|
||||||
|
|
||||||
|
export function MobileCollectionList() {
|
||||||
|
const { t } = useTranslation();
|
||||||
|
const [opened, handler] = useDisclosure();
|
||||||
|
const collections = useCollections();
|
||||||
|
const pinned = useHeadroom({ fixedAt: 0 });
|
||||||
|
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<Drawer
|
||||||
|
opened={opened}
|
||||||
|
onClose={handler.close}
|
||||||
|
title={t('collection.collections', { count: collections.length })}
|
||||||
|
>
|
||||||
|
<CollectionFavoriteItem />
|
||||||
|
{collections.map((collection) => (
|
||||||
|
<CollectionItem collection={collection} />
|
||||||
|
))}
|
||||||
|
</Drawer>
|
||||||
|
<Portal>
|
||||||
|
<Button
|
||||||
|
onClick={handler.open}
|
||||||
|
variant="outline"
|
||||||
|
size="xs"
|
||||||
|
style={{
|
||||||
|
position: 'fixed',
|
||||||
|
left: '50%',
|
||||||
|
bottom: pinned ? rem(16) : rem(-100),
|
||||||
|
width: `calc(100% - ${rem(16)} * 2)`,
|
||||||
|
backgroundColor: 'var(--mantine-color-body)',
|
||||||
|
transition: 'all 0.2s ease-in-out',
|
||||||
|
transform: 'translateX(-50%)',
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<TbFolder size={18} />
|
||||||
|
<Text ml={4}>
|
||||||
|
{t('collection.collections', { count: collections.length })}
|
||||||
|
</Text>
|
||||||
|
</Button>
|
||||||
|
</Portal>
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -0,0 +1,32 @@
|
|||||||
|
import { Badge, CopyButton } from '@mantine/core';
|
||||||
|
import { t } from 'i18next';
|
||||||
|
import { TbCopy } from 'react-icons/tb';
|
||||||
|
import { useActiveCollection } from '~/hooks/collections/use_active_collection';
|
||||||
|
import { useAppUrl } from '~/hooks/use_app_url';
|
||||||
|
|
||||||
|
const COPY_TIMEOUT = 3_000;
|
||||||
|
|
||||||
|
export function SharedCollectionCopyLink() {
|
||||||
|
const appUrl = useAppUrl();
|
||||||
|
const activeCollection = useActiveCollection();
|
||||||
|
|
||||||
|
if (!activeCollection) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
const copyUrl = `${appUrl}/shared/${activeCollection.id}`;
|
||||||
|
return (
|
||||||
|
<CopyButton value={copyUrl} timeout={COPY_TIMEOUT}>
|
||||||
|
{({ copied, copy }) => (
|
||||||
|
<Badge
|
||||||
|
variant={copied ? 'filled' : 'light'}
|
||||||
|
onClick={copy}
|
||||||
|
style={{ cursor: 'pointer' }}
|
||||||
|
>
|
||||||
|
{copied ? t('success-copy') : t('visibility.public')}
|
||||||
|
{!copied && <TbCopy style={{ marginLeft: 4 }} />}
|
||||||
|
</Badge>
|
||||||
|
)}
|
||||||
|
</CopyButton>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -16,8 +16,8 @@ import { GoPencil } from 'react-icons/go';
|
|||||||
import { IoIosAddCircleOutline } from 'react-icons/io';
|
import { IoIosAddCircleOutline } from 'react-icons/io';
|
||||||
import { IoTrashOutline } from 'react-icons/io5';
|
import { IoTrashOutline } from 'react-icons/io5';
|
||||||
import { ShareCollection } from '~/components/share/share_collection';
|
import { ShareCollection } from '~/components/share/share_collection';
|
||||||
|
import { useActiveCollection } from '~/hooks/collections/use_active_collection';
|
||||||
import { appendCollectionId } from '~/lib/navigation';
|
import { appendCollectionId } from '~/lib/navigation';
|
||||||
import { useActiveCollection } from '~/stores/collection_store';
|
|
||||||
import { Visibility } from '~/types/app';
|
import { Visibility } from '~/types/app';
|
||||||
|
|
||||||
interface DashboardHeaderProps {
|
interface DashboardHeaderProps {
|
||||||
@@ -32,7 +32,7 @@ interface DashboardHeaderProps {
|
|||||||
}
|
}
|
||||||
export function DashboardHeader({ navbar, aside }: DashboardHeaderProps) {
|
export function DashboardHeader({ navbar, aside }: DashboardHeaderProps) {
|
||||||
const { t } = useTranslation('common');
|
const { t } = useTranslation('common');
|
||||||
const { activeCollection } = useActiveCollection();
|
const activeCollection = useActiveCollection();
|
||||||
return (
|
return (
|
||||||
<AppShell.Header style={{ display: 'flex', alignItems: 'center' }}>
|
<AppShell.Header style={{ display: 'flex', alignItems: 'center' }}>
|
||||||
<Group justify="space-between" px="md" flex={1} wrap="nowrap">
|
<Group justify="space-between" px="md" flex={1} wrap="nowrap">
|
||||||
|
|||||||
@@ -20,10 +20,10 @@ import { PiGearLight } from 'react-icons/pi';
|
|||||||
import { UserCard } from '~/components/common/user_card';
|
import { UserCard } from '~/components/common/user_card';
|
||||||
import { FavoriteList } from '~/components/dashboard/favorite/favorite_list';
|
import { FavoriteList } from '~/components/dashboard/favorite/favorite_list';
|
||||||
import { SearchSpotlight } from '~/components/search/search';
|
import { SearchSpotlight } from '~/components/search/search';
|
||||||
|
import { useActiveCollection } from '~/hooks/collections/use_active_collection';
|
||||||
import { useAuth } from '~/hooks/use_auth';
|
import { useAuth } from '~/hooks/use_auth';
|
||||||
import useShortcut from '~/hooks/use_shortcut';
|
import useShortcut from '~/hooks/use_shortcut';
|
||||||
import { appendCollectionId } from '~/lib/navigation';
|
import { appendCollectionId } from '~/lib/navigation';
|
||||||
import { useActiveCollection } from '~/stores/collection_store';
|
|
||||||
import { useGlobalHotkeysStore } from '~/stores/global_hotkeys_store';
|
import { useGlobalHotkeysStore } from '~/stores/global_hotkeys_store';
|
||||||
|
|
||||||
interface DashboardNavbarProps {
|
interface DashboardNavbarProps {
|
||||||
@@ -34,7 +34,7 @@ export function DashboardNavbar({ isOpen, toggle }: DashboardNavbarProps) {
|
|||||||
const { t } = useTranslation('common');
|
const { t } = useTranslation('common');
|
||||||
const { isAuthenticated, user } = useAuth();
|
const { isAuthenticated, user } = useAuth();
|
||||||
|
|
||||||
const { activeCollection } = useActiveCollection();
|
const activeCollection = useActiveCollection();
|
||||||
const { globalHotkeysEnabled, setGlobalHotkeysEnabled } =
|
const { globalHotkeysEnabled, setGlobalHotkeysEnabled } =
|
||||||
useGlobalHotkeysStore();
|
useGlobalHotkeysStore();
|
||||||
|
|
||||||
|
|||||||
@@ -1,13 +1,13 @@
|
|||||||
import { Flex, Group, Stack, Text } from '@mantine/core';
|
import { Flex, Group, Stack, Text } from '@mantine/core';
|
||||||
import { useTranslation } from 'react-i18next';
|
import { useTranslation } from 'react-i18next';
|
||||||
import { FavoriteItem } from '~/components/dashboard/favorite/item/favorite_item';
|
import { FavoriteItem } from '~/components/dashboard/favorite/item/favorite_item';
|
||||||
import { useFavorites } from '~/stores/collection_store';
|
import { useFavoriteLinks } from '~/hooks/collections/use_favorite_links';
|
||||||
|
|
||||||
export function FavoriteList() {
|
export function FavoriteList() {
|
||||||
const { t } = useTranslation('common');
|
const { t } = useTranslation('common');
|
||||||
const { favorites } = useFavorites();
|
const favoriteLinks = useFavoriteLinks();
|
||||||
|
|
||||||
if (favorites.length === 0) {
|
if (favoriteLinks.length === 0) {
|
||||||
return (
|
return (
|
||||||
<Group justify="center">
|
<Group justify="center">
|
||||||
<Text c="dimmed" size="sm" mt="sm">
|
<Text c="dimmed" size="sm" mt="sm">
|
||||||
@@ -20,10 +20,10 @@ export function FavoriteList() {
|
|||||||
return (
|
return (
|
||||||
<Flex direction="column">
|
<Flex direction="column">
|
||||||
<Text c="dimmed" mt="xs" ml="md" mb={4}>
|
<Text c="dimmed" mt="xs" ml="md" mb={4}>
|
||||||
{t('favorite')} • {favorites.length}
|
{t('favorite')} • {favoriteLinks.length}
|
||||||
</Text>
|
</Text>
|
||||||
<Stack gap={4}>
|
<Stack gap={4}>
|
||||||
{favorites.map((link) => (
|
{favoriteLinks.map((link) => (
|
||||||
<FavoriteItem link={link} key={link.id} />
|
<FavoriteItem link={link} key={link.id} />
|
||||||
))}
|
))}
|
||||||
</Stack>
|
</Stack>
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { Link as InertiaLink } from '@inertiajs/react';
|
import { Link as InertiaLink, router } from '@inertiajs/react';
|
||||||
import { route } from '@izzyjs/route/client';
|
import { route } from '@izzyjs/route/client';
|
||||||
import { ActionIcon, Menu } from '@mantine/core';
|
import { ActionIcon, Menu } from '@mantine/core';
|
||||||
import { MouseEvent } from 'react';
|
import { MouseEvent } from 'react';
|
||||||
@@ -10,7 +10,6 @@ import { IoTrashOutline } from 'react-icons/io5';
|
|||||||
import { MdFavorite, MdFavoriteBorder } from 'react-icons/md';
|
import { MdFavorite, MdFavoriteBorder } from 'react-icons/md';
|
||||||
import { onFavorite } from '~/lib/favorite';
|
import { onFavorite } from '~/lib/favorite';
|
||||||
import { appendCollectionId, appendLinkId } from '~/lib/navigation';
|
import { appendCollectionId, appendLinkId } from '~/lib/navigation';
|
||||||
import { useFavorites } from '~/stores/collection_store';
|
|
||||||
import { Link, PublicLink } from '~/types/app';
|
import { Link, PublicLink } from '~/types/app';
|
||||||
|
|
||||||
interface LinksControlsProps {
|
interface LinksControlsProps {
|
||||||
@@ -21,10 +20,14 @@ export default function LinkControls({
|
|||||||
link,
|
link,
|
||||||
showGoToCollection = false,
|
showGoToCollection = false,
|
||||||
}: LinksControlsProps) {
|
}: LinksControlsProps) {
|
||||||
const { toggleFavorite } = useFavorites();
|
|
||||||
const { t } = useTranslation('common');
|
const { t } = useTranslation('common');
|
||||||
|
|
||||||
const onFavoriteCallback = () => toggleFavorite(link.id);
|
const onFavoriteCallback = () => {
|
||||||
|
const path = route('link.toggle-favorite', {
|
||||||
|
params: { id: link.id.toString() },
|
||||||
|
}).path;
|
||||||
|
router.put(path);
|
||||||
|
};
|
||||||
const handleStopPropagation = (event: MouseEvent<HTMLButtonElement>) =>
|
const handleStopPropagation = (event: MouseEvent<HTMLButtonElement>) =>
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
|
|
||||||
|
|||||||
@@ -28,7 +28,13 @@ export function LinkItem({ link, hideMenu: hideMenu = false }: LinkItemProps) {
|
|||||||
{!hideMenu && <LinkControls link={link} />}
|
{!hideMenu && <LinkControls link={link} />}
|
||||||
</Group>
|
</Group>
|
||||||
{description && (
|
{description && (
|
||||||
<Text c="dimmed" size="sm" mt="xs" lineClamp={3}>
|
<Text
|
||||||
|
c="dimmed"
|
||||||
|
size="sm"
|
||||||
|
mt="xs"
|
||||||
|
lineClamp={3}
|
||||||
|
style={{ wordBreak: 'break-word', whiteSpace: 'pre-line' }}
|
||||||
|
>
|
||||||
{description}
|
{description}
|
||||||
</Text>
|
</Text>
|
||||||
)}
|
)}
|
||||||
|
|||||||
@@ -1,24 +1,48 @@
|
|||||||
import { Stack } from '@mantine/core';
|
import { DisplayPreferences } from '#shared/types/index';
|
||||||
|
import { SimpleGrid, Stack, StyleProp } from '@mantine/core';
|
||||||
import { LinkItem } from '~/components/dashboard/link/item/link_item';
|
import { LinkItem } from '~/components/dashboard/link/item/link_item';
|
||||||
import { NoLink } from '~/components/dashboard/link/no_link/no_link';
|
import { NoLink } from '~/components/dashboard/link/no_link/no_link';
|
||||||
import { useActiveCollection } from '~/stores/collection_store';
|
import { useActiveCollection } from '~/hooks/collections/use_active_collection';
|
||||||
|
import { useFavoriteLinks } from '~/hooks/collections/use_favorite_links';
|
||||||
|
import { useDisplayPreferences } from '~/hooks/use_display_preferences';
|
||||||
|
|
||||||
export interface LinkListProps {
|
export interface LinkListProps {
|
||||||
hideMenu?: boolean;
|
hideMenu?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function LinkList({ hideMenu = false }: LinkListProps) {
|
export function LinkList({ hideMenu = false }: LinkListProps) {
|
||||||
const { activeCollection } = useActiveCollection();
|
const activeCollection = useActiveCollection();
|
||||||
|
const favoriteLinks = useFavoriteLinks();
|
||||||
|
const { displayPreferences } = useDisplayPreferences();
|
||||||
|
|
||||||
if (!activeCollection?.links || activeCollection.links.length === 0) {
|
const links = activeCollection?.links || favoriteLinks;
|
||||||
|
|
||||||
|
if (links.length === 0) {
|
||||||
return <NoLink hideMenu={hideMenu} />;
|
return <NoLink hideMenu={hideMenu} />;
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Stack gap="xs">
|
<Stack gap="xs">
|
||||||
{activeCollection?.links.map((link) => (
|
<SimpleGrid cols={getColsByView(displayPreferences)} spacing="xs">
|
||||||
<LinkItem link={link} key={link.id} hideMenu={hideMenu} />
|
{links.map((link) => (
|
||||||
))}
|
<LinkItem link={link} key={link.id} hideMenu={hideMenu} />
|
||||||
|
))}
|
||||||
|
</SimpleGrid>
|
||||||
</Stack>
|
</Stack>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function getColsByView(
|
||||||
|
displayPreferences: DisplayPreferences
|
||||||
|
): StyleProp<number> {
|
||||||
|
const { linkListDisplay } = displayPreferences;
|
||||||
|
|
||||||
|
if (linkListDisplay === 'grid') {
|
||||||
|
return {
|
||||||
|
sm: 1,
|
||||||
|
md: 2,
|
||||||
|
lg: 3,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|||||||
@@ -3,30 +3,36 @@ import { route } from '@izzyjs/route/client';
|
|||||||
import { Anchor, Box, Text } from '@mantine/core';
|
import { Anchor, Box, Text } from '@mantine/core';
|
||||||
import { useTranslation } from 'react-i18next';
|
import { useTranslation } from 'react-i18next';
|
||||||
import type { LinkListProps } from '~/components/dashboard/link/list/link_list';
|
import type { LinkListProps } from '~/components/dashboard/link/list/link_list';
|
||||||
|
import { useActiveCollection } from '~/hooks/collections/use_active_collection';
|
||||||
import { appendCollectionId } from '~/lib/navigation';
|
import { appendCollectionId } from '~/lib/navigation';
|
||||||
import { useActiveCollection } from '~/stores/collection_store';
|
|
||||||
import styles from './no_link.module.css';
|
import styles from './no_link.module.css';
|
||||||
|
|
||||||
interface NoLinkProps extends LinkListProps {}
|
interface NoLinkProps extends LinkListProps {}
|
||||||
|
|
||||||
export function NoLink({ hideMenu }: NoLinkProps) {
|
export function NoLink({ hideMenu }: NoLinkProps) {
|
||||||
const { t } = useTranslation('common');
|
const { t } = useTranslation('common');
|
||||||
const { activeCollection } = useActiveCollection();
|
const activeCollection = useActiveCollection();
|
||||||
|
const isFavorite = !activeCollection?.id;
|
||||||
|
|
||||||
|
const noLinkForCollection = t(
|
||||||
|
'home:no-link',
|
||||||
|
{ name: activeCollection?.name ?? '' } as any,
|
||||||
|
{
|
||||||
|
interpolation: { escapeValue: false },
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
const noLinkForFavorite = t('home:no-link-favorite');
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Box className={styles.noCollection} p="xl">
|
<Box className={styles.noCollection} p="xl">
|
||||||
<Text
|
<Text
|
||||||
className={styles.text}
|
className={styles.text}
|
||||||
dangerouslySetInnerHTML={{
|
dangerouslySetInnerHTML={{
|
||||||
__html: t(
|
__html: isFavorite ? noLinkForFavorite : noLinkForCollection,
|
||||||
'home:no-link',
|
|
||||||
{ name: activeCollection?.name ?? '' } as any,
|
|
||||||
{
|
|
||||||
interpolation: { escapeValue: false },
|
|
||||||
}
|
|
||||||
),
|
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
{!hideMenu && (
|
{!hideMenu && !isFavorite && (
|
||||||
<Anchor
|
<Anchor
|
||||||
component={Link}
|
component={Link}
|
||||||
href={appendCollectionId(
|
href={appendCollectionId(
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ import { Box, Group, SegmentedControl, Text, TextInput } from '@mantine/core';
|
|||||||
import { FormEvent } from 'react';
|
import { FormEvent } from 'react';
|
||||||
import { useTranslation } from 'react-i18next';
|
import { useTranslation } from 'react-i18next';
|
||||||
import BackToDashboard from '~/components/common/navigation/back_to_dashboard';
|
import BackToDashboard from '~/components/common/navigation/back_to_dashboard';
|
||||||
|
import useSearchParam from '~/hooks/use_search_param';
|
||||||
import { FormLayout, FormLayoutProps } from '~/layouts/form_layout';
|
import { FormLayout, FormLayoutProps } from '~/layouts/form_layout';
|
||||||
import { Visibility } from '~/types/app';
|
import { Visibility } from '~/types/app';
|
||||||
|
|
||||||
@@ -29,6 +30,7 @@ export default function MantineFormCollection({
|
|||||||
...props
|
...props
|
||||||
}: FormCollectionProps) {
|
}: FormCollectionProps) {
|
||||||
const { t } = useTranslation('common');
|
const { t } = useTranslation('common');
|
||||||
|
const collectionId = Number(useSearchParam('collectionId'));
|
||||||
|
|
||||||
const onSubmit = (event: FormEvent<HTMLFormElement>) => {
|
const onSubmit = (event: FormEvent<HTMLFormElement>) => {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
@@ -36,7 +38,7 @@ export default function MantineFormCollection({
|
|||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<FormLayout handleSubmit={onSubmit} {...props}>
|
<FormLayout handleSubmit={onSubmit} collectionId={collectionId} {...props}>
|
||||||
<BackToDashboard disabled={props.disableHomeLink}>
|
<BackToDashboard disabled={props.disableHomeLink}>
|
||||||
<TextInput
|
<TextInput
|
||||||
label={t('form.name')}
|
label={t('form.name')}
|
||||||
|
|||||||
@@ -2,15 +2,15 @@ import { ActionIcon, Anchor, CopyButton, Popover, Text } from '@mantine/core';
|
|||||||
import { useTranslation } from 'react-i18next';
|
import { useTranslation } from 'react-i18next';
|
||||||
import { TbShare3 } from 'react-icons/tb';
|
import { TbShare3 } from 'react-icons/tb';
|
||||||
import { Fragment } from 'react/jsx-runtime';
|
import { Fragment } from 'react/jsx-runtime';
|
||||||
|
import { useActiveCollection } from '~/hooks/collections/use_active_collection';
|
||||||
import { generateShareUrl } from '~/lib/navigation';
|
import { generateShareUrl } from '~/lib/navigation';
|
||||||
import { useActiveCollection } from '~/stores/collection_store';
|
|
||||||
import { Visibility } from '~/types/app';
|
import { Visibility } from '~/types/app';
|
||||||
|
|
||||||
const COPY_SUCCESS_TIMEOUT = 2_000;
|
const COPY_SUCCESS_TIMEOUT = 2_000;
|
||||||
|
|
||||||
export function ShareCollection() {
|
export function ShareCollection() {
|
||||||
const { t } = useTranslation('common');
|
const { t } = useTranslation('common');
|
||||||
const { activeCollection } = useActiveCollection();
|
const activeCollection = useActiveCollection();
|
||||||
if (
|
if (
|
||||||
activeCollection?.visibility !== Visibility.PUBLIC ||
|
activeCollection?.visibility !== Visibility.PUBLIC ||
|
||||||
typeof window === 'undefined'
|
typeof window === 'undefined'
|
||||||
|
|||||||
25
inertia/hooks/collections/use_active_collection.tsx
Normal file
25
inertia/hooks/collections/use_active_collection.tsx
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
import { PageProps } from '@adonisjs/inertia/types';
|
||||||
|
import { usePage } from '@inertiajs/react';
|
||||||
|
import { CollectionWithLinks } from '~/types/app';
|
||||||
|
|
||||||
|
interface UseActiveCollectionProps {
|
||||||
|
activeCollection?: CollectionWithLinks;
|
||||||
|
}
|
||||||
|
|
||||||
|
export const useActiveCollection = () => {
|
||||||
|
const { props } = usePage<PageProps & UseActiveCollectionProps>();
|
||||||
|
return props.activeCollection;
|
||||||
|
};
|
||||||
|
|
||||||
|
export type WithActiveCollectionProps = {
|
||||||
|
activeCollection?: CollectionWithLinks;
|
||||||
|
};
|
||||||
|
|
||||||
|
export const withActiveCollection = (
|
||||||
|
Component: React.ComponentType<WithActiveCollectionProps>
|
||||||
|
) => {
|
||||||
|
return (props: WithActiveCollectionProps) => {
|
||||||
|
const activeCollection = useActiveCollection();
|
||||||
|
return <Component {...props} activeCollection={activeCollection} />;
|
||||||
|
};
|
||||||
|
};
|
||||||
25
inertia/hooks/collections/use_collections.tsx
Normal file
25
inertia/hooks/collections/use_collections.tsx
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
import { PageProps } from '@adonisjs/inertia/types';
|
||||||
|
import { usePage } from '@inertiajs/react';
|
||||||
|
import { CollectionWithLinks } from '~/types/app';
|
||||||
|
|
||||||
|
interface UseCollectionsProps {
|
||||||
|
collections: CollectionWithLinks[];
|
||||||
|
}
|
||||||
|
|
||||||
|
export const useCollections = () => {
|
||||||
|
const { props } = usePage<PageProps & UseCollectionsProps>();
|
||||||
|
return props.collections;
|
||||||
|
};
|
||||||
|
|
||||||
|
export type WithCollectionsProps = {
|
||||||
|
collections: CollectionWithLinks[];
|
||||||
|
};
|
||||||
|
|
||||||
|
export const withCollections = <T extends object>(
|
||||||
|
Component: React.ComponentType<T & WithCollectionsProps>
|
||||||
|
): React.ComponentType<Omit<T, 'collections'>> => {
|
||||||
|
return (props: Omit<T, 'collections'>) => {
|
||||||
|
const collections = useCollections();
|
||||||
|
return <Component {...(props as T)} collections={collections} />;
|
||||||
|
};
|
||||||
|
};
|
||||||
12
inertia/hooks/collections/use_favorite_links.tsx
Normal file
12
inertia/hooks/collections/use_favorite_links.tsx
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
import { PageProps } from '@adonisjs/inertia/types';
|
||||||
|
import { usePage } from '@inertiajs/react';
|
||||||
|
import { LinkWithCollection } from '~/types/app';
|
||||||
|
|
||||||
|
interface UseFavoriteLinksProps {
|
||||||
|
favoriteLinks: LinkWithCollection[];
|
||||||
|
}
|
||||||
|
|
||||||
|
export const useFavoriteLinks = () => {
|
||||||
|
const { props } = usePage<PageProps & UseFavoriteLinksProps>();
|
||||||
|
return props.favoriteLinks;
|
||||||
|
};
|
||||||
7
inertia/hooks/use_app_url.tsx
Normal file
7
inertia/hooks/use_app_url.tsx
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
import { PageProps } from '@adonisjs/inertia/types';
|
||||||
|
import { usePage } from '@inertiajs/react';
|
||||||
|
|
||||||
|
export function useAppUrl() {
|
||||||
|
const { props } = usePage<PageProps & { appUrl: string }>();
|
||||||
|
return props.appUrl;
|
||||||
|
}
|
||||||
@@ -1,9 +0,0 @@
|
|||||||
import { useEffect } from 'react';
|
|
||||||
|
|
||||||
export const useDisableOverflow = () =>
|
|
||||||
useEffect(() => {
|
|
||||||
document.body.style.overflow = 'hidden';
|
|
||||||
return () => {
|
|
||||||
document.body.style.overflow = 'auto';
|
|
||||||
};
|
|
||||||
}, []);
|
|
||||||
26
inertia/hooks/use_display_preferences.tsx
Normal file
26
inertia/hooks/use_display_preferences.tsx
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
import { getDisplayPreferences } from '#shared/lib/display_preferences';
|
||||||
|
import { DisplayPreferences } from '#shared/types/index';
|
||||||
|
import { router } from '@inertiajs/react';
|
||||||
|
import { route } from '@izzyjs/route/client';
|
||||||
|
import { useAuth } from '~/hooks/use_auth';
|
||||||
|
|
||||||
|
export const useDisplayPreferences = () => {
|
||||||
|
const { user } = useAuth();
|
||||||
|
const displayPreferences = getDisplayPreferences(user?.displayPreferences);
|
||||||
|
|
||||||
|
const handleUpdateDisplayPreferences = (
|
||||||
|
displayPreferences: Partial<DisplayPreferences>
|
||||||
|
) => {
|
||||||
|
router.visit(route('user.update-display-preferences').path, {
|
||||||
|
method: 'post',
|
||||||
|
data: {
|
||||||
|
displayPreferences,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
return {
|
||||||
|
displayPreferences,
|
||||||
|
handleUpdateDisplayPreferences,
|
||||||
|
};
|
||||||
|
};
|
||||||
3
inertia/hooks/use_is_mobile.tsx
Normal file
3
inertia/hooks/use_is_mobile.tsx
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
import { useMediaQuery } from '@mantine/hooks';
|
||||||
|
|
||||||
|
export const useIsMobile = () => useMediaQuery('(max-width: 768px)');
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
import KEYS from '#core/constants/keys';
|
import KEYS from '#core/constants/keys';
|
||||||
import { useHotkeys } from 'react-hotkeys-hook';
|
import { useHotkeys } from '@mantine/hooks';
|
||||||
import { useGlobalHotkeysStore } from '~/stores/global_hotkeys_store';
|
import { useGlobalHotkeysStore } from '~/stores/global_hotkeys_store';
|
||||||
|
|
||||||
type ShortcutOptions = {
|
type ShortcutOptions = {
|
||||||
@@ -16,15 +16,12 @@ export default function useShortcut(
|
|||||||
}
|
}
|
||||||
) {
|
) {
|
||||||
const { globalHotkeysEnabled } = useGlobalHotkeysStore();
|
const { globalHotkeysEnabled } = useGlobalHotkeysStore();
|
||||||
|
const isEnabled = disableGlobalCheck
|
||||||
|
? enabled
|
||||||
|
: enabled && globalHotkeysEnabled;
|
||||||
return useHotkeys(
|
return useHotkeys(
|
||||||
KEYS[key],
|
[[KEYS[key], () => isEnabled && cb(), { preventDefault: true }]],
|
||||||
(event) => {
|
undefined,
|
||||||
event.preventDefault();
|
true
|
||||||
cb();
|
|
||||||
},
|
|
||||||
{
|
|
||||||
enabled: disableGlobalCheck ? enabled : enabled && globalHotkeysEnabled,
|
|
||||||
enableOnFormTags: ['INPUT'],
|
|
||||||
}
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,35 +1,35 @@
|
|||||||
{
|
{
|
||||||
"slogan": "Manage your links in the best possible way",
|
"slogan": "Manage your links in the best possible way",
|
||||||
"confirm": "Confirm",
|
"confirm": "Confirm",
|
||||||
"cancel": "Cancel",
|
"cancel": "Cancel",
|
||||||
"home": "Home",
|
"home": "Home",
|
||||||
"back-home": "← Back to home",
|
"back-home": "← Back to home",
|
||||||
"logout": "Logout",
|
"logout": "Logout",
|
||||||
"login": "Login",
|
"login": "Login",
|
||||||
"link": {
|
"link": {
|
||||||
"links": "Links",
|
"links": "Links",
|
||||||
"link": "Link URL",
|
"link": "Link URL",
|
||||||
"name": "Link name",
|
"name": "Link name",
|
||||||
"description": "Link description",
|
"description": "Link description",
|
||||||
"create": "Create a link",
|
"create": "Create a link",
|
||||||
"edit": "Edit a link",
|
"edit": "Edit a link",
|
||||||
"delete": "Delete a link",
|
"delete": "Delete a link",
|
||||||
"delete-confirm": "Confirm deletion?"
|
"delete-confirm": "Confirm deletion?"
|
||||||
},
|
},
|
||||||
"collection": {
|
"collection": {
|
||||||
"collections": "Collection",
|
"collections": "Collection",
|
||||||
"collections_other": "Collections",
|
"collections_other": "Collections",
|
||||||
"name": "Collection name",
|
"name": "Collection name",
|
||||||
"description": "Collection description",
|
"description": "Collection description",
|
||||||
"no-description": "No description",
|
"no-description": "No description",
|
||||||
"visibility": "Public",
|
"visibility": "Public",
|
||||||
"create": "Create a collection",
|
"create": "Create a collection",
|
||||||
"edit": "Edit a collection",
|
"edit": "Edit a collection",
|
||||||
"delete": "Delete a collection",
|
"delete": "Delete a collection",
|
||||||
"delete-confirm": "Confirm deletion?",
|
"delete-confirm": "Confirm deletion?",
|
||||||
"delete-description": "You must delete all links in this collection before you can delete this collection.",
|
"delete-description": "You must delete all links in this collection before you can delete this collection.",
|
||||||
"managed-by": "Collection managed by <b>{{name}}</b>"
|
"managed-by": "Collection managed by <b>{{name}}</b>"
|
||||||
},
|
},
|
||||||
"form": {
|
"form": {
|
||||||
"name": "Name",
|
"name": "Name",
|
||||||
"description": "Description",
|
"description": "Description",
|
||||||
@@ -49,38 +49,47 @@
|
|||||||
"private": "Privé",
|
"private": "Privé",
|
||||||
"public": "Public"
|
"public": "Public"
|
||||||
},
|
},
|
||||||
"favorite": "Favorite",
|
"favorite": "Favorite",
|
||||||
"add-favorite": "Add to favorites",
|
"add-favorite": "Add to favorites",
|
||||||
"remove-favorite": "Remove from favorites",
|
"remove-favorite": "Remove from favorites",
|
||||||
"favorites-appears-here": "Your favorites will appear here",
|
"favorites-appears-here": "Your favorites will appear here",
|
||||||
"go-to-collection": "Go to collection",
|
"go-to-collection": "Go to collection",
|
||||||
"no-item-found": "No item found",
|
"no-item-found": "No item found",
|
||||||
"admin": "Administrator",
|
"admin": "Admin",
|
||||||
|
"manage-users": "Manage users",
|
||||||
"user": "User",
|
"user": "User",
|
||||||
"search": "Search",
|
"search": "Search",
|
||||||
"search-with": "Search with",
|
"search-with": "Search with",
|
||||||
"avatar": "{{name}}'s avatar",
|
"avatar": "{{name}}'s avatar",
|
||||||
"generic-error": "Something went wrong",
|
"generic-error": "Something went wrong",
|
||||||
"generic-error-description": "An error has occurred, if this happens again please <a href=\"https://github.com/Sonny93/my-links\" target=\"_blank\">create an issue</a> with as much detail as possible.",
|
"generic-error-description": "An error has occurred, if this happens again please <a href=\"https://github.com/Sonny93/my-links\" target=\"_blank\">create an issue</a> with as much detail as possible.",
|
||||||
"retry": "Retry",
|
"retry": "Retry",
|
||||||
"privacy": "Privacy",
|
"privacy": "Privacy",
|
||||||
"terms": "Terms of use",
|
"terms": "Terms of use",
|
||||||
"language": {
|
"language": {
|
||||||
"fr": "Français",
|
"fr": "Français",
|
||||||
"en": "English"
|
"en": "English"
|
||||||
},
|
},
|
||||||
"lang": "Language",
|
"lang": "Language",
|
||||||
"settings": "Settings",
|
"settings": "Settings",
|
||||||
"profile": "Profile",
|
"profile": "Profile",
|
||||||
"select-your-lang": "Change the language",
|
"select-your-lang": "Change the language",
|
||||||
"name": "Name",
|
"name": "Name",
|
||||||
"email": "Email",
|
"email": "Email",
|
||||||
"member-since": "Member since",
|
"member-since": "Member since",
|
||||||
"footer": {
|
"footer": {
|
||||||
"made_by": "Made with ❤\uFE0F by"
|
"made_by": "Made with ❤\uFE0F by"
|
||||||
},
|
},
|
||||||
"loading": "Loading...",
|
"loading": "Loading...",
|
||||||
"no-results": "No results found",
|
"no-results": "No results found",
|
||||||
"click-to-copy": "Click on the following link to copy the shareable url",
|
"click-to-copy": "Click on the following link to copy the shareable url",
|
||||||
"success-copy": "Link copied to clipboard"
|
"success-copy": "Link copied to clipboard",
|
||||||
}
|
"user-preferences": "User preferences",
|
||||||
|
"preferences": "Preferences",
|
||||||
|
"preferences-description": "Display preferences do not apply on mobile",
|
||||||
|
"display-preferences": {
|
||||||
|
"collection-list-display": "Collection list display",
|
||||||
|
"link-list-display": "Link list display"
|
||||||
|
},
|
||||||
|
"coming-soon": "Under development"
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
{
|
{
|
||||||
"select-collection": "Please select a collection",
|
"select-collection": "Please select a collection",
|
||||||
"or-create-one": "or create one",
|
"or-create-one": "or create one",
|
||||||
"no-link": "No link for <b>{{name}}</b>"
|
"no-link": "No link for <b>{{name}}</b>",
|
||||||
|
"no-link-favorite": "No favorite link"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,35 +1,35 @@
|
|||||||
{
|
{
|
||||||
"slogan": "Gérez vos liens de la meilleure des façons",
|
"slogan": "Gérez vos liens de la meilleure des façons",
|
||||||
"confirm": "Confirmer",
|
"confirm": "Confirmer",
|
||||||
"cancel": "Annuler",
|
"cancel": "Annuler",
|
||||||
"home": "Accueil",
|
"home": "Accueil",
|
||||||
"back-home": "← Revenir à l'accueil",
|
"back-home": "← Revenir à l'accueil",
|
||||||
"logout": "Déconnexion",
|
"logout": "Déconnexion",
|
||||||
"login": "Connexion",
|
"login": "Connexion",
|
||||||
"link": {
|
"link": {
|
||||||
"links": "Liens",
|
"links": "Liens",
|
||||||
"link": "URL du lien",
|
"link": "URL du lien",
|
||||||
"name": "Nom du lien",
|
"name": "Nom du lien",
|
||||||
"description": "Description du lien",
|
"description": "Description du lien",
|
||||||
"create": "Créer un lien",
|
"create": "Créer un lien",
|
||||||
"edit": "Modifier un lien",
|
"edit": "Modifier un lien",
|
||||||
"delete": "Supprimer un lien",
|
"delete": "Supprimer un lien",
|
||||||
"delete-confirm": "Confirmer la suppression ?"
|
"delete-confirm": "Confirmer la suppression ?"
|
||||||
},
|
},
|
||||||
"collection": {
|
"collection": {
|
||||||
"collections": "Collection",
|
"collections": "Collection",
|
||||||
"collections_other": "Collections",
|
"collections_other": "Collections",
|
||||||
"name": "Nom de la collection",
|
"name": "Nom de la collection",
|
||||||
"description": "Description de la collection",
|
"description": "Description de la collection",
|
||||||
"no-description": "Aucune description",
|
"no-description": "Aucune description",
|
||||||
"visibility": "Public",
|
"visibility": "Public",
|
||||||
"create": "Créer une collection",
|
"create": "Créer une collection",
|
||||||
"edit": "Modifier une collection",
|
"edit": "Modifier une collection",
|
||||||
"delete": "Supprimer une collection",
|
"delete": "Supprimer une collection",
|
||||||
"delete-confirm": "Confirmer la suppression ?",
|
"delete-confirm": "Confirmer la suppression ?",
|
||||||
"delete-description": "Vous devez supprimer tous les liens de cette collection avant de pouvoir supprimer cette collection",
|
"delete-description": "Vous devez supprimer tous les liens de cette collection avant de pouvoir supprimer cette collection",
|
||||||
"managed-by": "Collection gérée par <b>{{name}}</b>"
|
"managed-by": "Collection gérée par <b>{{name}}</b>"
|
||||||
},
|
},
|
||||||
"form": {
|
"form": {
|
||||||
"name": "Nom",
|
"name": "Nom",
|
||||||
"description": "Description",
|
"description": "Description",
|
||||||
@@ -49,38 +49,47 @@
|
|||||||
"private": "Privé",
|
"private": "Privé",
|
||||||
"public": "Public"
|
"public": "Public"
|
||||||
},
|
},
|
||||||
"favorite": "Favoris",
|
"favorite": "Favoris",
|
||||||
"add-favorite": "Ajouter aux favoris",
|
"add-favorite": "Ajouter aux favoris",
|
||||||
"remove-favorite": "Retirer des favoris",
|
"remove-favorite": "Retirer des favoris",
|
||||||
"favorites-appears-here": "Vos favoris apparaîtront ici",
|
"favorites-appears-here": "Vos favoris apparaîtront ici",
|
||||||
"go-to-collection": "Voir la collection",
|
"go-to-collection": "Voir la collection",
|
||||||
"no-item-found": "Aucun élément trouvé",
|
"no-item-found": "Aucun élément trouvé",
|
||||||
"admin": "Administrateur",
|
"admin": "Admin",
|
||||||
|
"manage-users": "Gestion des utilisateurs",
|
||||||
"user": "Utilisateur",
|
"user": "Utilisateur",
|
||||||
"search": "Rechercher",
|
"search": "Rechercher",
|
||||||
"search-with": "Rechercher avec",
|
"search-with": "Rechercher avec",
|
||||||
"avatar": "Avatar de {{name}}",
|
"avatar": "Avatar de {{name}}",
|
||||||
"generic-error": "Une erreur est survenue",
|
"generic-error": "Une erreur est survenue",
|
||||||
"generic-error-description": "Une erreur est survenue, si cela se reproduit merci de <a href=\"https://github.com/Sonny93/my-links\" target=\"_blank\">créer une issue</a> avec le maximum de détails.",
|
"generic-error-description": "Une erreur est survenue, si cela se reproduit merci de <a href=\"https://github.com/Sonny93/my-links\" target=\"_blank\">créer une issue</a> avec le maximum de détails.",
|
||||||
"retry": "Recommencer",
|
"retry": "Recommencer",
|
||||||
"privacy": "Confidentialité",
|
"privacy": "Confidentialité",
|
||||||
"terms": "CGU",
|
"terms": "CGU",
|
||||||
"language": {
|
"language": {
|
||||||
"fr": "Français",
|
"fr": "Français",
|
||||||
"en": "English"
|
"en": "English"
|
||||||
},
|
},
|
||||||
"lang": "Langage",
|
"lang": "Langage",
|
||||||
"settings": "Paramètres",
|
"settings": "Paramètres",
|
||||||
"profile": "Profil",
|
"profile": "Profil",
|
||||||
"select-your-lang": "Modifier la langue",
|
"select-your-lang": "Modifier la langue",
|
||||||
"name": "Nom",
|
"name": "Nom",
|
||||||
"email": "Email",
|
"email": "Email",
|
||||||
"member-since": "Membre depuis",
|
"member-since": "Membre depuis",
|
||||||
"footer": {
|
"footer": {
|
||||||
"made_by": "Fait avec ❤\uFE0F par"
|
"made_by": "Fait avec ❤\uFE0F par"
|
||||||
},
|
},
|
||||||
"loading": "Chargement...",
|
"loading": "Chargement...",
|
||||||
"no-results": "Aucun résultat trouvé",
|
"no-results": "Aucun résultat trouvé",
|
||||||
"click-to-copy": "Cliquez sur le lien suivant pour copier l'URL partageable",
|
"click-to-copy": "Cliquez sur le lien suivant pour copier l'URL partageable",
|
||||||
"success-copy": "Link copié dans le presse-papiers"
|
"success-copy": "Link copié dans le presse-papiers",
|
||||||
}
|
"user-preferences": "Préférences utilisateur",
|
||||||
|
"preferences": "Préférences",
|
||||||
|
"preferences-description": "Les préférences d'affichage ne s'appliquent pas sur mobile",
|
||||||
|
"display-preferences": {
|
||||||
|
"collection-list-display": "Affichage de la liste des collections",
|
||||||
|
"link-list-display": "Affichage de la liste des liens"
|
||||||
|
},
|
||||||
|
"coming-soon": "En cours de développement"
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
{
|
{
|
||||||
"select-collection": "Veuillez sélectionner une collection",
|
"select-collection": "Veuillez sélectionner une collection",
|
||||||
"or-create-one": "ou en créer une",
|
"or-create-one": "ou en créer une",
|
||||||
"no-link": "Aucun lien pour <b>{{name}}</b>"
|
"no-link": "Aucun lien pour <b>{{name}}</b>",
|
||||||
|
"no-link-favorite": "Aucun lien dans les favoris"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
import { api } from '#adonis/api';
|
import { api } from '#adonis/api';
|
||||||
import { PRIMARY_COLOR } from '#config/project';
|
import { PRIMARY_COLOR } from '#config/project';
|
||||||
import { PageProps } from '@adonisjs/inertia/types';
|
import { router } from '@inertiajs/react';
|
||||||
import { router, usePage } from '@inertiajs/react';
|
|
||||||
import {
|
import {
|
||||||
ColorSchemeScript,
|
ColorSchemeScript,
|
||||||
createTheme,
|
createTheme,
|
||||||
@@ -9,12 +8,14 @@ import {
|
|||||||
rem,
|
rem,
|
||||||
} from '@mantine/core';
|
} from '@mantine/core';
|
||||||
import '@mantine/core/styles.css';
|
import '@mantine/core/styles.css';
|
||||||
|
import { ModalsProvider } from '@mantine/modals';
|
||||||
import '@mantine/spotlight/styles.css';
|
import '@mantine/spotlight/styles.css';
|
||||||
import { createTuyau } from '@tuyau/client';
|
import { createTuyau } from '@tuyau/client';
|
||||||
import { TuyauProvider } from '@tuyau/inertia/react';
|
import { TuyauProvider } from '@tuyau/inertia/react';
|
||||||
import dayjs from 'dayjs';
|
import dayjs from 'dayjs';
|
||||||
import { ReactNode, useEffect } from 'react';
|
import { ReactNode, useEffect } from 'react';
|
||||||
import { useTranslation } from 'react-i18next';
|
import { useTranslation } from 'react-i18next';
|
||||||
|
import { useAppUrl } from '~/hooks/use_app_url';
|
||||||
import '../styles/index.css';
|
import '../styles/index.css';
|
||||||
|
|
||||||
const TRANSITION_IN_CLASS = '__transition_fadeIn';
|
const TRANSITION_IN_CLASS = '__transition_fadeIn';
|
||||||
@@ -73,12 +74,12 @@ const customTheme = createTheme({
|
|||||||
|
|
||||||
export function BaseLayout({ children }: { children: ReactNode }) {
|
export function BaseLayout({ children }: { children: ReactNode }) {
|
||||||
const { i18n } = useTranslation();
|
const { i18n } = useTranslation();
|
||||||
|
const appUrl = useAppUrl();
|
||||||
dayjs.locale(i18n.language);
|
dayjs.locale(i18n.language);
|
||||||
const { props } = usePage<PageProps & { appBaseUrl: string }>();
|
|
||||||
|
|
||||||
const tuyauClient = createTuyau({
|
const tuyauClient = createTuyau({
|
||||||
api,
|
api,
|
||||||
baseUrl: props.appBaseUrl,
|
baseUrl: appUrl,
|
||||||
});
|
});
|
||||||
|
|
||||||
const findAppElement = () => document.getElementById('app');
|
const findAppElement = () => document.getElementById('app');
|
||||||
@@ -119,7 +120,9 @@ export function BaseLayout({ children }: { children: ReactNode }) {
|
|||||||
return (
|
return (
|
||||||
<TuyauProvider client={tuyauClient}>
|
<TuyauProvider client={tuyauClient}>
|
||||||
<ColorSchemeScript />
|
<ColorSchemeScript />
|
||||||
<MantineProvider theme={customTheme}>{children}</MantineProvider>
|
<MantineProvider theme={customTheme}>
|
||||||
|
<ModalsProvider>{children}</ModalsProvider>
|
||||||
|
</MantineProvider>
|
||||||
</TuyauProvider>
|
</TuyauProvider>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -31,7 +31,7 @@ const Layout = ({ children }: PropsWithChildren) => (
|
|||||||
maxWidth: '100%',
|
maxWidth: '100%',
|
||||||
width: LAYOUT_WIDTH,
|
width: LAYOUT_WIDTH,
|
||||||
marginInline: 'auto',
|
marginInline: 'auto',
|
||||||
marginBlock: rem(60),
|
marginBlock: rem(30),
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
{children}
|
{children}
|
||||||
|
|||||||
@@ -70,7 +70,7 @@ function FormLayout({
|
|||||||
{!disableHomeLink && (
|
{!disableHomeLink && (
|
||||||
<Anchor
|
<Anchor
|
||||||
component={Link}
|
component={Link}
|
||||||
href={appendCollectionId(route('dashboard').url, collectionId)}
|
href={appendCollectionId(route('dashboard').path, collectionId)}
|
||||||
disabled={disableHomeLink}
|
disabled={disableHomeLink}
|
||||||
>
|
>
|
||||||
{t('back-home')}
|
{t('back-home')}
|
||||||
|
|||||||
34
inertia/lib/display_preferences.tsx
Normal file
34
inertia/lib/display_preferences.tsx
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
import {
|
||||||
|
COLLECTION_LIST_DISPLAYS,
|
||||||
|
LINK_LIST_DISPLAYS,
|
||||||
|
} from '#shared/lib/display_preferences';
|
||||||
|
import { AiOutlineFolder } from 'react-icons/ai';
|
||||||
|
import { IoGridOutline } from 'react-icons/io5';
|
||||||
|
import { TbList } from 'react-icons/tb';
|
||||||
|
import { ValueWithIcon } from '~/components/common/combo_list/combo_list';
|
||||||
|
|
||||||
|
const collectionListDisplayIcons = {
|
||||||
|
list: <TbList size={20} />,
|
||||||
|
inline: <AiOutlineFolder size={20} />,
|
||||||
|
} as const;
|
||||||
|
|
||||||
|
export function getCollectionListDisplayOptions(): ValueWithIcon[] {
|
||||||
|
return COLLECTION_LIST_DISPLAYS.map((display) => ({
|
||||||
|
label: display,
|
||||||
|
value: display,
|
||||||
|
icon: collectionListDisplayIcons[display],
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
|
||||||
|
const linkListDisplayIcons = {
|
||||||
|
list: <TbList size={20} />,
|
||||||
|
grid: <IoGridOutline size={20} />,
|
||||||
|
} as const;
|
||||||
|
|
||||||
|
export function getLinkListDisplayOptions(): ValueWithIcon[] {
|
||||||
|
return LINK_LIST_DISPLAYS.map((display) => ({
|
||||||
|
label: display,
|
||||||
|
value: display,
|
||||||
|
icon: linkListDisplayIcons[display],
|
||||||
|
}));
|
||||||
|
}
|
||||||
@@ -1,98 +1,121 @@
|
|||||||
import { AppShell, ScrollArea } from '@mantine/core';
|
import { Link } from '@inertiajs/react';
|
||||||
import { useDisclosure } from '@mantine/hooks';
|
import { route } from '@izzyjs/route/client';
|
||||||
import { useEffect } from 'react';
|
|
||||||
import { DashboardAside } from '~/components/dashboard/dashboard_aside';
|
|
||||||
import { DashboardHeader } from '~/components/dashboard/dashboard_header';
|
|
||||||
import { DashboardNavbar } from '~/components/dashboard/dashboard_navbar';
|
|
||||||
import { LinkList } from '~/components/dashboard/link/list/link_list';
|
|
||||||
import { MantineFooter } from '~/components/footer/footer';
|
|
||||||
import { useDisableOverflow } from '~/hooks/use_disable_overflow';
|
|
||||||
import useShortcut from '~/hooks/use_shortcut';
|
|
||||||
import { DashboardLayout } from '~/layouts/dashboard_layout';
|
|
||||||
import {
|
import {
|
||||||
useActiveCollection,
|
Box,
|
||||||
useCollectionsSetter,
|
Button,
|
||||||
} from '~/stores/collection_store';
|
Divider,
|
||||||
import { CollectionWithLinks } from '~/types/app';
|
Group,
|
||||||
import classes from './dashboard.module.css';
|
Input,
|
||||||
|
Stack,
|
||||||
|
Text,
|
||||||
|
Tooltip,
|
||||||
|
} from '@mantine/core';
|
||||||
|
import { useTranslation } from 'react-i18next';
|
||||||
|
import { CollectionList } from '~/components/dashboard/collection/collection_list';
|
||||||
|
import { InlineCollectionList } from '~/components/dashboard/collection/inline_collection_list';
|
||||||
|
import { MobileCollectionList } from '~/components/dashboard/collection/mobile_collection_list';
|
||||||
|
import { SharedCollectionCopyLink } from '~/components/dashboard/collection/shared_collection_copy_link';
|
||||||
|
import { LinkList } from '~/components/dashboard/link/list/link_list';
|
||||||
|
import { useActiveCollection } from '~/hooks/collections/use_active_collection';
|
||||||
|
import { useDisplayPreferences } from '~/hooks/use_display_preferences';
|
||||||
|
import { useIsMobile } from '~/hooks/use_is_mobile';
|
||||||
|
import { appendCollectionId } from '~/lib/navigation';
|
||||||
|
import { Visibility } from '~/types/app';
|
||||||
|
|
||||||
interface DashboardPageProps {
|
export default function Dashboard() {
|
||||||
collections: CollectionWithLinks[];
|
const { t } = useTranslation();
|
||||||
activeCollection: CollectionWithLinks;
|
const { displayPreferences } = useDisplayPreferences();
|
||||||
}
|
const activeCollection = useActiveCollection();
|
||||||
|
|
||||||
const HEADER_SIZE_WITH_DESCRIPTION = 60;
|
const isMobile = useIsMobile();
|
||||||
const HEADER_SIZE_WITHOUT_DESCRIPTION = 50;
|
const isFavorite = !activeCollection?.id;
|
||||||
|
|
||||||
export default function MantineDashboard(props: Readonly<DashboardPageProps>) {
|
|
||||||
const [openedNavbar, { toggle: toggleNavbar, close: closeNavbar }] =
|
|
||||||
useDisclosure();
|
|
||||||
const [openedAside, { toggle: toggleAside, close: closeAside }] =
|
|
||||||
useDisclosure();
|
|
||||||
|
|
||||||
const { activeCollection } = useActiveCollection();
|
|
||||||
const { _setCollections, setActiveCollection } = useCollectionsSetter();
|
|
||||||
|
|
||||||
useShortcut('ESCAPE_KEY', () => {
|
|
||||||
closeNavbar();
|
|
||||||
closeAside();
|
|
||||||
});
|
|
||||||
|
|
||||||
useDisableOverflow();
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
_setCollections(props.collections);
|
|
||||||
setActiveCollection(props.activeCollection);
|
|
||||||
}, []);
|
|
||||||
|
|
||||||
const headerHeight = !!activeCollection?.description
|
|
||||||
? HEADER_SIZE_WITH_DESCRIPTION
|
|
||||||
: HEADER_SIZE_WITHOUT_DESCRIPTION;
|
|
||||||
const footerHeight = 45;
|
|
||||||
return (
|
return (
|
||||||
<DashboardLayout>
|
<Stack w="100%">
|
||||||
<div className={classes.app_wrapper}>
|
<Group justify="space-between">
|
||||||
<AppShell
|
<Tooltip label={t('coming-soon')}>
|
||||||
layout="alt"
|
<Input
|
||||||
header={{ height: headerHeight }}
|
placeholder={t('search')}
|
||||||
navbar={{
|
w={isMobile ? '100%' : '350px'}
|
||||||
width: 300,
|
disabled
|
||||||
breakpoint: 'sm',
|
|
||||||
collapsed: { mobile: !openedNavbar },
|
|
||||||
}}
|
|
||||||
aside={{
|
|
||||||
width: 300,
|
|
||||||
breakpoint: 'md',
|
|
||||||
collapsed: { mobile: !openedAside },
|
|
||||||
}}
|
|
||||||
footer={{ height: footerHeight }}
|
|
||||||
classNames={{
|
|
||||||
aside: classes.ml_custom_class,
|
|
||||||
footer: classes.ml_custom_class,
|
|
||||||
navbar: classes.ml_custom_class,
|
|
||||||
header: classes.ml_custom_class,
|
|
||||||
}}
|
|
||||||
className={classes.app_shell}
|
|
||||||
>
|
|
||||||
<DashboardHeader
|
|
||||||
navbar={{ opened: openedNavbar, toggle: toggleNavbar }}
|
|
||||||
aside={{ opened: openedAside, toggle: toggleAside }}
|
|
||||||
/>
|
/>
|
||||||
<DashboardNavbar isOpen={openedNavbar} toggle={toggleNavbar} />
|
</Tooltip>
|
||||||
<AppShell.Main>
|
<Group>
|
||||||
<ScrollArea
|
{activeCollection?.visibility === Visibility.PUBLIC && (
|
||||||
h="calc(100vh - var(--app-shell-header-height) - var(--app-shell-footer-height, 0px))"
|
<>
|
||||||
p="md"
|
<SharedCollectionCopyLink />
|
||||||
|
<Divider orientation="vertical" />
|
||||||
|
</>
|
||||||
|
)}
|
||||||
|
|
||||||
|
<Button
|
||||||
|
variant="outline"
|
||||||
|
component={Link}
|
||||||
|
href={appendCollectionId(
|
||||||
|
route('collection.create-form').path,
|
||||||
|
activeCollection?.id
|
||||||
|
)}
|
||||||
|
size="xs"
|
||||||
|
>
|
||||||
|
{t('collection.create')}
|
||||||
|
</Button>
|
||||||
|
{!isFavorite && (
|
||||||
|
<Button
|
||||||
|
variant="outline"
|
||||||
|
component={Link}
|
||||||
|
href={appendCollectionId(
|
||||||
|
route('collection.edit-form').path,
|
||||||
|
activeCollection?.id
|
||||||
|
)}
|
||||||
|
size="xs"
|
||||||
>
|
>
|
||||||
<LinkList />
|
{t('collection.edit')}
|
||||||
</ScrollArea>
|
</Button>
|
||||||
</AppShell.Main>
|
)}
|
||||||
<DashboardAside isOpen={openedAside} toggle={toggleAside} />
|
|
||||||
<AppShell.Footer pl="xs" pr="xs">
|
<>
|
||||||
<MantineFooter />
|
<Divider orientation="vertical" />
|
||||||
</AppShell.Footer>
|
<Button
|
||||||
</AppShell>
|
variant="light"
|
||||||
</div>
|
component={Link}
|
||||||
</DashboardLayout>
|
href={appendCollectionId(
|
||||||
|
route('link.create-form').path,
|
||||||
|
activeCollection?.id
|
||||||
|
)}
|
||||||
|
size="xs"
|
||||||
|
>
|
||||||
|
{t('link.create')}
|
||||||
|
</Button>
|
||||||
|
</>
|
||||||
|
</Group>
|
||||||
|
</Group>
|
||||||
|
{displayPreferences.collectionListDisplay === 'inline' && !isMobile && (
|
||||||
|
<InlineCollectionList />
|
||||||
|
)}
|
||||||
|
<Group
|
||||||
|
wrap="nowrap"
|
||||||
|
align="flex-start"
|
||||||
|
style={{ flexDirection: isMobile ? 'column-reverse' : 'row' }}
|
||||||
|
flex={1}
|
||||||
|
w="100%"
|
||||||
|
>
|
||||||
|
<Box w="100%">
|
||||||
|
{activeCollection?.description && (
|
||||||
|
<Text
|
||||||
|
size="sm"
|
||||||
|
c="dimmed"
|
||||||
|
mb="md"
|
||||||
|
style={{ wordBreak: 'break-word', whiteSpace: 'pre-line' }}
|
||||||
|
>
|
||||||
|
{activeCollection.description}
|
||||||
|
</Text>
|
||||||
|
)}
|
||||||
|
<LinkList />
|
||||||
|
</Box>
|
||||||
|
{displayPreferences.collectionListDisplay === 'list' && !isMobile && (
|
||||||
|
<CollectionList />
|
||||||
|
)}
|
||||||
|
</Group>
|
||||||
|
{isMobile && <MobileCollectionList />}
|
||||||
|
</Stack>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,28 +1,20 @@
|
|||||||
import { Flex, Text } from '@mantine/core';
|
import { Flex, Text } from '@mantine/core';
|
||||||
import { useEffect } from 'react';
|
|
||||||
import { useTranslation } from 'react-i18next';
|
import { useTranslation } from 'react-i18next';
|
||||||
import { LinkList } from '~/components/dashboard/link/list/link_list';
|
import { LinkList } from '~/components/dashboard/link/list/link_list';
|
||||||
import { useCollectionsSetter } from '~/stores/collection_store';
|
|
||||||
import type { CollectionWithLinks, PublicUser } from '~/types/app';
|
import type { CollectionWithLinks, PublicUser } from '~/types/app';
|
||||||
|
|
||||||
interface SharedPageProps {
|
interface SharedPageProps {
|
||||||
collection: CollectionWithLinks & { author: PublicUser };
|
activeCollection: CollectionWithLinks & { author: PublicUser };
|
||||||
}
|
}
|
||||||
|
|
||||||
export default function SharedPage({ collection }: SharedPageProps) {
|
export default function SharedPage({ activeCollection }: SharedPageProps) {
|
||||||
const { t } = useTranslation('common');
|
const { t } = useTranslation('common');
|
||||||
const { setActiveCollection } = useCollectionsSetter();
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
setActiveCollection(collection);
|
|
||||||
}, []);
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<Flex direction="column">
|
<Flex direction="column">
|
||||||
<Text size="xl">{collection.name}</Text>
|
<Text size="xl">{activeCollection.name}</Text>
|
||||||
<Text size="sm" c="dimmed">
|
<Text size="sm" c="dimmed">
|
||||||
{collection.description}
|
{activeCollection.description}
|
||||||
</Text>
|
</Text>
|
||||||
<Flex justify="flex-end">
|
<Flex justify="flex-end">
|
||||||
<Text
|
<Text
|
||||||
@@ -32,7 +24,7 @@ export default function SharedPage({ collection }: SharedPageProps) {
|
|||||||
mb="lg"
|
mb="lg"
|
||||||
dangerouslySetInnerHTML={{
|
dangerouslySetInnerHTML={{
|
||||||
__html: t('collection.managed-by', {
|
__html: t('collection.managed-by', {
|
||||||
name: collection.author.fullname,
|
name: activeCollection.author.fullname,
|
||||||
}),
|
}),
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
|
|||||||
@@ -1,92 +0,0 @@
|
|||||||
import { create } from 'zustand';
|
|
||||||
import { useShallow } from 'zustand/react/shallow';
|
|
||||||
import { CollectionWithLinks, Link, LinkWithCollection } from '~/types/app';
|
|
||||||
|
|
||||||
type Collections = CollectionWithLinks[];
|
|
||||||
|
|
||||||
interface CollectionStore {
|
|
||||||
collections: Collections;
|
|
||||||
_setCollections: (collections: Collections) => void;
|
|
||||||
|
|
||||||
activeCollection: CollectionWithLinks | null;
|
|
||||||
setActiveCollection: (collection: CollectionWithLinks) => void;
|
|
||||||
|
|
||||||
favorites: LinkWithCollection[];
|
|
||||||
toggleFavorite: (link: Link['id']) => void;
|
|
||||||
}
|
|
||||||
|
|
||||||
export const useCollectionStore = create<CollectionStore>((set, get) => ({
|
|
||||||
collections: [],
|
|
||||||
_setCollections: (collections) => {
|
|
||||||
const favorites = getFavoriteLinks(collections);
|
|
||||||
set({ collections, favorites });
|
|
||||||
},
|
|
||||||
|
|
||||||
activeCollection: null,
|
|
||||||
setActiveCollection: (collection) => set({ activeCollection: collection }),
|
|
||||||
|
|
||||||
favorites: [],
|
|
||||||
toggleFavorite: (linkId) => {
|
|
||||||
const { collections } = get();
|
|
||||||
let linkIndex = 0;
|
|
||||||
const collectionIndex = collections.findIndex(({ links }) => {
|
|
||||||
const lIndex = links.findIndex((l) => l.id === linkId);
|
|
||||||
if (lIndex !== -1) {
|
|
||||||
linkIndex = lIndex;
|
|
||||||
}
|
|
||||||
return lIndex !== -1;
|
|
||||||
});
|
|
||||||
|
|
||||||
const collectionLink = collections[collectionIndex].links[linkIndex];
|
|
||||||
const collectionsCopy = [...collections];
|
|
||||||
collectionsCopy[collectionIndex].links[linkIndex] = {
|
|
||||||
...collectionLink,
|
|
||||||
favorite: !collectionLink.favorite,
|
|
||||||
};
|
|
||||||
|
|
||||||
set({
|
|
||||||
collections: collectionsCopy,
|
|
||||||
activeCollection: collectionsCopy[collectionIndex],
|
|
||||||
favorites: getFavoriteLinks(collectionsCopy),
|
|
||||||
});
|
|
||||||
},
|
|
||||||
}));
|
|
||||||
|
|
||||||
export const useActiveCollection = () =>
|
|
||||||
useCollectionStore(
|
|
||||||
useShallow((state) => ({
|
|
||||||
activeCollection: state.activeCollection,
|
|
||||||
setActiveCollection: state.setActiveCollection,
|
|
||||||
}))
|
|
||||||
);
|
|
||||||
|
|
||||||
export const useCollections = () =>
|
|
||||||
useCollectionStore(
|
|
||||||
useShallow((state) => ({ collections: state.collections }))
|
|
||||||
);
|
|
||||||
|
|
||||||
export const useFavorites = () =>
|
|
||||||
useCollectionStore(
|
|
||||||
useShallow((state) => ({
|
|
||||||
favorites: state.favorites,
|
|
||||||
toggleFavorite: state.toggleFavorite,
|
|
||||||
}))
|
|
||||||
);
|
|
||||||
|
|
||||||
export function useCollectionsSetter() {
|
|
||||||
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
||||||
const { _setCollections, setActiveCollection } = useCollectionStore();
|
|
||||||
return { _setCollections, setActiveCollection };
|
|
||||||
}
|
|
||||||
|
|
||||||
function getFavoriteLinks(collections: Collections) {
|
|
||||||
return collections.reduce((acc, collection) => {
|
|
||||||
collection.links.forEach((link) => {
|
|
||||||
if (link.favorite) {
|
|
||||||
const newLink: LinkWithCollection = { ...link, collection };
|
|
||||||
acc.push(newLink);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
return acc;
|
|
||||||
}, [] as LinkWithCollection[]);
|
|
||||||
}
|
|
||||||
@@ -1,3 +1,5 @@
|
|||||||
|
import { DisplayPreferences } from '#shared/types/index';
|
||||||
|
|
||||||
type CommonBase = {
|
type CommonBase = {
|
||||||
id: number;
|
id: number;
|
||||||
createdAt: string;
|
createdAt: string;
|
||||||
@@ -10,6 +12,7 @@ export type User = CommonBase & {
|
|||||||
avatarUrl: string;
|
avatarUrl: string;
|
||||||
isAdmin: boolean;
|
isAdmin: boolean;
|
||||||
lastSeenAt: string;
|
lastSeenAt: string;
|
||||||
|
displayPreferences: DisplayPreferences;
|
||||||
};
|
};
|
||||||
|
|
||||||
export type PublicUser = Omit<User, 'email'>;
|
export type PublicUser = Omit<User, 'email'>;
|
||||||
|
|||||||
40
package.json
40
package.json
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "my-links",
|
"name": "my-links",
|
||||||
"version": "3.1.3",
|
"version": "3.2.0",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"license": "GPL-3.0-only",
|
"license": "GPL-3.0-only",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
@@ -8,7 +8,7 @@
|
|||||||
"build": "node ace build",
|
"build": "node ace build",
|
||||||
"dev": "node ace serve --hmr",
|
"dev": "node ace serve --hmr",
|
||||||
"test": "node ace test",
|
"test": "node ace test",
|
||||||
"lint": "eslint . --report-unused-disable-directives --max-warnings 0",
|
"lint": "eslint . --report-unused-disable-directives --max-warnings 0 --ignore-pattern '.adonisjs/*'",
|
||||||
"format": "prettier --write --parser typescript '**/*.{ts,tsx}'",
|
"format": "prettier --write --parser typescript '**/*.{ts,tsx}'",
|
||||||
"typecheck": "tsc --noEmit",
|
"typecheck": "tsc --noEmit",
|
||||||
"check": "pnpm run lint && pnpm run typecheck",
|
"check": "pnpm run lint && pnpm run typecheck",
|
||||||
@@ -39,25 +39,25 @@
|
|||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@adonisjs/assembler": "^7.8.2",
|
"@adonisjs/assembler": "^7.8.2",
|
||||||
"@adonisjs/eslint-config": "2.1.1",
|
"@adonisjs/eslint-config": "2.1.2",
|
||||||
"@adonisjs/prettier-config": "^1.4.5",
|
"@adonisjs/prettier-config": "^1.4.5",
|
||||||
"@adonisjs/tsconfig": "^1.4.1",
|
"@adonisjs/tsconfig": "^1.4.1",
|
||||||
"@faker-js/faker": "^9.9.0",
|
"@faker-js/faker": "^9.9.0",
|
||||||
"@japa/assert": "^4.1.1",
|
"@japa/assert": "^4.1.1",
|
||||||
"@japa/plugin-adonisjs": "^4.0.0",
|
"@japa/plugin-adonisjs": "^4.0.0",
|
||||||
"@japa/runner": "^4.3.0",
|
"@japa/runner": "^4.4.0",
|
||||||
"@swc/core": "^1.13.3",
|
"@swc/core": "^1.13.3",
|
||||||
"@tuyau/utils": "^0.0.9",
|
"@tuyau/utils": "^0.0.9",
|
||||||
"@types/luxon": "^3.7.1",
|
"@types/luxon": "^3.7.1",
|
||||||
"@types/node": "^24.2.0",
|
"@types/node": "^24.3.0",
|
||||||
"@types/react": "^19.1.9",
|
"@types/react": "^19.1.10",
|
||||||
"@types/react-dom": "^19.1.7",
|
"@types/react-dom": "^19.1.7",
|
||||||
"@typescript-eslint/eslint-plugin": "^8.39.0",
|
"@typescript-eslint/eslint-plugin": "^8.40.0",
|
||||||
"@vite-pwa/assets-generator": "^1.0.0",
|
"@vite-pwa/assets-generator": "^1.0.0",
|
||||||
"eslint": "^9.32.0",
|
"eslint": "^9.33.0",
|
||||||
"hot-hook": "^0.4.0",
|
"hot-hook": "^0.4.0",
|
||||||
"husky": "^9.1.7",
|
"husky": "^9.1.7",
|
||||||
"lint-staged": "^16.1.4",
|
"lint-staged": "^16.1.5",
|
||||||
"pino-pretty": "^13.1.1",
|
"pino-pretty": "^13.1.1",
|
||||||
"postcss": "^8.5.6",
|
"postcss": "^8.5.6",
|
||||||
"postcss-preset-mantine": "^1.18.0",
|
"postcss-preset-mantine": "^1.18.0",
|
||||||
@@ -66,7 +66,7 @@
|
|||||||
"release-it": "^19.0.4",
|
"release-it": "^19.0.4",
|
||||||
"ts-node-maintained": "^10.9.6",
|
"ts-node-maintained": "^10.9.6",
|
||||||
"typescript": "~5.9.2",
|
"typescript": "~5.9.2",
|
||||||
"vite": "^7.0.6"
|
"vite": "^7.1.3"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@adonisjs/ally": "^5.1.0",
|
"@adonisjs/ally": "^5.1.0",
|
||||||
@@ -79,11 +79,12 @@
|
|||||||
"@adonisjs/shield": "^8.2.0",
|
"@adonisjs/shield": "^8.2.0",
|
||||||
"@adonisjs/static": "^1.1.1",
|
"@adonisjs/static": "^1.1.1",
|
||||||
"@adonisjs/vite": "^4.0.0",
|
"@adonisjs/vite": "^4.0.0",
|
||||||
"@inertiajs/react": "^2.0.17",
|
"@inertiajs/react": "^2.1.2",
|
||||||
"@izzyjs/route": "^1.2.0",
|
"@izzyjs/route": "^1.2.0",
|
||||||
"@mantine/core": "^8.2.3",
|
"@mantine/core": "^8.2.5",
|
||||||
"@mantine/hooks": "^8.2.3",
|
"@mantine/hooks": "^8.2.5",
|
||||||
"@mantine/spotlight": "^8.2.3",
|
"@mantine/modals": "^8.2.5",
|
||||||
|
"@mantine/spotlight": "^8.2.5",
|
||||||
"@tuyau/client": "^0.2.10",
|
"@tuyau/client": "^0.2.10",
|
||||||
"@tuyau/core": "^0.4.2",
|
"@tuyau/core": "^0.4.2",
|
||||||
"@tuyau/inertia": "^0.0.15",
|
"@tuyau/inertia": "^0.0.15",
|
||||||
@@ -93,19 +94,18 @@
|
|||||||
"clsx": "^2.1.1",
|
"clsx": "^2.1.1",
|
||||||
"dayjs": "^1.11.13",
|
"dayjs": "^1.11.13",
|
||||||
"edge.js": "^6.3.0",
|
"edge.js": "^6.3.0",
|
||||||
"i18next": "^25.3.2",
|
"i18next": "^25.4.0",
|
||||||
"knex": "^3.1.0",
|
"knex": "^3.1.0",
|
||||||
"luxon": "^3.7.1",
|
"luxon": "^3.7.1",
|
||||||
"node-html-parser": "^7.0.1",
|
"node-html-parser": "^7.0.1",
|
||||||
"pg": "^8.16.3",
|
"pg": "^8.16.3",
|
||||||
"react": "^19.1.1",
|
"react": "^19.1.1",
|
||||||
"react-dom": "^19.1.1",
|
"react-dom": "^19.1.1",
|
||||||
"react-hotkeys-hook": "^5.1.0",
|
"react-i18next": "^15.7.0",
|
||||||
"react-i18next": "^15.6.1",
|
|
||||||
"react-icons": "^5.5.0",
|
"react-icons": "^5.5.0",
|
||||||
"reflect-metadata": "^0.2.2",
|
"reflect-metadata": "^0.2.2",
|
||||||
"vite-plugin-pwa": "^1.0.2",
|
"vite-plugin-pwa": "^1.0.3",
|
||||||
"zustand": "^5.0.7"
|
"zustand": "^5.0.8"
|
||||||
},
|
},
|
||||||
"hotHook": {
|
"hotHook": {
|
||||||
"boundaries": [
|
"boundaries": [
|
||||||
@@ -127,7 +127,7 @@
|
|||||||
"*.js,*.ts,*.jsx,*.tsx": "eslint --cache --fix"
|
"*.js,*.ts,*.jsx,*.tsx": "eslint --cache --fix"
|
||||||
},
|
},
|
||||||
"volta": {
|
"volta": {
|
||||||
"node": "24.1.0"
|
"node": "24.6.0"
|
||||||
},
|
},
|
||||||
"pnpm": {
|
"pnpm": {
|
||||||
"overrides": {
|
"overrides": {
|
||||||
|
|||||||
799
pnpm-lock.yaml
generated
799
pnpm-lock.yaml
generated
File diff suppressed because it is too large
Load Diff
18
shared/lib/display_preferences.ts
Normal file
18
shared/lib/display_preferences.ts
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
import { DisplayPreferences } from '#shared/types/index';
|
||||||
|
|
||||||
|
export const COLLECTION_LIST_DISPLAYS = ['list', 'inline'] as const;
|
||||||
|
export const LINK_LIST_DISPLAYS = ['list', 'grid'] as const;
|
||||||
|
|
||||||
|
export const DEFAULT_LIST_DISPLAY_PREFERENCES: DisplayPreferences = {
|
||||||
|
linkListDisplay: LINK_LIST_DISPLAYS[0],
|
||||||
|
collectionListDisplay: COLLECTION_LIST_DISPLAYS[0],
|
||||||
|
} as const;
|
||||||
|
|
||||||
|
export function getDisplayPreferences(
|
||||||
|
displayPreferences: Partial<DisplayPreferences> = DEFAULT_LIST_DISPLAY_PREFERENCES
|
||||||
|
): DisplayPreferences {
|
||||||
|
return {
|
||||||
|
...DEFAULT_LIST_DISPLAY_PREFERENCES,
|
||||||
|
...displayPreferences,
|
||||||
|
} as const;
|
||||||
|
}
|
||||||
@@ -1,3 +1,11 @@
|
|||||||
import { api } from '#adonis/api';
|
import { api } from '#adonis/api';
|
||||||
|
|
||||||
export type ApiRouteName = (typeof api.routes)[number]['name'];
|
export type ApiRouteName = (typeof api.routes)[number]['name'];
|
||||||
|
|
||||||
|
export type CollectionListDisplay = 'list' | 'inline';
|
||||||
|
export type LinkListDisplay = 'list' | 'grid';
|
||||||
|
|
||||||
|
export type DisplayPreferences = {
|
||||||
|
linkListDisplay: LinkListDisplay;
|
||||||
|
collectionListDisplay: CollectionListDisplay;
|
||||||
|
};
|
||||||
|
|||||||
@@ -27,6 +27,13 @@ export default await Env.create(new URL('../', import.meta.url), {
|
|||||||
|
|
||||||
/*
|
/*
|
||||||
|----------------------------------------------------------
|
|----------------------------------------------------------
|
||||||
|
| Variables for configuring app url
|
||||||
|
|----------------------------------------------------------
|
||||||
|
*/
|
||||||
|
APP_URL: Env.schema.string({ format: 'url', tld: false }), // Remove TLD to allow localhost
|
||||||
|
|
||||||
|
/*
|
||||||
|
|----------------------------------------------------------
|
||||||
| Variables for configuring database connection
|
| Variables for configuring database connection
|
||||||
|----------------------------------------------------------
|
|----------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
@@ -43,5 +50,4 @@ export default await Env.create(new URL('../', import.meta.url), {
|
|||||||
*/
|
*/
|
||||||
GOOGLE_CLIENT_ID: Env.schema.string(),
|
GOOGLE_CLIENT_ID: Env.schema.string(),
|
||||||
GOOGLE_CLIENT_SECRET: Env.schema.string(),
|
GOOGLE_CLIENT_SECRET: Env.schema.string(),
|
||||||
GOOGLE_CLIENT_CALLBACK_URL: Env.schema.string(),
|
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user