🚚(frontend) move types and pad api hooks
Move types and pad api hooks to pad-management.
This commit is contained in:
@@ -0,0 +1,3 @@
|
|||||||
|
export * from './usePad';
|
||||||
|
export * from './usePads';
|
||||||
|
export * from './useUpdatePad';
|
||||||
@@ -6,7 +6,7 @@ import {
|
|||||||
} from '@tanstack/react-query';
|
} from '@tanstack/react-query';
|
||||||
|
|
||||||
import { APIError, APIList, errorCauses, fetchAPI } from '@/api';
|
import { APIError, APIList, errorCauses, fetchAPI } from '@/api';
|
||||||
import { Pad } from '@/features/pads/pad';
|
import { Pad } from '@/features/pads/pad-management';
|
||||||
|
|
||||||
export enum PadsOrdering {
|
export enum PadsOrdering {
|
||||||
BY_CREATED_ON = 'created_at',
|
BY_CREATED_ON = 'created_at',
|
||||||
@@ -6,7 +6,7 @@ import {
|
|||||||
|
|
||||||
import { APIError, errorCauses, fetchAPI } from '@/api';
|
import { APIError, errorCauses, fetchAPI } from '@/api';
|
||||||
|
|
||||||
import { KEY_LIST_PAD } from '../../pads-panel';
|
import { KEY_LIST_PAD } from './usePads';
|
||||||
|
|
||||||
interface RemovePadProps {
|
interface RemovePadProps {
|
||||||
padId: string;
|
padId: string;
|
||||||
|
|||||||
@@ -3,10 +3,13 @@ import { useMutation, useQueryClient } from '@tanstack/react-query';
|
|||||||
import { APIError, errorCauses, fetchAPI } from '@/api';
|
import { APIError, errorCauses, fetchAPI } from '@/api';
|
||||||
import { Pad } from '@/features/pads';
|
import { Pad } from '@/features/pads';
|
||||||
|
|
||||||
export type PadParams = Pick<Pad, 'id'> &
|
export type UpdatePadParams = Pick<Pad, 'id'> &
|
||||||
Partial<Pick<Pad, 'content' | 'title' | 'is_public'>>;
|
Partial<Pick<Pad, 'content' | 'title' | 'is_public'>>;
|
||||||
|
|
||||||
export const updatePad = async ({ id, ...params }: PadParams): Promise<Pad> => {
|
export const updatePad = async ({
|
||||||
|
id,
|
||||||
|
...params
|
||||||
|
}: UpdatePadParams): Promise<Pad> => {
|
||||||
const response = await fetchAPI(`documents/${id}/`, {
|
const response = await fetchAPI(`documents/${id}/`, {
|
||||||
method: 'PATCH',
|
method: 'PATCH',
|
||||||
body: JSON.stringify({
|
body: JSON.stringify({
|
||||||
@@ -31,7 +34,7 @@ export function useUpdatePad({
|
|||||||
listInvalideQueries,
|
listInvalideQueries,
|
||||||
}: UpdatePadProps = {}) {
|
}: UpdatePadProps = {}) {
|
||||||
const queryClient = useQueryClient();
|
const queryClient = useQueryClient();
|
||||||
return useMutation<Pad, APIError, PadParams>({
|
return useMutation<Pad, APIError, UpdatePadParams>({
|
||||||
mutationFn: updatePad,
|
mutationFn: updatePad,
|
||||||
onSuccess: (data) => {
|
onSuccess: (data) => {
|
||||||
listInvalideQueries?.forEach((queryKey) => {
|
listInvalideQueries?.forEach((queryKey) => {
|
||||||
@@ -11,10 +11,10 @@ import { useRouter } from 'next/navigation';
|
|||||||
import { Box, Text, TextErrors } from '@/components';
|
import { Box, Text, TextErrors } from '@/components';
|
||||||
import useCunninghamTheme from '@/cunningham/useCunninghamTheme';
|
import useCunninghamTheme from '@/cunningham/useCunninghamTheme';
|
||||||
|
|
||||||
import { Pad } from '../../pad/types';
|
|
||||||
import { useRemovePad } from '../api/useRemovePad';
|
import { useRemovePad } from '../api/useRemovePad';
|
||||||
import IconPad from '../assets/icon-pad.svg';
|
import IconPad from '../assets/icon-pad.svg';
|
||||||
import IconRemove from '../assets/icon-trash.svg';
|
import IconRemove from '../assets/icon-trash.svg';
|
||||||
|
import { Pad } from '../types';
|
||||||
|
|
||||||
interface ModalRemovePadProps {
|
interface ModalRemovePadProps {
|
||||||
onClose: () => void;
|
onClose: () => void;
|
||||||
|
|||||||
@@ -11,11 +11,11 @@ import { useState } from 'react';
|
|||||||
|
|
||||||
import { Box, Text } from '@/components';
|
import { Box, Text } from '@/components';
|
||||||
import useCunninghamTheme from '@/cunningham/useCunninghamTheme';
|
import useCunninghamTheme from '@/cunningham/useCunninghamTheme';
|
||||||
import { KEY_PAD, Pad } from '@/features/pads/pad';
|
|
||||||
import { KEY_LIST_PAD } from '@/features/pads/pads-panel';
|
|
||||||
|
|
||||||
|
import { KEY_LIST_PAD, KEY_PAD } from '../api';
|
||||||
import { useUpdatePad } from '../api/useUpdatePad';
|
import { useUpdatePad } from '../api/useUpdatePad';
|
||||||
import IconEdit from '../assets/icon-edit.svg';
|
import IconEdit from '../assets/icon-edit.svg';
|
||||||
|
import { Pad } from '../types';
|
||||||
|
|
||||||
import { InputPadName } from './InputPadName';
|
import { InputPadName } from './InputPadName';
|
||||||
|
|
||||||
|
|||||||
@@ -1 +1,3 @@
|
|||||||
|
export * from './api';
|
||||||
export * from './components';
|
export * from './components';
|
||||||
|
export * from './types';
|
||||||
|
|||||||
@@ -11,7 +11,8 @@ import { t } from 'i18next';
|
|||||||
import { useEffect, useState } from 'react';
|
import { useEffect, useState } from 'react';
|
||||||
|
|
||||||
import { Box, Text } from '@/components';
|
import { Box, Text } from '@/components';
|
||||||
import { Pad, usePadStore } from '@/features/pads/pad/';
|
import { usePadStore } from '@/features/pads/pad/';
|
||||||
|
import { Pad } from '@/features/pads/pad-management';
|
||||||
|
|
||||||
import { useCreatePdf } from '../api/useCreatePdf';
|
import { useCreatePdf } from '../api/useCreatePdf';
|
||||||
import { downloadFile } from '../utils';
|
import { downloadFile } from '../utils';
|
||||||
|
|||||||
@@ -3,8 +3,11 @@ import React, { useMemo, useState } from 'react';
|
|||||||
import { useTranslation } from 'react-i18next';
|
import { useTranslation } from 'react-i18next';
|
||||||
|
|
||||||
import { Box, DropButton, IconOptions, Text } from '@/components';
|
import { Box, DropButton, IconOptions, Text } from '@/components';
|
||||||
import { Pad } from '@/features/pads/pad';
|
import {
|
||||||
import { ModalRemovePad, ModalUpdatePad } from '@/features/pads/pad-management';
|
ModalRemovePad,
|
||||||
|
ModalUpdatePad,
|
||||||
|
Pad,
|
||||||
|
} from '@/features/pads/pad-management';
|
||||||
|
|
||||||
import { TemplatesOrdering, useTemplates } from '../api/useTemplates';
|
import { TemplatesOrdering, useTemplates } from '../api/useTemplates';
|
||||||
|
|
||||||
|
|||||||
@@ -1 +0,0 @@
|
|||||||
export * from './usePad';
|
|
||||||
@@ -6,10 +6,10 @@ import { WebrtcProvider } from 'y-webrtc';
|
|||||||
|
|
||||||
import { Box } from '@/components';
|
import { Box } from '@/components';
|
||||||
import { useAuthStore } from '@/core/auth';
|
import { useAuthStore } from '@/core/auth';
|
||||||
|
import { Pad } from '@/features/pads/pad-management';
|
||||||
|
|
||||||
import useSavePad from '../hook/useSavePad';
|
import useSavePad from '../hook/useSavePad';
|
||||||
import { usePadStore } from '../stores';
|
import { usePadStore } from '../stores';
|
||||||
import { Pad } from '../types';
|
|
||||||
import { randomColor } from '../utils';
|
import { randomColor } from '../utils';
|
||||||
|
|
||||||
import { BlockNoteToolbar } from './BlockNoteToolbar';
|
import { BlockNoteToolbar } from './BlockNoteToolbar';
|
||||||
|
|||||||
@@ -1,10 +1,9 @@
|
|||||||
import React from 'react';
|
import React from 'react';
|
||||||
|
|
||||||
import { Box, Card, Text } from '@/components';
|
import { Box, Card, Text } from '@/components';
|
||||||
|
import { Pad } from '@/features/pads/pad-management';
|
||||||
import { PadToolBox } from '@/features/pads/pad-tools';
|
import { PadToolBox } from '@/features/pads/pad-tools';
|
||||||
|
|
||||||
import { Pad } from '../types';
|
|
||||||
|
|
||||||
import { BlockNoteEditor } from './BlockNoteEditor';
|
import { BlockNoteEditor } from './BlockNoteEditor';
|
||||||
|
|
||||||
interface PadEditorProps {
|
interface PadEditorProps {
|
||||||
|
|||||||
@@ -2,7 +2,8 @@ import { useRouter } from 'next/router';
|
|||||||
import { useCallback, useEffect, useRef, useState } from 'react';
|
import { useCallback, useEffect, useRef, useState } from 'react';
|
||||||
import * as Y from 'yjs';
|
import * as Y from 'yjs';
|
||||||
|
|
||||||
import { useUpdatePad } from '../api/useUpdatePad';
|
import { useUpdatePad } from '@/features/pads/pad-management/';
|
||||||
|
|
||||||
import { toBase64 } from '../utils';
|
import { toBase64 } from '../utils';
|
||||||
|
|
||||||
const useSavePad = (padId: string, doc: Y.Doc) => {
|
const useSavePad = (padId: string, doc: Y.Doc) => {
|
||||||
|
|||||||
@@ -1,4 +1,2 @@
|
|||||||
export * from './api';
|
|
||||||
export * from './components';
|
export * from './components';
|
||||||
export * from './stores';
|
export * from './stores';
|
||||||
export * from './types';
|
|
||||||
|
|||||||
@@ -4,8 +4,7 @@ import * as Y from 'yjs';
|
|||||||
import { create } from 'zustand';
|
import { create } from 'zustand';
|
||||||
|
|
||||||
import { signalingUrl } from '@/core';
|
import { signalingUrl } from '@/core';
|
||||||
|
import { Base64, Pad } from '@/features/pads/pad-management';
|
||||||
import { Base64, Pad } from '../types';
|
|
||||||
|
|
||||||
export interface PadStore {
|
export interface PadStore {
|
||||||
padsStore: {
|
padsStore: {
|
||||||
|
|||||||
@@ -1 +0,0 @@
|
|||||||
export * from './usePads';
|
|
||||||
@@ -5,7 +5,7 @@ import { useTranslation } from 'react-i18next';
|
|||||||
import IconGroup from '@/assets/icons/icon-group.svg';
|
import IconGroup from '@/assets/icons/icon-group.svg';
|
||||||
import { Box, StyledLink, Text } from '@/components';
|
import { Box, StyledLink, Text } from '@/components';
|
||||||
import { useCunninghamTheme } from '@/cunningham';
|
import { useCunninghamTheme } from '@/cunningham';
|
||||||
import { Pad } from '@/features/pads/pad';
|
import { Pad } from '@/features/pads/pad-management';
|
||||||
|
|
||||||
import IconNone from '../assets/icon-none.svg';
|
import IconNone from '../assets/icon-none.svg';
|
||||||
|
|
||||||
|
|||||||
@@ -4,9 +4,8 @@ import { useTranslation } from 'react-i18next';
|
|||||||
|
|
||||||
import { Box, Text } from '@/components';
|
import { Box, Text } from '@/components';
|
||||||
import { InfiniteScroll } from '@/components/InfiniteScroll';
|
import { InfiniteScroll } from '@/components/InfiniteScroll';
|
||||||
import { Pad } from '@/features/pads/pad';
|
import { Pad, usePads } from '@/features/pads/pad-management';
|
||||||
|
|
||||||
import { usePads } from '../api';
|
|
||||||
import { usePadPanelStore } from '../store';
|
import { usePadPanelStore } from '../store';
|
||||||
|
|
||||||
import { PadItem } from './PadItem';
|
import { PadItem } from './PadItem';
|
||||||
|
|||||||
@@ -3,8 +3,8 @@ import { useTranslation } from 'react-i18next';
|
|||||||
|
|
||||||
import { Box, BoxButton, StyledLink } from '@/components';
|
import { Box, BoxButton, StyledLink } from '@/components';
|
||||||
import { useCunninghamTheme } from '@/cunningham';
|
import { useCunninghamTheme } from '@/cunningham';
|
||||||
|
import { PadsOrdering } from '@/features/pads/pad-management';
|
||||||
|
|
||||||
import { PadsOrdering } from '../api';
|
|
||||||
import IconAdd from '../assets/icon-add.svg';
|
import IconAdd from '../assets/icon-add.svg';
|
||||||
import IconSort from '../assets/icon-sort.svg';
|
import IconSort from '../assets/icon-sort.svg';
|
||||||
import { usePadPanelStore } from '../store';
|
import { usePadPanelStore } from '../store';
|
||||||
|
|||||||
@@ -1,2 +1 @@
|
|||||||
export * from './api';
|
|
||||||
export * from './components';
|
export * from './components';
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import { create } from 'zustand';
|
import { create } from 'zustand';
|
||||||
|
|
||||||
import { PadsOrdering } from '../api/usePads';
|
import { PadsOrdering } from '@/features/pads/pad-management';
|
||||||
|
|
||||||
interface PadPanelStore {
|
interface PadPanelStore {
|
||||||
ordering: PadsOrdering;
|
ordering: PadsOrdering;
|
||||||
|
|||||||
@@ -5,7 +5,8 @@ import { ReactElement } from 'react';
|
|||||||
|
|
||||||
import { Box } from '@/components';
|
import { Box } from '@/components';
|
||||||
import { TextErrors } from '@/components/TextErrors';
|
import { TextErrors } from '@/components/TextErrors';
|
||||||
import { PadEditor, usePad } from '@/features/pads/pad';
|
import { PadEditor } from '@/features/pads/pad';
|
||||||
|
import { usePad } from '@/features/pads/pad-management';
|
||||||
import { PadLayout } from '@/layouts';
|
import { PadLayout } from '@/layouts';
|
||||||
import { NextPageWithLayout } from '@/types/next';
|
import { NextPageWithLayout } from '@/types/next';
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import { ReactElement } from 'react';
|
import { ReactElement } from 'react';
|
||||||
|
|
||||||
import { Box } from '@/components';
|
import { Box } from '@/components';
|
||||||
import { CardCreatePad } from '@/features/pads/';
|
import { CardCreatePad } from '@/features/pads/pad-management';
|
||||||
import { PadLayout } from '@/layouts';
|
import { PadLayout } from '@/layouts';
|
||||||
import { NextPageWithLayout } from '@/types/next';
|
import { NextPageWithLayout } from '@/types/next';
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user