mirror of
https://github.com/Sonny93/my-links.git
synced 2025-12-09 15:05:35 +00:00
Compare commits
22 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
dda6fc299a | ||
|
|
b0e3bfa0f6 | ||
|
|
9d4eb08bc9 | ||
|
|
f8e7e7cd64 | ||
|
|
cda3a89f32 | ||
|
|
ed4dbca329 | ||
|
|
f8a92b7219 | ||
|
|
161db362b3 | ||
|
|
a5e542a33f | ||
|
|
f0ec6d6b3d | ||
|
|
442a1003bb | ||
|
|
2c499a7789 | ||
|
|
5baa9e1c35 | ||
|
|
fd896db872 | ||
|
|
a45d534fa0 | ||
|
|
5d083327a8 | ||
|
|
136fcfac5d | ||
|
|
efcb1d0ef9 | ||
|
|
8b9e74bfe1 | ||
|
|
73752aed32 | ||
|
|
16a4ce1761 | ||
|
|
049feab0d8 |
@@ -4,7 +4,7 @@ build
|
|||||||
coverage
|
coverage
|
||||||
.vscode
|
.vscode
|
||||||
.DS_STORE
|
.DS_STORE
|
||||||
# .env
|
.env
|
||||||
tmp
|
tmp
|
||||||
storage
|
storage
|
||||||
|
|
||||||
|
|||||||
@@ -1,8 +1,9 @@
|
|||||||
|
# node ace generate:key
|
||||||
|
APP_KEY=soY8ZAtItT_fCkNUADfgffZUUo675lOj
|
||||||
TZ=UTC
|
TZ=UTC
|
||||||
PORT=3333
|
PORT=3333
|
||||||
HOST=localhost
|
HOST=localhost
|
||||||
LOG_LEVEL=info
|
LOG_LEVEL=info
|
||||||
APP_KEY=sLoJth45JD1vcS8n92Y2JUd8w3OL4HQb
|
|
||||||
NODE_ENV=development
|
NODE_ENV=development
|
||||||
SESSION_DRIVER=cookie
|
SESSION_DRIVER=cookie
|
||||||
DB_HOST=127.0.0.1
|
DB_HOST=127.0.0.1
|
||||||
@@ -12,4 +13,4 @@ DB_PASSWORD=my-links-pwd
|
|||||||
DB_DATABASE=my-links
|
DB_DATABASE=my-links
|
||||||
GOOGLE_CLIENT_ID=
|
GOOGLE_CLIENT_ID=
|
||||||
GOOGLE_CLIENT_SECRET=
|
GOOGLE_CLIENT_SECRET=
|
||||||
GOOGLE_CLIENT_CALLBACK_URL=http://localhost:3333/auth/callback
|
GOOGLE_CLIENT_CALLBACK_URL=http://localhost:3333/auth/callback
|
||||||
@@ -1,4 +1 @@
|
|||||||
#!/usr/bin/env sh
|
|
||||||
. "$(dirname -- "$0")/_/husky.sh"
|
|
||||||
|
|
||||||
npx lint-staged
|
npx lint-staged
|
||||||
|
|||||||
32
Dockerfile
32
Dockerfile
@@ -1,27 +1,43 @@
|
|||||||
# Source : https://github.com/adonisjs-community/adonis-packages/blob/main/Dockerfile
|
# Source : https://github.com/adonisjs-community/adonis-packages/blob/main/Dockerfile
|
||||||
|
|
||||||
FROM node:20-alpine3.18 as base
|
FROM node:20-alpine3.18 AS base
|
||||||
|
|
||||||
RUN apk --no-cache add curl
|
RUN apk --no-cache add curl
|
||||||
RUN corepack enable
|
RUN corepack enable
|
||||||
|
|
||||||
# All deps stage
|
# All deps stage
|
||||||
FROM base as deps
|
FROM base AS deps
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
ADD package.json package-lock.json ./
|
ADD package.json pnpm-lock.yaml ./
|
||||||
RUN npm install --ignore-scripts
|
RUN pnpm install --ignore-scripts
|
||||||
|
|
||||||
# Production only deps stage
|
# Production only deps stage
|
||||||
FROM base as production-deps
|
FROM base AS production-deps
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
ADD package.json package-lock.json ./
|
ADD package.json pnpm-lock.yaml ./
|
||||||
RUN npm install --omit="dev" --ignore-scripts
|
RUN pnpm install --ignore-scripts
|
||||||
|
|
||||||
# Build stage
|
# Build stage
|
||||||
FROM base as build
|
FROM base AS build
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
COPY --from=deps /app/node_modules /app/node_modules
|
COPY --from=deps /app/node_modules /app/node_modules
|
||||||
ADD . .
|
ADD . .
|
||||||
|
|
||||||
|
ENV PORT=3333
|
||||||
|
ENV HOST=localhost
|
||||||
|
ENV LOG_LEVEL=info
|
||||||
|
ENV APP_KEY=sLoJth45JD1vcS8n92Y2JUd8w3OL4HQb
|
||||||
|
ENV NODE_ENV=production
|
||||||
|
ENV SESSION_DRIVER=cookie
|
||||||
|
ENV DB_HOST=127.0.0.1
|
||||||
|
ENV DB_PORT=5432
|
||||||
|
ENV DB_USER=db_user
|
||||||
|
ENV DB_PASSWORD=db_password
|
||||||
|
ENV DB_DATABASE=db_db
|
||||||
|
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 izzy:routes
|
||||||
RUN node ace build
|
RUN node ace build
|
||||||
|
|
||||||
|
|||||||
20
Makefile
20
Makefile
@@ -1,19 +1,19 @@
|
|||||||
dev:
|
dev:
|
||||||
docker compose down
|
@docker compose down
|
||||||
docker compose -f dev.docker-compose.yml up -d --wait
|
@docker compose -f dev.docker-compose.yml up -d --wait
|
||||||
node ace migration:fresh
|
@node ace migration:fresh
|
||||||
npm run dev
|
@pnpm run dev
|
||||||
|
|
||||||
prod:
|
prod:
|
||||||
docker compose -f dev.docker-compose.yml down
|
@docker compose -f dev.docker-compose.yml down
|
||||||
docker compose up -d --build --wait
|
@docker compose up -d --build --wait
|
||||||
|
|
||||||
seed:
|
seed:
|
||||||
node ace db:seed
|
@node ace db:seed
|
||||||
|
|
||||||
down:
|
down:
|
||||||
-docker compose down
|
@-docker compose down
|
||||||
-docker compose -f dev.docker-compose.yml down
|
@-docker compose -f dev.docker-compose.yml down
|
||||||
|
|
||||||
release:
|
release:
|
||||||
npm run release
|
@pnpm run release
|
||||||
|
|||||||
10
README.md
10
README.md
@@ -19,13 +19,13 @@ cp example.env .env
|
|||||||
make dev
|
make dev
|
||||||
```
|
```
|
||||||
|
|
||||||
### NPM
|
### PNPM
|
||||||
|
|
||||||
```shell
|
```shell
|
||||||
# reset database and (force) apply all migrations
|
# reset database and (force) apply all migrations
|
||||||
node ace migration:fresh
|
node ace migration:fresh
|
||||||
# start dev server
|
# start dev server
|
||||||
npm run dev
|
pnpm run dev
|
||||||
```
|
```
|
||||||
|
|
||||||
## Start as prod
|
## Start as prod
|
||||||
@@ -36,17 +36,17 @@ npm run dev
|
|||||||
make prod
|
make prod
|
||||||
```
|
```
|
||||||
|
|
||||||
### NPM
|
### PNPM
|
||||||
|
|
||||||
```shell
|
```shell
|
||||||
# create production build
|
# create production build
|
||||||
npm run build
|
pnpm run build
|
||||||
# go to the build folder
|
# go to the build folder
|
||||||
cd build
|
cd build
|
||||||
# clone your .env
|
# clone your .env
|
||||||
cp ../.env .
|
cp ../.env .
|
||||||
# then start the production build
|
# then start the production build
|
||||||
npm run start
|
pnpm run start
|
||||||
```
|
```
|
||||||
|
|
||||||
## Generate app_key
|
## Generate app_key
|
||||||
|
|||||||
3
ace.js
3
ace.js
@@ -19,8 +19,7 @@
|
|||||||
/**
|
/**
|
||||||
* Register hook to process TypeScript files using ts-node
|
* Register hook to process TypeScript files using ts-node
|
||||||
*/
|
*/
|
||||||
import { register } from 'node:module';
|
import 'ts-node-maintained/register/esm';
|
||||||
register('ts-node/esm', import.meta.url);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Import ace console entrypoint
|
* Import ace console entrypoint
|
||||||
|
|||||||
@@ -25,9 +25,11 @@ export default class CollectionsController {
|
|||||||
return response.redirectToNamedRoute('dashboard');
|
return response.redirectToNamedRoute('dashboard');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO: Create DTOs
|
||||||
return inertia.render('dashboard', {
|
return inertia.render('dashboard', {
|
||||||
collections,
|
collections: collections.map((collection) => collection.serialize()),
|
||||||
activeCollection: activeCollection || collections[0],
|
activeCollection:
|
||||||
|
activeCollection?.serialize() || collections[0].serialize(),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
import env from '#start/env';
|
import env from '#start/env';
|
||||||
import app from '@adonisjs/core/services/app';
|
|
||||||
import { defineConfig, stores } from '@adonisjs/session';
|
import { defineConfig, stores } from '@adonisjs/session';
|
||||||
|
|
||||||
const sessionConfig = defineConfig({
|
const sessionConfig = defineConfig({
|
||||||
@@ -16,7 +15,7 @@ const sessionConfig = defineConfig({
|
|||||||
* Define how long to keep the session data alive without
|
* Define how long to keep the session data alive without
|
||||||
* any activity.
|
* any activity.
|
||||||
*/
|
*/
|
||||||
age: '2h',
|
age: '7d',
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Configuration for session cookie and the
|
* Configuration for session cookie and the
|
||||||
@@ -25,8 +24,10 @@ const sessionConfig = defineConfig({
|
|||||||
cookie: {
|
cookie: {
|
||||||
path: '/',
|
path: '/',
|
||||||
httpOnly: true,
|
httpOnly: true,
|
||||||
secure: app.inProduction,
|
secure: true,
|
||||||
sameSite: 'lax',
|
|
||||||
|
// TODO: set this to lax and found a solution to keep auth when using extension
|
||||||
|
sameSite: 'none',
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -27,8 +27,7 @@ const shieldConfig = defineConfig({
|
|||||||
* iFrames
|
* iFrames
|
||||||
*/
|
*/
|
||||||
xFrame: {
|
xFrame: {
|
||||||
enabled: true,
|
enabled: false,
|
||||||
action: 'DENY',
|
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -8,7 +8,6 @@ export default class extends BaseSeeder {
|
|||||||
static environment = ['development', 'testing'];
|
static environment = ['development', 'testing'];
|
||||||
|
|
||||||
async run() {
|
async run() {
|
||||||
// eslint-disable-next-line unicorn/no-await-expression-member
|
|
||||||
const users = await getUserIds();
|
const users = await getUserIds();
|
||||||
|
|
||||||
const collections = faker.helpers.multiple(
|
const collections = faker.helpers.multiple(
|
||||||
@@ -26,14 +25,16 @@ export async function getUserIds() {
|
|||||||
return users.map(({ id }) => id);
|
return users.map(({ id }) => id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let collectionId = 0;
|
||||||
function createRandomCollection(userIds: User['id'][]) {
|
function createRandomCollection(userIds: User['id'][]) {
|
||||||
const authorId = faker.helpers.arrayElements(userIds, 1).at(0);
|
const authorId = faker.helpers.arrayElements(userIds, 1).at(0);
|
||||||
|
collectionId++;
|
||||||
return {
|
return {
|
||||||
id: faker.string.uuid(),
|
id: collectionId,
|
||||||
name: faker.string.alphanumeric({ length: { min: 5, max: 25 } }),
|
name: faker.string.alphanumeric({ length: { min: 5, max: 25 } }),
|
||||||
description: faker.string.alphanumeric({ length: { min: 0, max: 254 } }),
|
description: faker.string.alphanumeric({ length: { min: 0, max: 254 } }),
|
||||||
visibility: Visibility.PRIVATE,
|
visibility: Visibility.PRIVATE,
|
||||||
nextId: undefined,
|
nextId: collectionId + 1,
|
||||||
authorId,
|
authorId,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,7 +9,6 @@ export default class extends BaseSeeder {
|
|||||||
static environment = ['development', 'testing'];
|
static environment = ['development', 'testing'];
|
||||||
|
|
||||||
async run() {
|
async run() {
|
||||||
// eslint-disable-next-line unicorn/no-await-expression-member
|
|
||||||
const users = await getUserIds();
|
const users = await getUserIds();
|
||||||
|
|
||||||
const links = await Promise.all(
|
const links = await Promise.all(
|
||||||
|
|||||||
4
eslint.config.js
Normal file
4
eslint.config.js
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
import { configApp } from '@adonisjs/eslint-config';
|
||||||
|
export default configApp({
|
||||||
|
files: ['**/*.ts', '**/*.tsx', '**/*.js', '**/*.jsx'],
|
||||||
|
});
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
import styled from '@emotion/styled';
|
import styled from '@emotion/styled';
|
||||||
import { ReactNode, useRef } from 'react';
|
import { HtmlHTMLAttributes, ReactNode, useRef } from 'react';
|
||||||
import DropdownContainer from '~/components/common/dropdown/dropdown_container';
|
import DropdownContainer from '~/components/common/dropdown/dropdown_container';
|
||||||
import DropdownLabel from '~/components/common/dropdown/dropdown_label';
|
import DropdownLabel from '~/components/common/dropdown/dropdown_label';
|
||||||
import useClickOutside from '~/hooks/use_click_outside';
|
import useClickOutside from '~/hooks/use_click_outside';
|
||||||
@@ -34,8 +34,8 @@ export default function Dropdown({
|
|||||||
label,
|
label,
|
||||||
className,
|
className,
|
||||||
svgSize,
|
svgSize,
|
||||||
}: {
|
onClick,
|
||||||
children: ReactNode;
|
}: HtmlHTMLAttributes<HTMLDivElement> & {
|
||||||
label: ReactNode | string;
|
label: ReactNode | string;
|
||||||
className?: string;
|
className?: string;
|
||||||
svgSize?: number;
|
svgSize?: number;
|
||||||
@@ -49,7 +49,10 @@ export default function Dropdown({
|
|||||||
return (
|
return (
|
||||||
<DropdownStyle
|
<DropdownStyle
|
||||||
opened={isShowing}
|
opened={isShowing}
|
||||||
onClick={toggle}
|
onClick={(event) => {
|
||||||
|
onClick?.(event);
|
||||||
|
toggle();
|
||||||
|
}}
|
||||||
ref={dropdownRef}
|
ref={dropdownRef}
|
||||||
className={className}
|
className={className}
|
||||||
svgSize={svgSize}
|
svgSize={svgSize}
|
||||||
|
|||||||
22
inertia/components/common/icon_button.tsx
Normal file
22
inertia/components/common/icon_button.tsx
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
import styled from '@emotion/styled';
|
||||||
|
|
||||||
|
const IconButton = styled.button(({ theme }) => ({
|
||||||
|
cursor: 'pointer',
|
||||||
|
height: '2rem',
|
||||||
|
width: '2rem',
|
||||||
|
fontSize: '1rem',
|
||||||
|
color: theme.colors.font,
|
||||||
|
backgroundColor: theme.colors.grey,
|
||||||
|
borderRadius: '50%',
|
||||||
|
border: 0,
|
||||||
|
display: 'flex',
|
||||||
|
alignItems: 'center',
|
||||||
|
justifyContent: 'center',
|
||||||
|
|
||||||
|
'&:disabled': {
|
||||||
|
cursor: 'not-allowed',
|
||||||
|
opacity: 0.15,
|
||||||
|
},
|
||||||
|
}));
|
||||||
|
|
||||||
|
export default IconButton;
|
||||||
8
inertia/components/common/legend.tsx
Normal file
8
inertia/components/common/legend.tsx
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
import styled from '@emotion/styled';
|
||||||
|
|
||||||
|
const Legend = styled.span(({ theme }) => ({
|
||||||
|
fontSize: '13px',
|
||||||
|
color: theme.colors.grey,
|
||||||
|
}));
|
||||||
|
|
||||||
|
export default Legend;
|
||||||
218
inertia/components/common/table.tsx
Normal file
218
inertia/components/common/table.tsx
Normal file
@@ -0,0 +1,218 @@
|
|||||||
|
import styled from '@emotion/styled';
|
||||||
|
import {
|
||||||
|
ColumnDef,
|
||||||
|
flexRender,
|
||||||
|
getCoreRowModel,
|
||||||
|
getPaginationRowModel,
|
||||||
|
getSortedRowModel,
|
||||||
|
PaginationState,
|
||||||
|
useReactTable,
|
||||||
|
} from '@tanstack/react-table';
|
||||||
|
import { useState } from 'react';
|
||||||
|
import IconButton from '~/components/common/icon_button';
|
||||||
|
|
||||||
|
import {
|
||||||
|
MdKeyboardArrowLeft,
|
||||||
|
MdKeyboardArrowRight,
|
||||||
|
MdKeyboardDoubleArrowLeft,
|
||||||
|
MdKeyboardDoubleArrowRight,
|
||||||
|
} from 'react-icons/md';
|
||||||
|
import Input from '~/components/common/form/_input';
|
||||||
|
|
||||||
|
const TablePageFooter = styled.div({
|
||||||
|
display: 'flex',
|
||||||
|
gap: '1em',
|
||||||
|
alignItems: 'center',
|
||||||
|
});
|
||||||
|
|
||||||
|
const Box = styled(TablePageFooter)({
|
||||||
|
gap: '0.35em',
|
||||||
|
});
|
||||||
|
|
||||||
|
const Resizer = styled.div<{ isResizing: boolean }>(
|
||||||
|
({ theme, isResizing }) => ({
|
||||||
|
cursor: 'col-resize',
|
||||||
|
userSelect: 'none',
|
||||||
|
touchAction: 'none',
|
||||||
|
position: 'absolute',
|
||||||
|
right: 0,
|
||||||
|
top: 0,
|
||||||
|
height: '100%',
|
||||||
|
width: '5px',
|
||||||
|
opacity: !isResizing ? 0 : 1,
|
||||||
|
background: !isResizing ? theme.colors.white : theme.colors.primary,
|
||||||
|
'&:hover': {
|
||||||
|
opacity: 0.5,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
);
|
||||||
|
|
||||||
|
type TableProps<T> = {
|
||||||
|
columns: ColumnDef<T>[];
|
||||||
|
data: T[];
|
||||||
|
};
|
||||||
|
|
||||||
|
export default function Table<T>({ columns, data }: TableProps<T>) {
|
||||||
|
const [pagination, setPagination] = useState<PaginationState>({
|
||||||
|
pageIndex: 0,
|
||||||
|
pageSize: 10,
|
||||||
|
});
|
||||||
|
|
||||||
|
const table = useReactTable({
|
||||||
|
data,
|
||||||
|
columns,
|
||||||
|
enableColumnResizing: true,
|
||||||
|
columnResizeMode: 'onChange',
|
||||||
|
state: {
|
||||||
|
pagination,
|
||||||
|
},
|
||||||
|
onPaginationChange: setPagination,
|
||||||
|
getCoreRowModel: getCoreRowModel(),
|
||||||
|
getPaginationRowModel: getPaginationRowModel(),
|
||||||
|
getSortedRowModel: getSortedRowModel(),
|
||||||
|
debugTable: true,
|
||||||
|
});
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div css={{ fontSize: '0.9rem', paddingBlock: '1em' }}>
|
||||||
|
<div
|
||||||
|
css={{
|
||||||
|
maxWidth: '100%',
|
||||||
|
marginBottom: '1em',
|
||||||
|
display: 'block',
|
||||||
|
overflowX: 'auto',
|
||||||
|
overflowY: 'hidden',
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<table>
|
||||||
|
<thead>
|
||||||
|
{table.getHeaderGroups().map((headerGroup) => (
|
||||||
|
<tr key={headerGroup.id}>
|
||||||
|
{headerGroup.headers.map((header) => (
|
||||||
|
<th
|
||||||
|
key={header.id}
|
||||||
|
style={{
|
||||||
|
width: header.getSize(),
|
||||||
|
}}
|
||||||
|
css={{
|
||||||
|
position: 'relative',
|
||||||
|
userSelect: 'none',
|
||||||
|
// resizer
|
||||||
|
'&:hover > div > div': {
|
||||||
|
opacity: 0.5,
|
||||||
|
},
|
||||||
|
}}
|
||||||
|
colSpan={header.colSpan}
|
||||||
|
>
|
||||||
|
{header.isPlaceholder ? null : (
|
||||||
|
<div
|
||||||
|
css={{
|
||||||
|
cursor: header.column.getCanSort()
|
||||||
|
? 'pointer'
|
||||||
|
: 'default',
|
||||||
|
}}
|
||||||
|
onClick={header.column.getToggleSortingHandler()}
|
||||||
|
title={
|
||||||
|
header.column.getCanSort()
|
||||||
|
? header.column.getNextSortingOrder() === 'asc'
|
||||||
|
? 'Sort ascending'
|
||||||
|
: header.column.getNextSortingOrder() === 'desc'
|
||||||
|
? 'Sort descending'
|
||||||
|
: 'Clear sort'
|
||||||
|
: undefined
|
||||||
|
}
|
||||||
|
>
|
||||||
|
{flexRender(
|
||||||
|
header.column.columnDef.header,
|
||||||
|
header.getContext()
|
||||||
|
)}
|
||||||
|
{{
|
||||||
|
asc: ' 🔼',
|
||||||
|
desc: ' 🔽',
|
||||||
|
}[header.column.getIsSorted() as string] ?? null}
|
||||||
|
{header.column.getCanResize() && (
|
||||||
|
<Resizer
|
||||||
|
onMouseDown={header.getResizeHandler()}
|
||||||
|
onTouchStart={header.getResizeHandler()}
|
||||||
|
isResizing={header.column.getIsResizing()}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</th>
|
||||||
|
))}
|
||||||
|
</tr>
|
||||||
|
))}
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
{table
|
||||||
|
.getRowModel()
|
||||||
|
.rows.slice(0, 10)
|
||||||
|
.map((row) => (
|
||||||
|
<tr key={row.id}>
|
||||||
|
{row.getVisibleCells().map((cell) => (
|
||||||
|
<td key={cell.id} style={{ width: cell.column.getSize() }}>
|
||||||
|
{flexRender(
|
||||||
|
cell.column.columnDef.cell,
|
||||||
|
cell.getContext()
|
||||||
|
)}
|
||||||
|
</td>
|
||||||
|
))}
|
||||||
|
</tr>
|
||||||
|
))}
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
{table.getPageCount() > 1 && (
|
||||||
|
<TablePageFooter>
|
||||||
|
<Box>
|
||||||
|
<IconButton
|
||||||
|
onClick={() => table.setPageIndex(0)}
|
||||||
|
disabled={!table.getCanPreviousPage()}
|
||||||
|
>
|
||||||
|
<MdKeyboardDoubleArrowLeft />
|
||||||
|
</IconButton>
|
||||||
|
<IconButton
|
||||||
|
onClick={() => table.previousPage()}
|
||||||
|
disabled={!table.getCanPreviousPage()}
|
||||||
|
>
|
||||||
|
<MdKeyboardArrowLeft />
|
||||||
|
</IconButton>
|
||||||
|
<IconButton
|
||||||
|
onClick={() => table.nextPage()}
|
||||||
|
disabled={!table.getCanNextPage()}
|
||||||
|
>
|
||||||
|
<MdKeyboardArrowRight />
|
||||||
|
</IconButton>
|
||||||
|
<IconButton
|
||||||
|
onClick={() => table.setPageIndex(table.getPageCount() - 1)}
|
||||||
|
disabled={!table.getCanNextPage()}
|
||||||
|
>
|
||||||
|
<MdKeyboardDoubleArrowRight />
|
||||||
|
</IconButton>
|
||||||
|
</Box>
|
||||||
|
<Box>
|
||||||
|
<span>Page</span>
|
||||||
|
<strong>
|
||||||
|
{table.getState().pagination.pageIndex + 1} of{' '}
|
||||||
|
{table.getPageCount()}
|
||||||
|
</strong>
|
||||||
|
</Box>
|
||||||
|
<Box>
|
||||||
|
Go to page
|
||||||
|
<Input
|
||||||
|
type="number"
|
||||||
|
min="1"
|
||||||
|
max={table.getPageCount()}
|
||||||
|
defaultValue={table.getState().pagination.pageIndex + 1}
|
||||||
|
onChange={(e) => {
|
||||||
|
const page = e.target.value ? Number(e.target.value) - 1 : 0;
|
||||||
|
table.setPageIndex(page);
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
</Box>
|
||||||
|
</TablePageFooter>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -7,7 +7,7 @@ import FavoritesContext from '~/contexts/favorites_context';
|
|||||||
import GlobalHotkeysContext from '~/contexts/global_hotkeys_context';
|
import GlobalHotkeysContext from '~/contexts/global_hotkeys_context';
|
||||||
import useShortcut from '~/hooks/use_shortcut';
|
import useShortcut from '~/hooks/use_shortcut';
|
||||||
import { appendCollectionId } from '~/lib/navigation';
|
import { appendCollectionId } from '~/lib/navigation';
|
||||||
import { CollectionWithLinks, Link } from '~/types/app';
|
import { CollectionWithLinks, LinkWithCollection } from '~/types/app';
|
||||||
|
|
||||||
export default function DashboardProviders(
|
export default function DashboardProviders(
|
||||||
props: Readonly<{
|
props: Readonly<{
|
||||||
@@ -31,14 +31,18 @@ export default function DashboardProviders(
|
|||||||
router.visit(appendCollectionId(route('dashboard').url, collection.id));
|
router.visit(appendCollectionId(route('dashboard').url, collection.id));
|
||||||
};
|
};
|
||||||
|
|
||||||
const favorites = useMemo<Link[]>(
|
// TODO: compute this in controller
|
||||||
|
const favorites = useMemo<LinkWithCollection[]>(
|
||||||
() =>
|
() =>
|
||||||
collections.reduce((acc, collection) => {
|
collections.reduce((acc, collection) => {
|
||||||
collection.links.forEach((link) =>
|
collection.links.forEach((link) => {
|
||||||
link.favorite ? acc.push(link) : null
|
if (link.favorite) {
|
||||||
);
|
const newLink: LinkWithCollection = { ...link, collection };
|
||||||
|
acc.push(newLink);
|
||||||
|
}
|
||||||
|
});
|
||||||
return acc;
|
return acc;
|
||||||
}, [] as Link[]),
|
}, [] as LinkWithCollection[]),
|
||||||
[collections]
|
[collections]
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -76,6 +80,7 @@ export default function DashboardProviders(
|
|||||||
enabled: globalHotkeysEnabled,
|
enabled: globalHotkeysEnabled,
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<CollectionsContext.Provider value={collectionsContextValue}>
|
<CollectionsContext.Provider value={collectionsContextValue}>
|
||||||
<ActiveCollectionContext.Provider value={activeCollectionContextValue}>
|
<ActiveCollectionContext.Provider value={activeCollectionContextValue}>
|
||||||
|
|||||||
@@ -1,71 +1,18 @@
|
|||||||
import { useTheme } from '@emotion/react';
|
import { useTheme } from '@emotion/react';
|
||||||
import styled from '@emotion/styled';
|
|
||||||
import { route } from '@izzyjs/route/client';
|
import { route } from '@izzyjs/route/client';
|
||||||
import { useCallback } from 'react';
|
|
||||||
import { useTranslation } from 'react-i18next';
|
import { useTranslation } from 'react-i18next';
|
||||||
import { AiFillStar, AiOutlineStar } from 'react-icons/ai';
|
|
||||||
import { BsThreeDotsVertical } from 'react-icons/bs';
|
import { BsThreeDotsVertical } from 'react-icons/bs';
|
||||||
import { GoPencil } from 'react-icons/go';
|
import { GoPencil } from 'react-icons/go';
|
||||||
import { IoTrashOutline } from 'react-icons/io5';
|
import { IoTrashOutline } from 'react-icons/io5';
|
||||||
import Dropdown from '~/components/common/dropdown/dropdown';
|
import Dropdown from '~/components/common/dropdown/dropdown';
|
||||||
import {
|
import { DropdownItemLink } from '~/components/common/dropdown/dropdown_item';
|
||||||
DropdownItemButton,
|
import FavoriteDropdownItem from '~/components/dashboard/side_nav/favorite/favorite_dropdown_item';
|
||||||
DropdownItemLink,
|
|
||||||
} from '~/components/common/dropdown/dropdown_item';
|
|
||||||
import useActiveCollection from '~/hooks/use_active_collection';
|
|
||||||
import useCollections from '~/hooks/use_collections';
|
|
||||||
import { appendLinkId } from '~/lib/navigation';
|
import { appendLinkId } from '~/lib/navigation';
|
||||||
import { makeRequest } from '~/lib/request';
|
|
||||||
import { Link } from '~/types/app';
|
import { Link } from '~/types/app';
|
||||||
|
|
||||||
const StartItem = styled(DropdownItemButton)(({ theme }) => ({
|
|
||||||
color: theme.colors.yellow,
|
|
||||||
}));
|
|
||||||
|
|
||||||
export default function LinkControls({ link }: { link: Link }) {
|
export default function LinkControls({ link }: { link: Link }) {
|
||||||
const theme = useTheme();
|
const theme = useTheme();
|
||||||
const { t } = useTranslation('common');
|
const { t } = useTranslation('common');
|
||||||
const { collections, setCollections } = useCollections();
|
|
||||||
const { setActiveCollection } = useActiveCollection();
|
|
||||||
|
|
||||||
const toggleFavorite = useCallback(
|
|
||||||
(linkId: Link['id']) => {
|
|
||||||
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,
|
|
||||||
};
|
|
||||||
|
|
||||||
setCollections(collectionsCopy);
|
|
||||||
setActiveCollection(collectionsCopy[collectionIndex]);
|
|
||||||
},
|
|
||||||
[collections, setCollections]
|
|
||||||
);
|
|
||||||
|
|
||||||
const onFavorite = () => {
|
|
||||||
const { url, method } = route('link.toggle-favorite', {
|
|
||||||
params: { id: link.id.toString() },
|
|
||||||
});
|
|
||||||
makeRequest({
|
|
||||||
url,
|
|
||||||
method,
|
|
||||||
body: {
|
|
||||||
favorite: !link.favorite,
|
|
||||||
},
|
|
||||||
})
|
|
||||||
.then(() => toggleFavorite(link.id))
|
|
||||||
.catch(console.error);
|
|
||||||
};
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Dropdown
|
<Dropdown
|
||||||
@@ -73,17 +20,7 @@ export default function LinkControls({ link }: { link: Link }) {
|
|||||||
css={{ backgroundColor: theme.colors.secondary }}
|
css={{ backgroundColor: theme.colors.secondary }}
|
||||||
svgSize={18}
|
svgSize={18}
|
||||||
>
|
>
|
||||||
<StartItem onClick={onFavorite}>
|
<FavoriteDropdownItem link={link} />
|
||||||
{!link.favorite ? (
|
|
||||||
<>
|
|
||||||
<AiFillStar /> {t('add-favorite')}
|
|
||||||
</>
|
|
||||||
) : (
|
|
||||||
<>
|
|
||||||
<AiOutlineStar /> {t('remove-favorite')}
|
|
||||||
</>
|
|
||||||
)}
|
|
||||||
</StartItem>
|
|
||||||
<DropdownItemLink
|
<DropdownItemLink
|
||||||
href={appendLinkId(route('link.edit-form').url, link.id)}
|
href={appendLinkId(route('link.edit-form').url, link.id)}
|
||||||
>
|
>
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
import styled from '@emotion/styled';
|
import styled from '@emotion/styled';
|
||||||
import { RefObject, useEffect, useRef, useState } from 'react';
|
import { RefObject, useEffect, useRef, useState } from 'react';
|
||||||
import { AiOutlineFolder } from 'react-icons/ai';
|
import { AiOutlineFolder } from 'react-icons/ai';
|
||||||
|
import Legend from '~/components/common/legend';
|
||||||
import TextEllipsis from '~/components/common/text_ellipsis';
|
import TextEllipsis from '~/components/common/text_ellipsis';
|
||||||
import LinkFavicon from '~/components/dashboard/link/link_favicon';
|
import LinkFavicon from '~/components/dashboard/link/link_favicon';
|
||||||
import useCollections from '~/hooks/use_collections';
|
import useCollections from '~/hooks/use_collections';
|
||||||
@@ -14,7 +15,7 @@ const SearchItemStyle = styled('li', {
|
|||||||
shouldForwardProp: (propName) => propName !== 'isActive',
|
shouldForwardProp: (propName) => propName !== 'isActive',
|
||||||
})<{ isActive: boolean }>(({ theme, isActive }) => ({
|
})<{ isActive: boolean }>(({ theme, isActive }) => ({
|
||||||
fontSize: '16px',
|
fontSize: '16px',
|
||||||
backgroundColor: isActive ? theme.colors.background : 'transparent',
|
backgroundColor: isActive ? theme.colors.secondary : 'transparent',
|
||||||
display: 'flex',
|
display: 'flex',
|
||||||
gap: '0.35em',
|
gap: '0.35em',
|
||||||
alignItems: 'center',
|
alignItems: 'center',
|
||||||
@@ -22,11 +23,6 @@ const SearchItemStyle = styled('li', {
|
|||||||
padding: '0.25em 0.35em !important',
|
padding: '0.25em 0.35em !important',
|
||||||
}));
|
}));
|
||||||
|
|
||||||
const ItemLegeng = styled.span(({ theme }) => ({
|
|
||||||
fontSize: '13px',
|
|
||||||
color: theme.colors.grey,
|
|
||||||
}));
|
|
||||||
|
|
||||||
interface CommonResultProps {
|
interface CommonResultProps {
|
||||||
innerRef: RefObject<HTMLLIElement>;
|
innerRef: RefObject<HTMLLIElement>;
|
||||||
isActive: boolean;
|
isActive: boolean;
|
||||||
@@ -100,7 +96,7 @@ function ResultLink({
|
|||||||
__html: result.matched_part ?? result.name,
|
__html: result.matched_part ?? result.name,
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
<ItemLegeng>({collection.name})</ItemLegeng>
|
<Legend>({collection.name})</Legend>
|
||||||
</SearchItemStyle>
|
</SearchItemStyle>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,60 @@
|
|||||||
|
import styled from '@emotion/styled';
|
||||||
|
import { useCallback } from 'react';
|
||||||
|
import { useTranslation } from 'react-i18next';
|
||||||
|
import { AiFillStar, AiOutlineStar } from 'react-icons/ai';
|
||||||
|
import { DropdownItemButton } from '~/components/common/dropdown/dropdown_item';
|
||||||
|
import useActiveCollection from '~/hooks/use_active_collection';
|
||||||
|
import useCollections from '~/hooks/use_collections';
|
||||||
|
import { onFavorite } from '~/lib/favorite';
|
||||||
|
import { Link } from '~/types/app';
|
||||||
|
|
||||||
|
const StarItem = styled(DropdownItemButton)(({ theme }) => ({
|
||||||
|
color: theme.colors.yellow,
|
||||||
|
}));
|
||||||
|
|
||||||
|
export default function FavoriteDropdownItem({ link }: { link: Link }) {
|
||||||
|
const { collections, setCollections } = useCollections();
|
||||||
|
const { setActiveCollection } = useActiveCollection();
|
||||||
|
const { t } = useTranslation();
|
||||||
|
|
||||||
|
const toggleFavorite = useCallback(
|
||||||
|
(linkId: Link['id']) => {
|
||||||
|
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,
|
||||||
|
};
|
||||||
|
|
||||||
|
setCollections(collectionsCopy);
|
||||||
|
setActiveCollection(collectionsCopy[collectionIndex]);
|
||||||
|
},
|
||||||
|
[collections, setCollections]
|
||||||
|
);
|
||||||
|
|
||||||
|
const onFavoriteCallback = () => toggleFavorite(link.id);
|
||||||
|
return (
|
||||||
|
<StarItem
|
||||||
|
onClick={() => onFavorite(link.id, !link.favorite, onFavoriteCallback)}
|
||||||
|
>
|
||||||
|
{!link.favorite ? (
|
||||||
|
<>
|
||||||
|
<AiFillStar /> {t('add-favorite')}
|
||||||
|
</>
|
||||||
|
) : (
|
||||||
|
<>
|
||||||
|
<AiOutlineStar /> {t('remove-favorite')}
|
||||||
|
</>
|
||||||
|
)}
|
||||||
|
</StarItem>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -1,8 +1,69 @@
|
|||||||
import styled from '@emotion/styled';
|
import styled from '@emotion/styled';
|
||||||
|
import { route } from '@izzyjs/route/client';
|
||||||
|
import { useTranslation } from 'react-i18next';
|
||||||
|
import { BsThreeDotsVertical } from 'react-icons/bs';
|
||||||
|
import { FaRegEye } from 'react-icons/fa';
|
||||||
|
import { GoPencil } from 'react-icons/go';
|
||||||
|
import { IoTrashOutline } from 'react-icons/io5';
|
||||||
|
import Dropdown from '~/components/common/dropdown/dropdown';
|
||||||
|
import { DropdownItemLink } from '~/components/common/dropdown/dropdown_item';
|
||||||
|
import Legend from '~/components/common/legend';
|
||||||
|
import TextEllipsis from '~/components/common/text_ellipsis';
|
||||||
|
import LinkFavicon from '~/components/dashboard/link/link_favicon';
|
||||||
|
import FavoriteDropdownItem from '~/components/dashboard/side_nav/favorite/favorite_dropdown_item';
|
||||||
import { ItemExternalLink } from '~/components/dashboard/side_nav/nav_item';
|
import { ItemExternalLink } from '~/components/dashboard/side_nav/nav_item';
|
||||||
|
import { appendCollectionId, appendLinkId } from '~/lib/navigation';
|
||||||
|
import { LinkWithCollection } from '~/types/app';
|
||||||
|
|
||||||
const FavoriteItem = styled(ItemExternalLink)(({ theme }) => ({
|
const FavoriteItemStyle = styled(ItemExternalLink)(({ theme }) => ({
|
||||||
|
height: 'auto',
|
||||||
backgroundColor: theme.colors.secondary,
|
backgroundColor: theme.colors.secondary,
|
||||||
}));
|
}));
|
||||||
|
|
||||||
export default FavoriteItem;
|
const FavoriteDropdown = styled(Dropdown)(({ theme }) => ({
|
||||||
|
backgroundColor: theme.colors.secondary,
|
||||||
|
}));
|
||||||
|
|
||||||
|
const FavoriteContainer = styled.div({
|
||||||
|
flex: 1,
|
||||||
|
lineHeight: '1.1rem',
|
||||||
|
});
|
||||||
|
|
||||||
|
export default function FavoriteItem({ link }: { link: LinkWithCollection }) {
|
||||||
|
const { t } = useTranslation();
|
||||||
|
return (
|
||||||
|
<FavoriteItemStyle href={link.url}>
|
||||||
|
<LinkFavicon url={link.url} size={24} />
|
||||||
|
<FavoriteContainer>
|
||||||
|
<TextEllipsis>{link.name}</TextEllipsis>
|
||||||
|
<Legend>{link.collection.name}</Legend>
|
||||||
|
</FavoriteContainer>
|
||||||
|
<FavoriteDropdown
|
||||||
|
onClick={(event) => {
|
||||||
|
event.preventDefault();
|
||||||
|
event.stopPropagation();
|
||||||
|
}}
|
||||||
|
label={<BsThreeDotsVertical />}
|
||||||
|
svgSize={18}
|
||||||
|
>
|
||||||
|
<DropdownItemLink
|
||||||
|
href={appendCollectionId(route('dashboard').url, link.collection.id)}
|
||||||
|
>
|
||||||
|
<FaRegEye /> {t('go-to-collection')}
|
||||||
|
</DropdownItemLink>
|
||||||
|
<FavoriteDropdownItem link={link} />
|
||||||
|
<DropdownItemLink
|
||||||
|
href={appendLinkId(route('link.edit-form').url, link.id)}
|
||||||
|
>
|
||||||
|
<GoPencil /> {t('link.edit')}
|
||||||
|
</DropdownItemLink>
|
||||||
|
<DropdownItemLink
|
||||||
|
href={appendLinkId(route('link.delete-form').url, link.id)}
|
||||||
|
danger
|
||||||
|
>
|
||||||
|
<IoTrashOutline /> {t('link.delete')}
|
||||||
|
</DropdownItemLink>
|
||||||
|
</FavoriteDropdown>
|
||||||
|
</FavoriteItemStyle>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,7 +1,5 @@
|
|||||||
import styled from '@emotion/styled';
|
import styled from '@emotion/styled';
|
||||||
import { useTranslation } from 'react-i18next';
|
import { useTranslation } from 'react-i18next';
|
||||||
import TextEllipsis from '~/components/common/text_ellipsis';
|
|
||||||
import LinkFavicon from '~/components/dashboard/link/link_favicon';
|
|
||||||
import FavoriteListContainer from '~/components/dashboard/side_nav/favorite/favorite_container';
|
import FavoriteListContainer from '~/components/dashboard/side_nav/favorite/favorite_container';
|
||||||
import FavoriteItem from '~/components/dashboard/side_nav/favorite/favorite_item';
|
import FavoriteItem from '~/components/dashboard/side_nav/favorite/favorite_item';
|
||||||
import useFavorites from '~/hooks/use_favorites';
|
import useFavorites from '~/hooks/use_favorites';
|
||||||
@@ -44,11 +42,8 @@ export default function FavoriteList() {
|
|||||||
{t('favorite')} • {favorites.length}
|
{t('favorite')} • {favorites.length}
|
||||||
</FavoriteLabel>
|
</FavoriteLabel>
|
||||||
<FavoriteListStyle>
|
<FavoriteListStyle>
|
||||||
{favorites.map(({ id, name, url }) => (
|
{favorites.map((link) => (
|
||||||
<FavoriteItem href={url} key={id}>
|
<FavoriteItem link={link} key={link.id} />
|
||||||
<LinkFavicon url={url} size={24} />
|
|
||||||
<TextEllipsis>{name}</TextEllipsis>
|
|
||||||
</FavoriteItem>
|
|
||||||
))}
|
))}
|
||||||
</FavoriteListStyle>
|
</FavoriteListStyle>
|
||||||
</FavoriteListContainer>
|
</FavoriteListContainer>
|
||||||
|
|||||||
@@ -131,7 +131,9 @@ function GlobalStyles() {
|
|||||||
},
|
},
|
||||||
|
|
||||||
'th, td': {
|
'th, td': {
|
||||||
whiteSpace: 'nowrap',
|
whiteSspace: 'nowrap',
|
||||||
|
overflow: 'hidden',
|
||||||
|
textOverflow: 'ellipsis',
|
||||||
},
|
},
|
||||||
|
|
||||||
'tr:nth-of-type(even)': {
|
'tr:nth-of-type(even)': {
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ const ProfileStyle = styled(UnstyledList)({
|
|||||||
gap: '1.25em',
|
gap: '1.25em',
|
||||||
});
|
});
|
||||||
|
|
||||||
const Column = styled.li({
|
const Column = styled.div({
|
||||||
display: 'flex',
|
display: 'flex',
|
||||||
gap: '1rem',
|
gap: '1rem',
|
||||||
flexDirection: 'column',
|
flexDirection: 'column',
|
||||||
|
|||||||
@@ -1,12 +1,12 @@
|
|||||||
import { createContext } from 'react';
|
import { createContext } from 'react';
|
||||||
import { Link } from '~/types/app';
|
import { LinkWithCollection } from '~/types/app';
|
||||||
|
|
||||||
type FavoritesContextType = {
|
type FavoritesContextType = {
|
||||||
favorites: Link[];
|
favorites: LinkWithCollection[];
|
||||||
};
|
};
|
||||||
|
|
||||||
const iFavoritesContextState = {
|
const iFavoritesContextState = {
|
||||||
favorites: [] as Link[],
|
favorites: [] as LinkWithCollection[],
|
||||||
};
|
};
|
||||||
|
|
||||||
const FavoritesContext = createContext<FavoritesContextType>(
|
const FavoritesContext = createContext<FavoritesContextType>(
|
||||||
|
|||||||
@@ -32,6 +32,7 @@
|
|||||||
"add-favorite": "Add to favorites",
|
"add-favorite": "Add to favorites",
|
||||||
"remove-favorite": "Remove from favorites",
|
"remove-favorite": "Remove from favorites",
|
||||||
"favorites-appears-here": "Your favorites will appear here",
|
"favorites-appears-here": "Your favorites will appear here",
|
||||||
|
"go-to-collection": "Go to collection",
|
||||||
"no-item-found": "No item found",
|
"no-item-found": "No item found",
|
||||||
"admin": "Administrator",
|
"admin": "Administrator",
|
||||||
"search": "Search",
|
"search": "Search",
|
||||||
|
|||||||
@@ -32,6 +32,7 @@
|
|||||||
"add-favorite": "Ajouter aux favoris",
|
"add-favorite": "Ajouter aux favoris",
|
||||||
"remove-favorite": "Retirer des favoris",
|
"remove-favorite": "Retirer des favoris",
|
||||||
"favorites-appears-here": "Vos favoris apparaîtront ici",
|
"favorites-appears-here": "Vos favoris apparaîtront ici",
|
||||||
|
"go-to-collection": "Voir la collection",
|
||||||
"no-item-found": "Aucun élément trouvé",
|
"no-item-found": "Aucun élément trouvé",
|
||||||
"admin": "Administrateur",
|
"admin": "Administrateur",
|
||||||
"search": "Rechercher",
|
"search": "Rechercher",
|
||||||
|
|||||||
22
inertia/lib/favorite.ts
Normal file
22
inertia/lib/favorite.ts
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
import { route } from '@izzyjs/route/client';
|
||||||
|
import { makeRequest } from '~/lib/request';
|
||||||
|
import { Link } from '~/types/app';
|
||||||
|
|
||||||
|
export const onFavorite = (
|
||||||
|
linkId: Link['id'],
|
||||||
|
isFavorite: boolean,
|
||||||
|
cb: () => void
|
||||||
|
) => {
|
||||||
|
const { url, method } = route('link.toggle-favorite', {
|
||||||
|
params: { id: linkId.toString() },
|
||||||
|
});
|
||||||
|
makeRequest({
|
||||||
|
url,
|
||||||
|
method,
|
||||||
|
body: {
|
||||||
|
favorite: isFavorite,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
.then(() => cb())
|
||||||
|
.catch(console.error);
|
||||||
|
};
|
||||||
@@ -1,14 +1,13 @@
|
|||||||
import { useTheme } from '@emotion/react';
|
import { useTheme } from '@emotion/react';
|
||||||
import styled from '@emotion/styled';
|
import styled from '@emotion/styled';
|
||||||
|
import { ColumnDef } from '@tanstack/react-table';
|
||||||
import dayjs from 'dayjs';
|
import dayjs from 'dayjs';
|
||||||
import relativeTime from 'dayjs/plugin/relativeTime';
|
import relativeTime from 'dayjs/plugin/relativeTime';
|
||||||
import { ReactNode } from 'react';
|
import { useMemo } from 'react';
|
||||||
import { useTranslation } from 'react-i18next';
|
import { useTranslation } from 'react-i18next';
|
||||||
import RoundedImage from '~/components/common/rounded_image';
|
import Table from '~/components/common/table';
|
||||||
import TextEllipsis from '~/components/common/text_ellipsis';
|
|
||||||
import ContentLayout from '~/components/layouts/content_layout';
|
import ContentLayout from '~/components/layouts/content_layout';
|
||||||
import { DATE_FORMAT } from '~/constants';
|
import { DATE_FORMAT } from '~/constants';
|
||||||
import { sortByCreationDate } from '~/lib/array';
|
|
||||||
import { UserWithRelationCount } from '~/types/app';
|
import { UserWithRelationCount } from '~/types/app';
|
||||||
|
|
||||||
dayjs.extend(relativeTime);
|
dayjs.extend(relativeTime);
|
||||||
@@ -19,15 +18,18 @@ interface AdminDashboardProps {
|
|||||||
totalLinks: number;
|
totalLinks: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
const Cell = styled.div<{ column?: boolean; fixed?: boolean }>(
|
const CenteredCell = styled.div({
|
||||||
({ column, fixed }) => ({
|
display: 'flex',
|
||||||
width: '100%',
|
alignItems: 'center',
|
||||||
display: 'flex',
|
justifyContent: 'center',
|
||||||
alignItems: 'center',
|
flexDirection: 'column',
|
||||||
justifyContent: fixed ? 'unset' : 'center',
|
});
|
||||||
gap: column ? 0 : '0.35em',
|
|
||||||
flexDirection: column ? 'column' : 'row',
|
const RenderDateCell = (info: any) => (
|
||||||
})
|
<CenteredCell>
|
||||||
|
<span>{dayjs(info.getValue().toString()).fromNow()}</span>
|
||||||
|
<span>{dayjs(info.getValue().toString()).format(DATE_FORMAT)}</span>
|
||||||
|
</CenteredCell>
|
||||||
);
|
);
|
||||||
|
|
||||||
const ThemeProvider = (props: AdminDashboardProps) => (
|
const ThemeProvider = (props: AdminDashboardProps) => (
|
||||||
@@ -44,95 +46,76 @@ function AdminDashboard({
|
|||||||
}: AdminDashboardProps) {
|
}: AdminDashboardProps) {
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
const theme = useTheme();
|
const theme = useTheme();
|
||||||
return (
|
const columns = useMemo(
|
||||||
<div style={{ overflow: 'auto', marginTop: '1em' }}>
|
() =>
|
||||||
<table>
|
[
|
||||||
<thead>
|
{
|
||||||
<tr>
|
accessorKey: 'id',
|
||||||
<TableCell type="th">#</TableCell>
|
header: (
|
||||||
<TableCell type="th">{t('common:name')}</TableCell>
|
<>
|
||||||
<TableCell type="th">{t('common:email')}</TableCell>
|
# <span css={{ color: theme.colors.grey }}>({users.length})</span>
|
||||||
<TableCell type="th">
|
</>
|
||||||
|
),
|
||||||
|
cell: (info) => info.getValue(),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
accessorKey: 'fullname',
|
||||||
|
header: t('common:name'),
|
||||||
|
cell: (info) => info.getValue(),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
accessorKey: 'email',
|
||||||
|
header: t('common:email'),
|
||||||
|
cell: (info) => info.getValue(),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
accessorKey: 'count',
|
||||||
|
header: (
|
||||||
|
<>
|
||||||
{t('common:collection.collections', { count: totalCollections })}{' '}
|
{t('common:collection.collections', { count: totalCollections })}{' '}
|
||||||
<span css={{ color: theme.colors.grey }}>
|
<span css={{ color: theme.colors.grey }}>
|
||||||
({totalCollections})
|
({totalCollections})
|
||||||
</span>
|
</span>
|
||||||
</TableCell>
|
</>
|
||||||
<TableCell type="th">
|
),
|
||||||
|
cell: (info) => (info.getValue() as any)?.collection,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
accessorKey: 'count',
|
||||||
|
header: (
|
||||||
|
<>
|
||||||
{t('common:link.links', { count: totalLinks })}{' '}
|
{t('common:link.links', { count: totalLinks })}{' '}
|
||||||
<span css={{ color: theme.colors.grey }}>({totalLinks})</span>
|
<span css={{ color: theme.colors.grey }}>({totalLinks})</span>
|
||||||
</TableCell>
|
</>
|
||||||
<TableCell type="th">{t('admin:role')}</TableCell>
|
),
|
||||||
<TableCell type="th">{t('admin:created_at')}</TableCell>
|
cell: (info: any) => info.getValue()?.link,
|
||||||
<TableCell type="th">{t('admin:updated_at')}</TableCell>
|
},
|
||||||
</tr>
|
{
|
||||||
</thead>
|
accessorKey: 'isAdmin',
|
||||||
<tbody>
|
header: t('admin:role'),
|
||||||
{users.length !== 0 &&
|
cell: (info) =>
|
||||||
sortByCreationDate(users).map((user) => (
|
info.getValue() ? (
|
||||||
<TableUserRow user={user} key={user.id} />
|
<span style={{ color: theme.colors.lightRed }}>
|
||||||
))}
|
{t('admin:admin')}
|
||||||
</tbody>
|
</span>
|
||||||
</table>
|
) : (
|
||||||
</div>
|
<span style={{ color: theme.colors.green }}>
|
||||||
|
{t('admin:user')}
|
||||||
|
</span>
|
||||||
|
),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
accessorKey: 'createdAt',
|
||||||
|
header: t('admin:created_at'),
|
||||||
|
cell: RenderDateCell,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
accessorKey: 'updatedAt',
|
||||||
|
header: t('admin:updated_at'),
|
||||||
|
cell: RenderDateCell,
|
||||||
|
},
|
||||||
|
] as ColumnDef<UserWithRelationCount>[],
|
||||||
|
[]
|
||||||
);
|
);
|
||||||
}
|
return <Table columns={columns} data={users} />;
|
||||||
|
|
||||||
function TableUserRow({ user }: { user: UserWithRelationCount }) {
|
|
||||||
const { t } = useTranslation();
|
|
||||||
const theme = useTheme();
|
|
||||||
const { id, fullname, avatarUrl, email, isAdmin, createdAt, updatedAt } =
|
|
||||||
user;
|
|
||||||
return (
|
|
||||||
<tr>
|
|
||||||
<TableCell type="td">{id}</TableCell>
|
|
||||||
<TableCell type="td" fixed>
|
|
||||||
{avatarUrl && (
|
|
||||||
<RoundedImage
|
|
||||||
src={avatarUrl}
|
|
||||||
width={24}
|
|
||||||
height={24}
|
|
||||||
alt={fullname}
|
|
||||||
title={fullname}
|
|
||||||
referrerPolicy="no-referrer"
|
|
||||||
/>
|
|
||||||
)}
|
|
||||||
<TextEllipsis>{fullname ?? '-'}</TextEllipsis>
|
|
||||||
</TableCell>
|
|
||||||
<TableCell type="td">
|
|
||||||
<TextEllipsis>{email}</TextEllipsis>
|
|
||||||
</TableCell>
|
|
||||||
<TableCell type="td">{user.count.collection}</TableCell>
|
|
||||||
<TableCell type="td">{user.count.link}</TableCell>
|
|
||||||
<TableCell type="td">
|
|
||||||
{isAdmin ? (
|
|
||||||
<span style={{ color: theme.colors.lightRed }}>
|
|
||||||
{t('admin:admin')}
|
|
||||||
</span>
|
|
||||||
) : (
|
|
||||||
<span style={{ color: theme.colors.green }}>{t('admin:user')}</span>
|
|
||||||
)}
|
|
||||||
</TableCell>
|
|
||||||
<TableCell type="td" column>
|
|
||||||
<span>{dayjs(createdAt.toString()).fromNow()}</span>
|
|
||||||
<span>{dayjs(createdAt.toString()).format(DATE_FORMAT)}</span>
|
|
||||||
</TableCell>
|
|
||||||
<TableCell type="td" column>
|
|
||||||
<span>{dayjs(updatedAt.toString()).fromNow()}</span>
|
|
||||||
<span>{dayjs(updatedAt.toString()).format(DATE_FORMAT)}</span>
|
|
||||||
</TableCell>
|
|
||||||
</tr>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
type TableItem = {
|
|
||||||
children: ReactNode;
|
|
||||||
type: 'td' | 'th';
|
|
||||||
fixed?: boolean;
|
|
||||||
column?: boolean;
|
|
||||||
};
|
|
||||||
|
|
||||||
function TableCell({ children, type, ...props }: TableItem) {
|
|
||||||
const child = <Cell {...props}>{children}</Cell>;
|
|
||||||
return type === 'td' ? <td>{child}</td> : <th>{child}</th>;
|
|
||||||
}
|
}
|
||||||
|
|||||||
14363
package-lock.json
generated
14363
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
78
package.json
78
package.json
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "my-links",
|
"name": "my-links",
|
||||||
"version": "2.0.0",
|
"version": "2.1.3",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"license": "UNLICENSED",
|
"license": "UNLICENSED",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
@@ -8,7 +8,7 @@
|
|||||||
"build": "node ace build",
|
"build": "node ace build",
|
||||||
"dev": "node ace serve --watch",
|
"dev": "node ace serve --watch",
|
||||||
"test": "node ace test",
|
"test": "node ace test",
|
||||||
"lint": "eslint . --ext .ts,.tsx --report-unused-disable-directives --max-warnings 0",
|
"lint": "eslint . --report-unused-disable-directives --max-warnings 0",
|
||||||
"format": "prettier --write --parser typescript '**/*.{ts,tsx}'",
|
"format": "prettier --write --parser typescript '**/*.{ts,tsx}'",
|
||||||
"typecheck": "tsc --noEmit",
|
"typecheck": "tsc --noEmit",
|
||||||
"prepare": "husky",
|
"prepare": "husky",
|
||||||
@@ -36,66 +36,67 @@
|
|||||||
"#lib/*": "./app/lib/*.js"
|
"#lib/*": "./app/lib/*.js"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@adonisjs/assembler": "^7.7.0",
|
"@adonisjs/assembler": "^7.8.2",
|
||||||
"@adonisjs/eslint-config": "^1.3.0",
|
"@adonisjs/eslint-config": "2.0.0-beta.6",
|
||||||
"@adonisjs/tsconfig": "^1.3.0",
|
"@adonisjs/prettier-config": "^1.4.0",
|
||||||
"@emotion/babel-plugin": "^11.11.0",
|
"@adonisjs/tsconfig": "^1.4.0",
|
||||||
"@faker-js/faker": "^8.4.1",
|
"@emotion/babel-plugin": "^11.12.0",
|
||||||
|
"@faker-js/faker": "^9.0.1",
|
||||||
"@japa/assert": "^3.0.0",
|
"@japa/assert": "^3.0.0",
|
||||||
"@japa/plugin-adonisjs": "^3.0.1",
|
"@japa/plugin-adonisjs": "^3.0.1",
|
||||||
"@japa/runner": "^3.1.4",
|
"@japa/runner": "^3.1.4",
|
||||||
"@swc/core": "^1.5.24",
|
"@swc/core": "^1.7.26",
|
||||||
"@types/luxon": "^3.4.2",
|
"@types/luxon": "^3.4.2",
|
||||||
"@types/node": "^20.13.0",
|
"@types/node": "^20.14.10",
|
||||||
"@types/react": "^18.3.3",
|
"@types/react": "^18.3.7",
|
||||||
"@types/react-dom": "^18.3.0",
|
"@types/react-dom": "^18.3.0",
|
||||||
"@types/react-select": "^5.0.1",
|
|
||||||
"@types/react-toggle": "^4.0.5",
|
"@types/react-toggle": "^4.0.5",
|
||||||
"@typescript-eslint/eslint-plugin": "^7.11.0",
|
"@typescript-eslint/eslint-plugin": "^8.6.0",
|
||||||
"@vitejs/plugin-react": "^4.3.0",
|
"@vitejs/plugin-react": "^4.3.1",
|
||||||
"eslint": "^8.57.0",
|
"eslint": "^9.10.0",
|
||||||
"hot-hook": "^0.2.6",
|
"hot-hook": "^0.2.6",
|
||||||
"husky": "^9.0.11",
|
"husky": "^9.1.6",
|
||||||
"lint-staged": "^15.2.5",
|
"lint-staged": "^15.2.10",
|
||||||
"pino-pretty": "^11.1.0",
|
"pino-pretty": "^11.2.2",
|
||||||
"prettier": "^3.3.0",
|
"prettier": "^3.3.3",
|
||||||
"release-it": "^17.3.0",
|
"release-it": "^17.6.0",
|
||||||
"ts-node": "^10.9.2",
|
"ts-node-maintained": "^10.9.4",
|
||||||
"typescript": "^5.4.5",
|
"typescript": "~5.6.2",
|
||||||
"vite": "^5.2.12"
|
"vite": "^5.4.6"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@adonisjs/ally": "^5.0.2",
|
"@adonisjs/ally": "^5.0.2",
|
||||||
"@adonisjs/auth": "^9.2.1",
|
"@adonisjs/auth": "^9.2.3",
|
||||||
"@adonisjs/core": "^6.9.1",
|
"@adonisjs/core": "^6.13.1",
|
||||||
"@adonisjs/cors": "^2.2.1",
|
"@adonisjs/cors": "^2.2.1",
|
||||||
"@adonisjs/inertia": "^1.1.0",
|
"@adonisjs/inertia": "^1.1.0",
|
||||||
"@adonisjs/lucid": "^20.6.0",
|
"@adonisjs/lucid": "^21.2.0",
|
||||||
"@adonisjs/session": "^7.4.0",
|
"@adonisjs/session": "^7.4.2",
|
||||||
"@adonisjs/shield": "^8.1.1",
|
"@adonisjs/shield": "^8.1.1",
|
||||||
"@adonisjs/static": "^1.1.1",
|
"@adonisjs/static": "^1.1.1",
|
||||||
"@adonisjs/vite": "^3.0.0",
|
"@adonisjs/vite": "^3.0.0",
|
||||||
"@emotion/react": "^11.11.4",
|
"@emotion/react": "11.12.0",
|
||||||
"@emotion/styled": "^11.11.5",
|
"@emotion/styled": "^11.13.0",
|
||||||
"@inertiajs/react": "^1.1.0",
|
"@inertiajs/react": "^1.2.0",
|
||||||
"@izzyjs/route": "^1.1.0-0",
|
"@izzyjs/route": "^1.1.0-0",
|
||||||
|
"@tanstack/react-table": "^8.20.5",
|
||||||
"@vinejs/vine": "^2.1.0",
|
"@vinejs/vine": "^2.1.0",
|
||||||
"bentocache": "^1.0.0-beta.9",
|
"bentocache": "^1.0.0-beta.9",
|
||||||
"dayjs": "^1.11.11",
|
"dayjs": "^1.11.13",
|
||||||
"edge.js": "^6.0.2",
|
"edge.js": "^6.0.2",
|
||||||
"hex-rgb": "^5.0.0",
|
"hex-rgb": "^5.0.0",
|
||||||
"i18next": "^23.11.5",
|
"i18next": "^23.15.1",
|
||||||
"knex": "^3.1.0",
|
"knex": "^3.1.0",
|
||||||
"luxon": "^3.4.4",
|
"luxon": "^3.5.0",
|
||||||
"node-html-parser": "^6.1.13",
|
"node-html-parser": "^6.1.13",
|
||||||
"pg": "^8.11.5",
|
"pg": "^8.12.0",
|
||||||
"react": "^18.3.1",
|
"react": "^18.3.1",
|
||||||
"react-dnd": "^16.0.1",
|
"react-dnd": "^16.0.1",
|
||||||
"react-dnd-html5-backend": "^16.0.1",
|
"react-dnd-html5-backend": "^16.0.1",
|
||||||
"react-dom": "^18.3.1",
|
"react-dom": "^18.3.1",
|
||||||
"react-hotkeys-hook": "^4.5.0",
|
"react-hotkeys-hook": "^4.5.1",
|
||||||
"react-i18next": "^14.1.2",
|
"react-i18next": "^15.0.2",
|
||||||
"react-icons": "^5.2.1",
|
"react-icons": "^5.3.0",
|
||||||
"react-select": "^5.8.0",
|
"react-select": "^5.8.0",
|
||||||
"react-swipeable": "^7.0.1",
|
"react-swipeable": "^7.0.1",
|
||||||
"react-toggle": "^4.1.3",
|
"react-toggle": "^4.1.3",
|
||||||
@@ -107,9 +108,6 @@
|
|||||||
"./app/middleware/*.ts"
|
"./app/middleware/*.ts"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"eslintConfig": {
|
|
||||||
"extends": "@adonisjs/eslint-config/app"
|
|
||||||
},
|
|
||||||
"prettier": {
|
"prettier": {
|
||||||
"trailingComma": "es5",
|
"trailingComma": "es5",
|
||||||
"semi": true,
|
"semi": true,
|
||||||
@@ -126,4 +124,4 @@
|
|||||||
"volta": {
|
"volta": {
|
||||||
"node": "22.2.0"
|
"node": "22.2.0"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
9712
pnpm-lock.yaml
generated
Normal file
9712
pnpm-lock.yaml
generated
Normal file
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user