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 = {
|
||||
request: unknown;
|
||||
response: MakeTuyauResponse<
|
||||
import('../app/links/controllers/links_controller.ts').default['showCreatePage'],
|
||||
import('../app/links/controllers/delete_link_controller.js').default['showCreatePage'],
|
||||
false
|
||||
>;
|
||||
};
|
||||
@@ -110,14 +110,14 @@ type LinksPost = {
|
||||
>
|
||||
>;
|
||||
response: MakeTuyauResponse<
|
||||
import('../app/links/controllers/links_controller.ts').default['store'],
|
||||
import('../app/links/controllers/delete_link_controller.js').default['store'],
|
||||
true
|
||||
>;
|
||||
};
|
||||
type LinksEditGetHead = {
|
||||
request: unknown;
|
||||
response: MakeTuyauResponse<
|
||||
import('../app/links/controllers/links_controller.ts').default['showEditPage'],
|
||||
import('../app/links/controllers/delete_link_controller.js').default['showEditPage'],
|
||||
false
|
||||
>;
|
||||
};
|
||||
@@ -128,7 +128,7 @@ type LinksIdPut = {
|
||||
>
|
||||
>;
|
||||
response: MakeTuyauResponse<
|
||||
import('../app/links/controllers/links_controller.ts').default['update'],
|
||||
import('../app/links/controllers/delete_link_controller.js').default['update'],
|
||||
true
|
||||
>;
|
||||
};
|
||||
@@ -139,14 +139,14 @@ type LinksIdFavoritePut = {
|
||||
>
|
||||
>;
|
||||
response: MakeTuyauResponse<
|
||||
import('../app/links/controllers/links_controller.ts').default['toggleFavorite'],
|
||||
import('../app/links/controllers/delete_link_controller.js').default['toggleFavorite'],
|
||||
true
|
||||
>;
|
||||
};
|
||||
type LinksDeleteGetHead = {
|
||||
request: unknown;
|
||||
response: MakeTuyauResponse<
|
||||
import('../app/links/controllers/links_controller.ts').default['showDeletePage'],
|
||||
import('../app/links/controllers/delete_link_controller.js').default['showDeletePage'],
|
||||
false
|
||||
>;
|
||||
};
|
||||
@@ -157,7 +157,7 @@ type LinksIdDelete = {
|
||||
>
|
||||
>;
|
||||
response: MakeTuyauResponse<
|
||||
import('../app/links/controllers/links_controller.ts').default['delete'],
|
||||
import('../app/links/controllers/delete_link_controller.js').default['execute'],
|
||||
true
|
||||
>;
|
||||
};
|
||||
|
||||
14
.env.example
14
.env.example
@@ -1,16 +1,22 @@
|
||||
# node ace generate:key
|
||||
APP_KEY=soY8ZAtItT_fCkNUADfgffZUUo675lOj
|
||||
# App
|
||||
TZ=UTC
|
||||
PORT=3333
|
||||
HOST=localhost
|
||||
LOG_LEVEL=info
|
||||
LOG_LEVEL=debug
|
||||
APP_KEY=soY8ZAtItT_fCkNUADfgffZUUo675lOj # node ace generate:key
|
||||
NODE_ENV=development
|
||||
SESSION_DRIVER=cookie
|
||||
|
||||
# App url
|
||||
APP_URL=http://localhost:3333
|
||||
|
||||
# Database
|
||||
DB_HOST=127.0.0.1
|
||||
DB_PORT=5432
|
||||
DB_USER=root
|
||||
DB_PASSWORD=root
|
||||
DB_DATABASE=app
|
||||
|
||||
# Google
|
||||
GOOGLE_CLIENT_ID=
|
||||
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
|
||||
|
||||
FROM node:24.1-alpine3.20 AS base
|
||||
FROM node:24.6-alpine3.22 AS base
|
||||
|
||||
RUN apk --no-cache add curl
|
||||
RUN corepack enable
|
||||
@@ -34,9 +34,9 @@ ENV DB_PORT=5432
|
||||
ENV DB_USER=db_user
|
||||
ENV DB_PASSWORD=db_password
|
||||
ENV DB_DATABASE=db_db
|
||||
ENV APP_URL=http://localhost:3333
|
||||
ENV GOOGLE_CLIENT_ID=client_id
|
||||
ENV GOOGLE_CLIENT_SECRET=client_secret
|
||||
ENV GOOGLE_CLIENT_CALLBACK_URL=http://localhost:3333/auth/callback
|
||||
|
||||
RUN node ace izzy:routes
|
||||
RUN node ace build
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import AuthController from '#auth/controllers/auth_controller';
|
||||
import CollectionsController from '#collections/controllers/show_collections_controller';
|
||||
import LinksController from '#links/controllers/links_controller';
|
||||
import { CollectionService } from '#collections/services/collection_service';
|
||||
import LinksController from '#links/controllers/delete_link_controller';
|
||||
import User from '#user/models/user';
|
||||
import { inject } from '@adonisjs/core';
|
||||
import { HttpContext } from '@adonisjs/core/http';
|
||||
@@ -28,14 +28,14 @@ export default class AdminController {
|
||||
constructor(
|
||||
protected usersController: AuthController,
|
||||
protected linksController: LinksController,
|
||||
protected collectionsController: CollectionsController
|
||||
protected collectionService: CollectionService
|
||||
) {}
|
||||
|
||||
async index({ inertia }: HttpContext) {
|
||||
const users = await this.usersController.getAllUsersWithTotalRelations();
|
||||
const linksCount = await this.linksController.getTotalLinksCount();
|
||||
const collectionsCount =
|
||||
await this.collectionsController.getTotalCollectionsCount();
|
||||
await this.collectionService.getTotalCollectionsCount();
|
||||
|
||||
return inertia.render('admin/dashboard', {
|
||||
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 { createCollectionValidator } from '#collections/validators/create_collection_validator';
|
||||
import { inject } from '@adonisjs/core';
|
||||
import { type HttpContext } from '@adonisjs/core/http';
|
||||
|
||||
@inject()
|
||||
export default class CreateCollectionController extends BaseCollectionController {
|
||||
constructor(private collectionService: CollectionService) {
|
||||
super();
|
||||
}
|
||||
export default class CreateCollectionController {
|
||||
constructor(private collectionService: CollectionService) {}
|
||||
|
||||
async render({ inertia }: HttpContext) {
|
||||
const collections = await this.collectionService.getCollectionsByAuthorId();
|
||||
const collections =
|
||||
await this.collectionService.getCollectionsForAuthenticatedUser();
|
||||
return inertia.render('collections/create', {
|
||||
disableHomeLink: collections.length === 0,
|
||||
});
|
||||
@@ -20,6 +18,6 @@ export default class CreateCollectionController extends BaseCollectionController
|
||||
async execute({ request }: HttpContext) {
|
||||
const payload = await request.validateUsing(createCollectionValidator);
|
||||
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 { deleteCollectionValidator } from '#collections/validators/delete_collection_validator';
|
||||
import { inject } from '@adonisjs/core';
|
||||
import { HttpContext } from '@adonisjs/core/http';
|
||||
|
||||
@inject()
|
||||
export default class DeleteCollectionController extends BaseCollectionController {
|
||||
constructor(private collectionService: CollectionService) {
|
||||
super();
|
||||
}
|
||||
export default class DeleteCollectionController {
|
||||
constructor(private collectionService: CollectionService) {}
|
||||
|
||||
async render({ inertia }: HttpContext) {
|
||||
const collectionId = await this.validateCollectionId();
|
||||
const collectionId = await this.collectionService.validateCollectionId();
|
||||
if (!collectionId) return;
|
||||
|
||||
const collection =
|
||||
|
||||
@@ -1,21 +1,23 @@
|
||||
import BaseCollectionController from '#collections/controllers/base_collection_controller';
|
||||
import { CollectionService } from '#collections/services/collection_service';
|
||||
import { LinkService } from '#links/services/link_service';
|
||||
import { inject } from '@adonisjs/core';
|
||||
import type { HttpContext } from '@adonisjs/core/http';
|
||||
|
||||
@inject()
|
||||
export default class ShowCollectionsController extends BaseCollectionController {
|
||||
constructor(private collectionService: CollectionService) {
|
||||
super();
|
||||
}
|
||||
export default class ShowCollectionsController {
|
||||
constructor(
|
||||
private collectionService: CollectionService,
|
||||
private linkService: LinkService
|
||||
) {}
|
||||
|
||||
// Dashboard
|
||||
async render({ inertia, response }: HttpContext) {
|
||||
const activeCollectionId = await this.validateCollectionId(false);
|
||||
const collections = await this.collectionService.getCollectionsByAuthorId();
|
||||
if (collections.length === 0) {
|
||||
return response.redirectToNamedRoute('collection.create-form');
|
||||
}
|
||||
const activeCollectionId =
|
||||
await this.collectionService.validateCollectionId(false);
|
||||
const [collections, favoriteLinks] = await Promise.all([
|
||||
this.collectionService.getCollectionsForAuthenticatedUser(),
|
||||
this.linkService.getFavoriteLinksForAuthenticatedUser(),
|
||||
]);
|
||||
|
||||
const activeCollection = collections.find(
|
||||
(c) => c.id === activeCollectionId
|
||||
@@ -27,8 +29,8 @@ export default class ShowCollectionsController extends BaseCollectionController
|
||||
|
||||
return inertia.render('dashboard', {
|
||||
collections: collections.map((collection) => collection.serialize()),
|
||||
activeCollection:
|
||||
activeCollection?.serialize() || collections[0].serialize(),
|
||||
favoriteLinks: favoriteLinks.map((link) => link.serialize()),
|
||||
activeCollection: activeCollection?.serialize(),
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,22 +1,19 @@
|
||||
import BaseCollectionController from '#collections/controllers/base_collection_controller';
|
||||
import { CollectionService } from '#collections/services/collection_service';
|
||||
import { updateCollectionValidator } from '#collections/validators/update_collection_validator';
|
||||
import { inject } from '@adonisjs/core';
|
||||
import { HttpContext } from '@adonisjs/core/http';
|
||||
|
||||
@inject()
|
||||
export default class UpdateCollectionController extends BaseCollectionController {
|
||||
constructor(private collectionService: CollectionService) {
|
||||
super();
|
||||
}
|
||||
export default class UpdateCollectionController {
|
||||
constructor(private collectionService: CollectionService) {}
|
||||
|
||||
async render({ inertia }: HttpContext) {
|
||||
const collectionId = await this.validateCollectionId();
|
||||
const collectionId = await this.collectionService.validateCollectionId();
|
||||
if (!collectionId) return;
|
||||
|
||||
const collection =
|
||||
await this.collectionService.getCollectionById(collectionId);
|
||||
return inertia.render('collections/update', {
|
||||
return inertia.render('collections/edit', {
|
||||
collection: collection.serialize(),
|
||||
});
|
||||
}
|
||||
@@ -28,6 +25,6 @@ export default class UpdateCollectionController extends BaseCollectionController
|
||||
} = await request.validateUsing(updateCollectionValidator);
|
||||
|
||||
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 Collection from '#collections/models/collection';
|
||||
import { collectionIdValidator } from '#collections/validators/collection_id_validator';
|
||||
import { HttpContext } from '@adonisjs/core/http';
|
||||
import db from '@adonisjs/lucid/services/db';
|
||||
|
||||
@@ -20,12 +21,12 @@ export class CollectionService {
|
||||
.firstOrFail();
|
||||
}
|
||||
|
||||
async getCollectionsByAuthorId() {
|
||||
async getCollectionsForAuthenticatedUser() {
|
||||
const context = this.getAuthContext();
|
||||
return await Collection.query()
|
||||
.where('author_id', context.auth.user!.id)
|
||||
.orderBy('created_at')
|
||||
.preload('links');
|
||||
.preload('links', (q) => q.orderBy('favorite', 'desc'));
|
||||
}
|
||||
|
||||
async getTotalCollectionsCount() {
|
||||
@@ -60,11 +61,44 @@ export class CollectionService {
|
||||
.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();
|
||||
if (!context.auth.user || !context.auth.user.id) {
|
||||
throw new Error('User not authenticated');
|
||||
}
|
||||
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 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
|
||||
@@ -8,21 +16,21 @@ const LinksController = () => import('#links/controllers/links_controller');
|
||||
router
|
||||
.group(() => {
|
||||
router
|
||||
.get('/create', [LinksController, 'showCreatePage'])
|
||||
.get('/create', [CreateLinkController, 'render'])
|
||||
.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.put('/:id', [LinksController, 'update']).as('link.edit');
|
||||
router.get('/edit', [UpdateLinkController, 'render']).as('link.edit-form');
|
||||
router.put('/:id', [UpdateLinkController, 'execute']).as('link.edit');
|
||||
|
||||
router
|
||||
.put('/:id/favorite', [LinksController, 'toggleFavorite'])
|
||||
.put('/:id/favorite', [ToggleFavoriteController, 'toggleFavorite'])
|
||||
.as('link.toggle-favorite');
|
||||
|
||||
router
|
||||
.get('/delete', [LinksController, 'showDeletePage'])
|
||||
.get('/delete', [DeleteLinkController, 'render'])
|
||||
.as('link.delete-form');
|
||||
router.delete('/:id', [LinksController, 'delete']).as('link.delete');
|
||||
router.delete('/:id', [DeleteLinkController, 'execute']).as('link.delete');
|
||||
})
|
||||
.middleware([middleware.auth()])
|
||||
.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 Collection from '#collections/models/collection';
|
||||
import Link from '#links/models/link';
|
||||
import User from '#user/models/user';
|
||||
import { CollectionService } from '#collections/services/collection_service';
|
||||
import { inject } from '@adonisjs/core';
|
||||
import type { HttpContext } from '@adonisjs/core/http';
|
||||
import { getSharedCollectionValidator } from '../validators/shared_collection.js';
|
||||
|
||||
class LinkWithoutFavoriteDto {
|
||||
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(),
|
||||
});
|
||||
}
|
||||
|
||||
@inject()
|
||||
export default class SharedCollectionsController {
|
||||
constructor(private collectionService: CollectionService) {}
|
||||
|
||||
async index({ request, inertia }: HttpContext) {
|
||||
const { params } = await request.validateUsing(
|
||||
getSharedCollectionValidator
|
||||
);
|
||||
|
||||
const collection = await this.getSharedCollectionById(params.id);
|
||||
return inertia.render('shared', { collection });
|
||||
}
|
||||
|
||||
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(),
|
||||
};
|
||||
const activeCollection =
|
||||
await this.collectionService.getPublicCollectionById(params.id);
|
||||
return inertia.render('shared', { activeCollection });
|
||||
}
|
||||
}
|
||||
|
||||
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 AppBaseModel from '#core/models/app_base_model';
|
||||
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 { column, computed, hasMany } from '@adonisjs/lucid/orm';
|
||||
import type { HasMany } from '@adonisjs/lucid/types/relations';
|
||||
@@ -51,4 +53,15 @@ export default class User extends AppBaseModel {
|
||||
autoUpdate: true,
|
||||
})
|
||||
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';
|
||||
|
||||
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({
|
||||
clientId: env.get('GOOGLE_CLIENT_ID'),
|
||||
clientSecret: env.get('GOOGLE_CLIENT_SECRET'),
|
||||
callbackUrl: env.get('GOOGLE_CLIENT_CALLBACK_URL'),
|
||||
callbackUrl: env.get('APP_URL') + '/auth/callback',
|
||||
prompt: 'select_account',
|
||||
display: 'page',
|
||||
scopes: ['userinfo.email', 'userinfo.profile'],
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { isSSREnableForPage } from '#config/ssr';
|
||||
import env from '#start/env';
|
||||
import { DEFAULT_USER_THEME, KEY_USER_THEME } from '#user/constants/theme';
|
||||
import logger from '@adonisjs/core/services/logger';
|
||||
import { defineConfig } from '@adonisjs/inertia';
|
||||
@@ -24,6 +25,7 @@ export default defineConfig({
|
||||
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')
|
||||
);
|
||||
|
||||
currentPage.default.layout =
|
||||
currentPage.default.layout ||
|
||||
((p: any) => <DefaultLayout children={p} />);
|
||||
if (currentPage?.default) {
|
||||
currentPage.default.layout =
|
||||
currentPage.default.layout ||
|
||||
((p: any) => <DefaultLayout children={p} />);
|
||||
}
|
||||
|
||||
return currentPage;
|
||||
},
|
||||
|
||||
@@ -9,9 +9,13 @@ export default function render(page: any) {
|
||||
resolve: (name) => {
|
||||
const pages = import.meta.glob('../pages/**/*.tsx', { eager: true });
|
||||
let pageComponent: any = pages[`../pages/${name}.tsx`];
|
||||
pageComponent.default.layout =
|
||||
pageComponent?.default?.layout ||
|
||||
((pageChildren: any) => <DefaultLayout children={pageChildren} />);
|
||||
|
||||
if (pageComponent?.default) {
|
||||
pageComponent.default.layout =
|
||||
pageComponent.default.layout ||
|
||||
((pageChildren: any) => <DefaultLayout children={pageChildren} />);
|
||||
}
|
||||
|
||||
return pageComponent;
|
||||
},
|
||||
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 { ExternalLinkUnstyled } from '~/components/common/links/external_link_unstyled';
|
||||
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 classes from './floating_navbar.module.css';
|
||||
|
||||
@@ -40,9 +42,11 @@ export function FloatingNavbar({ width }: FloatingNavbarProps) {
|
||||
|
||||
const links = (
|
||||
<>
|
||||
<InternalLink route="dashboard" style={{ fontSize: rem(16) }}>
|
||||
Dashboard
|
||||
</InternalLink>
|
||||
{auth.isAuthenticated && (
|
||||
<InternalLink route="dashboard" style={{ fontSize: rem(16) }}>
|
||||
Dashboard
|
||||
</InternalLink>
|
||||
)}
|
||||
<ExternalLinkUnstyled
|
||||
href={PROJECT_REPO_GITHUB_URL}
|
||||
style={{ fontSize: rem(16) }}
|
||||
@@ -74,8 +78,8 @@ export function FloatingNavbar({ width }: FloatingNavbarProps) {
|
||||
</Group>
|
||||
<Group>
|
||||
{!isMobile && <Group>{links}</Group>}
|
||||
{isMobile && <Burger opened={opened} onClick={handler.toggle} />}
|
||||
{auth.isAuthenticated && <UserDropdown />}
|
||||
{isMobile && <Burger opened={opened} onClick={handler.toggle} />}
|
||||
{!auth.isAuthenticated && (
|
||||
<Button
|
||||
variant="default"
|
||||
@@ -101,6 +105,10 @@ export function FloatingNavbar({ width }: FloatingNavbarProps) {
|
||||
<Flex direction="column" gap="md">
|
||||
{links}
|
||||
</Flex>
|
||||
<Group mt="md">
|
||||
<ThemeSwitcher />
|
||||
<LocaleSwitcher />
|
||||
</Group>
|
||||
</Drawer>
|
||||
</Box>
|
||||
</>
|
||||
|
||||
@@ -10,10 +10,6 @@
|
||||
var(--mantine-color-dark-8)
|
||||
);
|
||||
}
|
||||
|
||||
@media (max-width: 768px) {
|
||||
display: none;
|
||||
}
|
||||
}
|
||||
|
||||
.userActive {
|
||||
|
||||
@@ -1,10 +1,11 @@
|
||||
import { Avatar, Group, Menu, Text, UnstyledButton } from '@mantine/core';
|
||||
import { useDisclosure } from '@mantine/hooks';
|
||||
import { modals } from '@mantine/modals';
|
||||
import cx from 'clsx';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import { TbChevronDown, TbLogout, TbUser } from 'react-icons/tb';
|
||||
import { InternalLink } from '~/components/common/links/internal_link';
|
||||
import { TbChevronDown, TbLogout, TbSettings, TbShield } from 'react-icons/tb';
|
||||
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 classes from './user_dropdown.module.css';
|
||||
|
||||
@@ -13,6 +14,14 @@ export function UserDropdown() {
|
||||
const [userMenuOpened, { open: openUserMenu, close: closeUserMenu }] =
|
||||
useDisclosure(false);
|
||||
const { t } = useTranslation();
|
||||
|
||||
const handlePreferencesModal = () => {
|
||||
modals.open({
|
||||
title: t('user-preferences'),
|
||||
children: <UserPreferences />,
|
||||
});
|
||||
};
|
||||
|
||||
return (
|
||||
<Menu
|
||||
width={260}
|
||||
@@ -41,29 +50,31 @@ export function UserDropdown() {
|
||||
</UnstyledButton>
|
||||
</Menu.Target>
|
||||
<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 && (
|
||||
<>
|
||||
<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.Item
|
||||
leftSection={<TbSettings size={16} />}
|
||||
onClick={handlePreferencesModal}
|
||||
>
|
||||
{t('common:preferences')}
|
||||
</Menu.Item>
|
||||
<Menu.Item
|
||||
leftSection={<TbLogout size={16} />}
|
||||
component={InternalLinkUnstyled}
|
||||
href="/auth/logout"
|
||||
color="inherit"
|
||||
>
|
||||
{t('common:logout')}
|
||||
</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 { useEffect, useRef } from 'react';
|
||||
import { AiFillFolderOpen, AiOutlineFolder } from 'react-icons/ai';
|
||||
import { useActiveCollection } from '~/hooks/collections/use_active_collection';
|
||||
import { appendCollectionId } from '~/lib/navigation';
|
||||
import { useActiveCollection } from '~/stores/collection_store';
|
||||
import { CollectionWithLinks } from '~/types/app';
|
||||
import classes from './collection_item.module.css';
|
||||
|
||||
export default function CollectionItem({
|
||||
collection,
|
||||
}: {
|
||||
interface CollectionItemProps {
|
||||
collection: CollectionWithLinks;
|
||||
}) {
|
||||
}
|
||||
|
||||
export function CollectionItem({ collection }: CollectionItemProps) {
|
||||
const itemRef = useRef<HTMLAnchorElement>(null);
|
||||
const { activeCollection } = useActiveCollection();
|
||||
const activeCollection = useActiveCollection();
|
||||
const isActiveCollection = collection.id === activeCollection?.id;
|
||||
const FolderIcon = isActiveCollection ? AiFillFolderOpen : AiOutlineFolder;
|
||||
|
||||
@@ -34,7 +34,10 @@ export default function CollectionItem({
|
||||
title={collection.name}
|
||||
>
|
||||
<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}
|
||||
</Text>
|
||||
</Link>
|
||||
|
||||
@@ -1,50 +1,12 @@
|
||||
import { router } from '@inertiajs/react';
|
||||
import { route } from '@izzyjs/route/client';
|
||||
import { Box, ScrollArea, Text } from '@mantine/core';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import CollectionItem from '~/components/dashboard/collection/item/collection_item';
|
||||
import useShortcut from '~/hooks/use_shortcut';
|
||||
import { appendCollectionId } from '~/lib/navigation';
|
||||
import { useActiveCollection, useCollections } from '~/stores/collection_store';
|
||||
import { useCollections } from '~/hooks/collections/use_collections';
|
||||
import styles from './collection_list.module.css';
|
||||
|
||||
export default function CollectionList() {
|
||||
const { t } = useTranslation('common');
|
||||
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);
|
||||
|
||||
const collections = useCollections();
|
||||
return (
|
||||
<Box className={styles.sideMenu}>
|
||||
<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 { IoTrashOutline } from 'react-icons/io5';
|
||||
import { ShareCollection } from '~/components/share/share_collection';
|
||||
import { useActiveCollection } from '~/hooks/collections/use_active_collection';
|
||||
import { appendCollectionId } from '~/lib/navigation';
|
||||
import { useActiveCollection } from '~/stores/collection_store';
|
||||
import { Visibility } from '~/types/app';
|
||||
|
||||
interface DashboardHeaderProps {
|
||||
@@ -32,7 +32,7 @@ interface DashboardHeaderProps {
|
||||
}
|
||||
export function DashboardHeader({ navbar, aside }: DashboardHeaderProps) {
|
||||
const { t } = useTranslation('common');
|
||||
const { activeCollection } = useActiveCollection();
|
||||
const activeCollection = useActiveCollection();
|
||||
return (
|
||||
<AppShell.Header style={{ display: 'flex', alignItems: 'center' }}>
|
||||
<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 { FavoriteList } from '~/components/dashboard/favorite/favorite_list';
|
||||
import { SearchSpotlight } from '~/components/search/search';
|
||||
import { useActiveCollection } from '~/hooks/collections/use_active_collection';
|
||||
import { useAuth } from '~/hooks/use_auth';
|
||||
import useShortcut from '~/hooks/use_shortcut';
|
||||
import { appendCollectionId } from '~/lib/navigation';
|
||||
import { useActiveCollection } from '~/stores/collection_store';
|
||||
import { useGlobalHotkeysStore } from '~/stores/global_hotkeys_store';
|
||||
|
||||
interface DashboardNavbarProps {
|
||||
@@ -34,7 +34,7 @@ export function DashboardNavbar({ isOpen, toggle }: DashboardNavbarProps) {
|
||||
const { t } = useTranslation('common');
|
||||
const { isAuthenticated, user } = useAuth();
|
||||
|
||||
const { activeCollection } = useActiveCollection();
|
||||
const activeCollection = useActiveCollection();
|
||||
const { globalHotkeysEnabled, setGlobalHotkeysEnabled } =
|
||||
useGlobalHotkeysStore();
|
||||
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
import { Flex, Group, Stack, Text } from '@mantine/core';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
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() {
|
||||
const { t } = useTranslation('common');
|
||||
const { favorites } = useFavorites();
|
||||
const favoriteLinks = useFavoriteLinks();
|
||||
|
||||
if (favorites.length === 0) {
|
||||
if (favoriteLinks.length === 0) {
|
||||
return (
|
||||
<Group justify="center">
|
||||
<Text c="dimmed" size="sm" mt="sm">
|
||||
@@ -20,10 +20,10 @@ export function FavoriteList() {
|
||||
return (
|
||||
<Flex direction="column">
|
||||
<Text c="dimmed" mt="xs" ml="md" mb={4}>
|
||||
{t('favorite')} • {favorites.length}
|
||||
{t('favorite')} • {favoriteLinks.length}
|
||||
</Text>
|
||||
<Stack gap={4}>
|
||||
{favorites.map((link) => (
|
||||
{favoriteLinks.map((link) => (
|
||||
<FavoriteItem link={link} key={link.id} />
|
||||
))}
|
||||
</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 { ActionIcon, Menu } from '@mantine/core';
|
||||
import { MouseEvent } from 'react';
|
||||
@@ -10,7 +10,6 @@ import { IoTrashOutline } from 'react-icons/io5';
|
||||
import { MdFavorite, MdFavoriteBorder } from 'react-icons/md';
|
||||
import { onFavorite } from '~/lib/favorite';
|
||||
import { appendCollectionId, appendLinkId } from '~/lib/navigation';
|
||||
import { useFavorites } from '~/stores/collection_store';
|
||||
import { Link, PublicLink } from '~/types/app';
|
||||
|
||||
interface LinksControlsProps {
|
||||
@@ -21,10 +20,14 @@ export default function LinkControls({
|
||||
link,
|
||||
showGoToCollection = false,
|
||||
}: LinksControlsProps) {
|
||||
const { toggleFavorite } = useFavorites();
|
||||
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>) =>
|
||||
event.preventDefault();
|
||||
|
||||
|
||||
@@ -28,7 +28,13 @@ export function LinkItem({ link, hideMenu: hideMenu = false }: LinkItemProps) {
|
||||
{!hideMenu && <LinkControls link={link} />}
|
||||
</Group>
|
||||
{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}
|
||||
</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 { 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 {
|
||||
hideMenu?: boolean;
|
||||
}
|
||||
|
||||
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 (
|
||||
<Stack gap="xs">
|
||||
{activeCollection?.links.map((link) => (
|
||||
<LinkItem link={link} key={link.id} hideMenu={hideMenu} />
|
||||
))}
|
||||
<SimpleGrid cols={getColsByView(displayPreferences)} spacing="xs">
|
||||
{links.map((link) => (
|
||||
<LinkItem link={link} key={link.id} hideMenu={hideMenu} />
|
||||
))}
|
||||
</SimpleGrid>
|
||||
</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 { useTranslation } from 'react-i18next';
|
||||
import type { LinkListProps } from '~/components/dashboard/link/list/link_list';
|
||||
import { useActiveCollection } from '~/hooks/collections/use_active_collection';
|
||||
import { appendCollectionId } from '~/lib/navigation';
|
||||
import { useActiveCollection } from '~/stores/collection_store';
|
||||
import styles from './no_link.module.css';
|
||||
|
||||
interface NoLinkProps extends LinkListProps {}
|
||||
|
||||
export function NoLink({ hideMenu }: NoLinkProps) {
|
||||
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 (
|
||||
<Box className={styles.noCollection} p="xl">
|
||||
<Text
|
||||
className={styles.text}
|
||||
dangerouslySetInnerHTML={{
|
||||
__html: t(
|
||||
'home:no-link',
|
||||
{ name: activeCollection?.name ?? '' } as any,
|
||||
{
|
||||
interpolation: { escapeValue: false },
|
||||
}
|
||||
),
|
||||
__html: isFavorite ? noLinkForFavorite : noLinkForCollection,
|
||||
}}
|
||||
/>
|
||||
{!hideMenu && (
|
||||
{!hideMenu && !isFavorite && (
|
||||
<Anchor
|
||||
component={Link}
|
||||
href={appendCollectionId(
|
||||
|
||||
@@ -2,6 +2,7 @@ import { Box, Group, SegmentedControl, Text, TextInput } from '@mantine/core';
|
||||
import { FormEvent } from 'react';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import BackToDashboard from '~/components/common/navigation/back_to_dashboard';
|
||||
import useSearchParam from '~/hooks/use_search_param';
|
||||
import { FormLayout, FormLayoutProps } from '~/layouts/form_layout';
|
||||
import { Visibility } from '~/types/app';
|
||||
|
||||
@@ -29,6 +30,7 @@ export default function MantineFormCollection({
|
||||
...props
|
||||
}: FormCollectionProps) {
|
||||
const { t } = useTranslation('common');
|
||||
const collectionId = Number(useSearchParam('collectionId'));
|
||||
|
||||
const onSubmit = (event: FormEvent<HTMLFormElement>) => {
|
||||
event.preventDefault();
|
||||
@@ -36,7 +38,7 @@ export default function MantineFormCollection({
|
||||
};
|
||||
|
||||
return (
|
||||
<FormLayout handleSubmit={onSubmit} {...props}>
|
||||
<FormLayout handleSubmit={onSubmit} collectionId={collectionId} {...props}>
|
||||
<BackToDashboard disabled={props.disableHomeLink}>
|
||||
<TextInput
|
||||
label={t('form.name')}
|
||||
|
||||
@@ -2,15 +2,15 @@ import { ActionIcon, Anchor, CopyButton, Popover, Text } from '@mantine/core';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import { TbShare3 } from 'react-icons/tb';
|
||||
import { Fragment } from 'react/jsx-runtime';
|
||||
import { useActiveCollection } from '~/hooks/collections/use_active_collection';
|
||||
import { generateShareUrl } from '~/lib/navigation';
|
||||
import { useActiveCollection } from '~/stores/collection_store';
|
||||
import { Visibility } from '~/types/app';
|
||||
|
||||
const COPY_SUCCESS_TIMEOUT = 2_000;
|
||||
|
||||
export function ShareCollection() {
|
||||
const { t } = useTranslation('common');
|
||||
const { activeCollection } = useActiveCollection();
|
||||
const activeCollection = useActiveCollection();
|
||||
if (
|
||||
activeCollection?.visibility !== Visibility.PUBLIC ||
|
||||
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 { useHotkeys } from 'react-hotkeys-hook';
|
||||
import { useHotkeys } from '@mantine/hooks';
|
||||
import { useGlobalHotkeysStore } from '~/stores/global_hotkeys_store';
|
||||
|
||||
type ShortcutOptions = {
|
||||
@@ -16,15 +16,12 @@ export default function useShortcut(
|
||||
}
|
||||
) {
|
||||
const { globalHotkeysEnabled } = useGlobalHotkeysStore();
|
||||
const isEnabled = disableGlobalCheck
|
||||
? enabled
|
||||
: enabled && globalHotkeysEnabled;
|
||||
return useHotkeys(
|
||||
KEYS[key],
|
||||
(event) => {
|
||||
event.preventDefault();
|
||||
cb();
|
||||
},
|
||||
{
|
||||
enabled: disableGlobalCheck ? enabled : enabled && globalHotkeysEnabled,
|
||||
enableOnFormTags: ['INPUT'],
|
||||
}
|
||||
[[KEYS[key], () => isEnabled && cb(), { preventDefault: true }]],
|
||||
undefined,
|
||||
true
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1,35 +1,35 @@
|
||||
{
|
||||
"slogan": "Manage your links in the best possible way",
|
||||
"confirm": "Confirm",
|
||||
"cancel": "Cancel",
|
||||
"slogan": "Manage your links in the best possible way",
|
||||
"confirm": "Confirm",
|
||||
"cancel": "Cancel",
|
||||
"home": "Home",
|
||||
"back-home": "← Back to home",
|
||||
"logout": "Logout",
|
||||
"login": "Login",
|
||||
"link": {
|
||||
"links": "Links",
|
||||
"link": "Link URL",
|
||||
"name": "Link name",
|
||||
"description": "Link description",
|
||||
"create": "Create a link",
|
||||
"edit": "Edit a link",
|
||||
"delete": "Delete a link",
|
||||
"delete-confirm": "Confirm deletion?"
|
||||
},
|
||||
"collection": {
|
||||
"collections": "Collection",
|
||||
"collections_other": "Collections",
|
||||
"name": "Collection name",
|
||||
"description": "Collection description",
|
||||
"no-description": "No description",
|
||||
"visibility": "Public",
|
||||
"create": "Create a collection",
|
||||
"edit": "Edit a collection",
|
||||
"delete": "Delete a collection",
|
||||
"delete-confirm": "Confirm deletion?",
|
||||
"delete-description": "You must delete all links in this collection before you can delete this collection.",
|
||||
"back-home": "← Back to home",
|
||||
"logout": "Logout",
|
||||
"login": "Login",
|
||||
"link": {
|
||||
"links": "Links",
|
||||
"link": "Link URL",
|
||||
"name": "Link name",
|
||||
"description": "Link description",
|
||||
"create": "Create a link",
|
||||
"edit": "Edit a link",
|
||||
"delete": "Delete a link",
|
||||
"delete-confirm": "Confirm deletion?"
|
||||
},
|
||||
"collection": {
|
||||
"collections": "Collection",
|
||||
"collections_other": "Collections",
|
||||
"name": "Collection name",
|
||||
"description": "Collection description",
|
||||
"no-description": "No description",
|
||||
"visibility": "Public",
|
||||
"create": "Create a collection",
|
||||
"edit": "Edit a collection",
|
||||
"delete": "Delete a collection",
|
||||
"delete-confirm": "Confirm deletion?",
|
||||
"delete-description": "You must delete all links in this collection before you can delete this collection.",
|
||||
"managed-by": "Collection managed by <b>{{name}}</b>"
|
||||
},
|
||||
},
|
||||
"form": {
|
||||
"name": "Name",
|
||||
"description": "Description",
|
||||
@@ -49,38 +49,47 @@
|
||||
"private": "Privé",
|
||||
"public": "Public"
|
||||
},
|
||||
"favorite": "Favorite",
|
||||
"add-favorite": "Add to favorites",
|
||||
"remove-favorite": "Remove from favorites",
|
||||
"favorites-appears-here": "Your favorites will appear here",
|
||||
"go-to-collection": "Go to collection",
|
||||
"no-item-found": "No item found",
|
||||
"admin": "Administrator",
|
||||
"favorite": "Favorite",
|
||||
"add-favorite": "Add to favorites",
|
||||
"remove-favorite": "Remove from favorites",
|
||||
"favorites-appears-here": "Your favorites will appear here",
|
||||
"go-to-collection": "Go to collection",
|
||||
"no-item-found": "No item found",
|
||||
"admin": "Admin",
|
||||
"manage-users": "Manage users",
|
||||
"user": "User",
|
||||
"search": "Search",
|
||||
"search-with": "Search with",
|
||||
"avatar": "{{name}}'s avatar",
|
||||
"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.",
|
||||
"retry": "Retry",
|
||||
"privacy": "Privacy",
|
||||
"terms": "Terms of use",
|
||||
"language": {
|
||||
"fr": "Français",
|
||||
"en": "English"
|
||||
},
|
||||
"lang": "Language",
|
||||
"settings": "Settings",
|
||||
"profile": "Profile",
|
||||
"select-your-lang": "Change the language",
|
||||
"name": "Name",
|
||||
"email": "Email",
|
||||
"member-since": "Member since",
|
||||
"footer": {
|
||||
"made_by": "Made with ❤\uFE0F by"
|
||||
},
|
||||
"search": "Search",
|
||||
"search-with": "Search with",
|
||||
"avatar": "{{name}}'s avatar",
|
||||
"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.",
|
||||
"retry": "Retry",
|
||||
"privacy": "Privacy",
|
||||
"terms": "Terms of use",
|
||||
"language": {
|
||||
"fr": "Français",
|
||||
"en": "English"
|
||||
},
|
||||
"lang": "Language",
|
||||
"settings": "Settings",
|
||||
"profile": "Profile",
|
||||
"select-your-lang": "Change the language",
|
||||
"name": "Name",
|
||||
"email": "Email",
|
||||
"member-since": "Member since",
|
||||
"footer": {
|
||||
"made_by": "Made with ❤\uFE0F by"
|
||||
},
|
||||
"loading": "Loading...",
|
||||
"no-results": "No results found",
|
||||
"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",
|
||||
"or-create-one": "or create one",
|
||||
"no-link": "No link for <b>{{name}}</b>"
|
||||
"select-collection": "Please select a collection",
|
||||
"or-create-one": "or create one",
|
||||
"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",
|
||||
"confirm": "Confirmer",
|
||||
"cancel": "Annuler",
|
||||
"slogan": "Gérez vos liens de la meilleure des façons",
|
||||
"confirm": "Confirmer",
|
||||
"cancel": "Annuler",
|
||||
"home": "Accueil",
|
||||
"back-home": "← Revenir à l'accueil",
|
||||
"logout": "Déconnexion",
|
||||
"login": "Connexion",
|
||||
"link": {
|
||||
"links": "Liens",
|
||||
"link": "URL du lien",
|
||||
"name": "Nom du lien",
|
||||
"description": "Description du lien",
|
||||
"create": "Créer un lien",
|
||||
"edit": "Modifier un lien",
|
||||
"delete": "Supprimer un lien",
|
||||
"delete-confirm": "Confirmer la suppression ?"
|
||||
},
|
||||
"collection": {
|
||||
"collections": "Collection",
|
||||
"collections_other": "Collections",
|
||||
"name": "Nom de la collection",
|
||||
"description": "Description de la collection",
|
||||
"no-description": "Aucune description",
|
||||
"visibility": "Public",
|
||||
"create": "Créer une collection",
|
||||
"edit": "Modifier une collection",
|
||||
"delete": "Supprimer une collection",
|
||||
"delete-confirm": "Confirmer la suppression ?",
|
||||
"delete-description": "Vous devez supprimer tous les liens de cette collection avant de pouvoir supprimer cette collection",
|
||||
"back-home": "← Revenir à l'accueil",
|
||||
"logout": "Déconnexion",
|
||||
"login": "Connexion",
|
||||
"link": {
|
||||
"links": "Liens",
|
||||
"link": "URL du lien",
|
||||
"name": "Nom du lien",
|
||||
"description": "Description du lien",
|
||||
"create": "Créer un lien",
|
||||
"edit": "Modifier un lien",
|
||||
"delete": "Supprimer un lien",
|
||||
"delete-confirm": "Confirmer la suppression ?"
|
||||
},
|
||||
"collection": {
|
||||
"collections": "Collection",
|
||||
"collections_other": "Collections",
|
||||
"name": "Nom de la collection",
|
||||
"description": "Description de la collection",
|
||||
"no-description": "Aucune description",
|
||||
"visibility": "Public",
|
||||
"create": "Créer une collection",
|
||||
"edit": "Modifier une collection",
|
||||
"delete": "Supprimer une collection",
|
||||
"delete-confirm": "Confirmer la suppression ?",
|
||||
"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>"
|
||||
},
|
||||
},
|
||||
"form": {
|
||||
"name": "Nom",
|
||||
"description": "Description",
|
||||
@@ -49,38 +49,47 @@
|
||||
"private": "Privé",
|
||||
"public": "Public"
|
||||
},
|
||||
"favorite": "Favoris",
|
||||
"add-favorite": "Ajouter aux favoris",
|
||||
"remove-favorite": "Retirer des favoris",
|
||||
"favorites-appears-here": "Vos favoris apparaîtront ici",
|
||||
"go-to-collection": "Voir la collection",
|
||||
"no-item-found": "Aucun élément trouvé",
|
||||
"admin": "Administrateur",
|
||||
"favorite": "Favoris",
|
||||
"add-favorite": "Ajouter aux favoris",
|
||||
"remove-favorite": "Retirer des favoris",
|
||||
"favorites-appears-here": "Vos favoris apparaîtront ici",
|
||||
"go-to-collection": "Voir la collection",
|
||||
"no-item-found": "Aucun élément trouvé",
|
||||
"admin": "Admin",
|
||||
"manage-users": "Gestion des utilisateurs",
|
||||
"user": "Utilisateur",
|
||||
"search": "Rechercher",
|
||||
"search-with": "Rechercher avec",
|
||||
"avatar": "Avatar de {{name}}",
|
||||
"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.",
|
||||
"retry": "Recommencer",
|
||||
"privacy": "Confidentialité",
|
||||
"terms": "CGU",
|
||||
"language": {
|
||||
"fr": "Français",
|
||||
"en": "English"
|
||||
},
|
||||
"lang": "Langage",
|
||||
"settings": "Paramètres",
|
||||
"profile": "Profil",
|
||||
"select-your-lang": "Modifier la langue",
|
||||
"name": "Nom",
|
||||
"email": "Email",
|
||||
"member-since": "Membre depuis",
|
||||
"footer": {
|
||||
"made_by": "Fait avec ❤\uFE0F par"
|
||||
},
|
||||
"search": "Rechercher",
|
||||
"search-with": "Rechercher avec",
|
||||
"avatar": "Avatar de {{name}}",
|
||||
"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.",
|
||||
"retry": "Recommencer",
|
||||
"privacy": "Confidentialité",
|
||||
"terms": "CGU",
|
||||
"language": {
|
||||
"fr": "Français",
|
||||
"en": "English"
|
||||
},
|
||||
"lang": "Langage",
|
||||
"settings": "Paramètres",
|
||||
"profile": "Profil",
|
||||
"select-your-lang": "Modifier la langue",
|
||||
"name": "Nom",
|
||||
"email": "Email",
|
||||
"member-since": "Membre depuis",
|
||||
"footer": {
|
||||
"made_by": "Fait avec ❤\uFE0F par"
|
||||
},
|
||||
"loading": "Chargement...",
|
||||
"no-results": "Aucun résultat trouvé",
|
||||
"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",
|
||||
"or-create-one": "ou en créer une",
|
||||
"no-link": "Aucun lien pour <b>{{name}}</b>"
|
||||
"select-collection": "Veuillez sélectionner une collection",
|
||||
"or-create-one": "ou en créer une",
|
||||
"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 { PRIMARY_COLOR } from '#config/project';
|
||||
import { PageProps } from '@adonisjs/inertia/types';
|
||||
import { router, usePage } from '@inertiajs/react';
|
||||
import { router } from '@inertiajs/react';
|
||||
import {
|
||||
ColorSchemeScript,
|
||||
createTheme,
|
||||
@@ -9,12 +8,14 @@ import {
|
||||
rem,
|
||||
} from '@mantine/core';
|
||||
import '@mantine/core/styles.css';
|
||||
import { ModalsProvider } from '@mantine/modals';
|
||||
import '@mantine/spotlight/styles.css';
|
||||
import { createTuyau } from '@tuyau/client';
|
||||
import { TuyauProvider } from '@tuyau/inertia/react';
|
||||
import dayjs from 'dayjs';
|
||||
import { ReactNode, useEffect } from 'react';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import { useAppUrl } from '~/hooks/use_app_url';
|
||||
import '../styles/index.css';
|
||||
|
||||
const TRANSITION_IN_CLASS = '__transition_fadeIn';
|
||||
@@ -73,12 +74,12 @@ const customTheme = createTheme({
|
||||
|
||||
export function BaseLayout({ children }: { children: ReactNode }) {
|
||||
const { i18n } = useTranslation();
|
||||
const appUrl = useAppUrl();
|
||||
dayjs.locale(i18n.language);
|
||||
const { props } = usePage<PageProps & { appBaseUrl: string }>();
|
||||
|
||||
const tuyauClient = createTuyau({
|
||||
api,
|
||||
baseUrl: props.appBaseUrl,
|
||||
baseUrl: appUrl,
|
||||
});
|
||||
|
||||
const findAppElement = () => document.getElementById('app');
|
||||
@@ -119,7 +120,9 @@ export function BaseLayout({ children }: { children: ReactNode }) {
|
||||
return (
|
||||
<TuyauProvider client={tuyauClient}>
|
||||
<ColorSchemeScript />
|
||||
<MantineProvider theme={customTheme}>{children}</MantineProvider>
|
||||
<MantineProvider theme={customTheme}>
|
||||
<ModalsProvider>{children}</ModalsProvider>
|
||||
</MantineProvider>
|
||||
</TuyauProvider>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -31,7 +31,7 @@ const Layout = ({ children }: PropsWithChildren) => (
|
||||
maxWidth: '100%',
|
||||
width: LAYOUT_WIDTH,
|
||||
marginInline: 'auto',
|
||||
marginBlock: rem(60),
|
||||
marginBlock: rem(30),
|
||||
}}
|
||||
>
|
||||
{children}
|
||||
|
||||
@@ -70,7 +70,7 @@ function FormLayout({
|
||||
{!disableHomeLink && (
|
||||
<Anchor
|
||||
component={Link}
|
||||
href={appendCollectionId(route('dashboard').url, collectionId)}
|
||||
href={appendCollectionId(route('dashboard').path, collectionId)}
|
||||
disabled={disableHomeLink}
|
||||
>
|
||||
{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 { useDisclosure } from '@mantine/hooks';
|
||||
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 { Link } from '@inertiajs/react';
|
||||
import { route } from '@izzyjs/route/client';
|
||||
import {
|
||||
useActiveCollection,
|
||||
useCollectionsSetter,
|
||||
} from '~/stores/collection_store';
|
||||
import { CollectionWithLinks } from '~/types/app';
|
||||
import classes from './dashboard.module.css';
|
||||
Box,
|
||||
Button,
|
||||
Divider,
|
||||
Group,
|
||||
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 {
|
||||
collections: CollectionWithLinks[];
|
||||
activeCollection: CollectionWithLinks;
|
||||
}
|
||||
export default function Dashboard() {
|
||||
const { t } = useTranslation();
|
||||
const { displayPreferences } = useDisplayPreferences();
|
||||
const activeCollection = useActiveCollection();
|
||||
|
||||
const HEADER_SIZE_WITH_DESCRIPTION = 60;
|
||||
const HEADER_SIZE_WITHOUT_DESCRIPTION = 50;
|
||||
|
||||
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;
|
||||
const isMobile = useIsMobile();
|
||||
const isFavorite = !activeCollection?.id;
|
||||
return (
|
||||
<DashboardLayout>
|
||||
<div className={classes.app_wrapper}>
|
||||
<AppShell
|
||||
layout="alt"
|
||||
header={{ height: headerHeight }}
|
||||
navbar={{
|
||||
width: 300,
|
||||
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 }}
|
||||
<Stack w="100%">
|
||||
<Group justify="space-between">
|
||||
<Tooltip label={t('coming-soon')}>
|
||||
<Input
|
||||
placeholder={t('search')}
|
||||
w={isMobile ? '100%' : '350px'}
|
||||
disabled
|
||||
/>
|
||||
<DashboardNavbar isOpen={openedNavbar} toggle={toggleNavbar} />
|
||||
<AppShell.Main>
|
||||
<ScrollArea
|
||||
h="calc(100vh - var(--app-shell-header-height) - var(--app-shell-footer-height, 0px))"
|
||||
p="md"
|
||||
</Tooltip>
|
||||
<Group>
|
||||
{activeCollection?.visibility === Visibility.PUBLIC && (
|
||||
<>
|
||||
<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 />
|
||||
</ScrollArea>
|
||||
</AppShell.Main>
|
||||
<DashboardAside isOpen={openedAside} toggle={toggleAside} />
|
||||
<AppShell.Footer pl="xs" pr="xs">
|
||||
<MantineFooter />
|
||||
</AppShell.Footer>
|
||||
</AppShell>
|
||||
</div>
|
||||
</DashboardLayout>
|
||||
{t('collection.edit')}
|
||||
</Button>
|
||||
)}
|
||||
|
||||
<>
|
||||
<Divider orientation="vertical" />
|
||||
<Button
|
||||
variant="light"
|
||||
component={Link}
|
||||
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 { useEffect } from 'react';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import { LinkList } from '~/components/dashboard/link/list/link_list';
|
||||
import { useCollectionsSetter } from '~/stores/collection_store';
|
||||
import type { CollectionWithLinks, PublicUser } from '~/types/app';
|
||||
|
||||
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 { setActiveCollection } = useCollectionsSetter();
|
||||
|
||||
useEffect(() => {
|
||||
setActiveCollection(collection);
|
||||
}, []);
|
||||
|
||||
return (
|
||||
<>
|
||||
<Flex direction="column">
|
||||
<Text size="xl">{collection.name}</Text>
|
||||
<Text size="xl">{activeCollection.name}</Text>
|
||||
<Text size="sm" c="dimmed">
|
||||
{collection.description}
|
||||
{activeCollection.description}
|
||||
</Text>
|
||||
<Flex justify="flex-end">
|
||||
<Text
|
||||
@@ -32,7 +24,7 @@ export default function SharedPage({ collection }: SharedPageProps) {
|
||||
mb="lg"
|
||||
dangerouslySetInnerHTML={{
|
||||
__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 = {
|
||||
id: number;
|
||||
createdAt: string;
|
||||
@@ -10,6 +12,7 @@ export type User = CommonBase & {
|
||||
avatarUrl: string;
|
||||
isAdmin: boolean;
|
||||
lastSeenAt: string;
|
||||
displayPreferences: DisplayPreferences;
|
||||
};
|
||||
|
||||
export type PublicUser = Omit<User, 'email'>;
|
||||
|
||||
40
package.json
40
package.json
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "my-links",
|
||||
"version": "3.1.3",
|
||||
"version": "3.2.0",
|
||||
"type": "module",
|
||||
"license": "GPL-3.0-only",
|
||||
"scripts": {
|
||||
@@ -8,7 +8,7 @@
|
||||
"build": "node ace build",
|
||||
"dev": "node ace serve --hmr",
|
||||
"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}'",
|
||||
"typecheck": "tsc --noEmit",
|
||||
"check": "pnpm run lint && pnpm run typecheck",
|
||||
@@ -39,25 +39,25 @@
|
||||
},
|
||||
"devDependencies": {
|
||||
"@adonisjs/assembler": "^7.8.2",
|
||||
"@adonisjs/eslint-config": "2.1.1",
|
||||
"@adonisjs/eslint-config": "2.1.2",
|
||||
"@adonisjs/prettier-config": "^1.4.5",
|
||||
"@adonisjs/tsconfig": "^1.4.1",
|
||||
"@faker-js/faker": "^9.9.0",
|
||||
"@japa/assert": "^4.1.1",
|
||||
"@japa/plugin-adonisjs": "^4.0.0",
|
||||
"@japa/runner": "^4.3.0",
|
||||
"@japa/runner": "^4.4.0",
|
||||
"@swc/core": "^1.13.3",
|
||||
"@tuyau/utils": "^0.0.9",
|
||||
"@types/luxon": "^3.7.1",
|
||||
"@types/node": "^24.2.0",
|
||||
"@types/react": "^19.1.9",
|
||||
"@types/node": "^24.3.0",
|
||||
"@types/react": "^19.1.10",
|
||||
"@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",
|
||||
"eslint": "^9.32.0",
|
||||
"eslint": "^9.33.0",
|
||||
"hot-hook": "^0.4.0",
|
||||
"husky": "^9.1.7",
|
||||
"lint-staged": "^16.1.4",
|
||||
"lint-staged": "^16.1.5",
|
||||
"pino-pretty": "^13.1.1",
|
||||
"postcss": "^8.5.6",
|
||||
"postcss-preset-mantine": "^1.18.0",
|
||||
@@ -66,7 +66,7 @@
|
||||
"release-it": "^19.0.4",
|
||||
"ts-node-maintained": "^10.9.6",
|
||||
"typescript": "~5.9.2",
|
||||
"vite": "^7.0.6"
|
||||
"vite": "^7.1.3"
|
||||
},
|
||||
"dependencies": {
|
||||
"@adonisjs/ally": "^5.1.0",
|
||||
@@ -79,11 +79,12 @@
|
||||
"@adonisjs/shield": "^8.2.0",
|
||||
"@adonisjs/static": "^1.1.1",
|
||||
"@adonisjs/vite": "^4.0.0",
|
||||
"@inertiajs/react": "^2.0.17",
|
||||
"@inertiajs/react": "^2.1.2",
|
||||
"@izzyjs/route": "^1.2.0",
|
||||
"@mantine/core": "^8.2.3",
|
||||
"@mantine/hooks": "^8.2.3",
|
||||
"@mantine/spotlight": "^8.2.3",
|
||||
"@mantine/core": "^8.2.5",
|
||||
"@mantine/hooks": "^8.2.5",
|
||||
"@mantine/modals": "^8.2.5",
|
||||
"@mantine/spotlight": "^8.2.5",
|
||||
"@tuyau/client": "^0.2.10",
|
||||
"@tuyau/core": "^0.4.2",
|
||||
"@tuyau/inertia": "^0.0.15",
|
||||
@@ -93,19 +94,18 @@
|
||||
"clsx": "^2.1.1",
|
||||
"dayjs": "^1.11.13",
|
||||
"edge.js": "^6.3.0",
|
||||
"i18next": "^25.3.2",
|
||||
"i18next": "^25.4.0",
|
||||
"knex": "^3.1.0",
|
||||
"luxon": "^3.7.1",
|
||||
"node-html-parser": "^7.0.1",
|
||||
"pg": "^8.16.3",
|
||||
"react": "^19.1.1",
|
||||
"react-dom": "^19.1.1",
|
||||
"react-hotkeys-hook": "^5.1.0",
|
||||
"react-i18next": "^15.6.1",
|
||||
"react-i18next": "^15.7.0",
|
||||
"react-icons": "^5.5.0",
|
||||
"reflect-metadata": "^0.2.2",
|
||||
"vite-plugin-pwa": "^1.0.2",
|
||||
"zustand": "^5.0.7"
|
||||
"vite-plugin-pwa": "^1.0.3",
|
||||
"zustand": "^5.0.8"
|
||||
},
|
||||
"hotHook": {
|
||||
"boundaries": [
|
||||
@@ -127,7 +127,7 @@
|
||||
"*.js,*.ts,*.jsx,*.tsx": "eslint --cache --fix"
|
||||
},
|
||||
"volta": {
|
||||
"node": "24.1.0"
|
||||
"node": "24.6.0"
|
||||
},
|
||||
"pnpm": {
|
||||
"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';
|
||||
|
||||
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
|
||||
|----------------------------------------------------------
|
||||
*/
|
||||
@@ -43,5 +50,4 @@ export default await Env.create(new URL('../', import.meta.url), {
|
||||
*/
|
||||
GOOGLE_CLIENT_ID: Env.schema.string(),
|
||||
GOOGLE_CLIENT_SECRET: Env.schema.string(),
|
||||
GOOGLE_CLIENT_CALLBACK_URL: Env.schema.string(),
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user