feat(ui): remove refs to BoardRecord in UI

UI should only work w/ BoardDTO
This commit is contained in:
psychedelicious 2023-06-15 14:44:06 +10:00
parent 48193b7fa7
commit 163ef2c941
3 changed files with 12 additions and 12 deletions

View File

@ -6,7 +6,7 @@ import { ContextMenu } from 'chakra-ui-contextmenu';
import { useTranslation } from 'react-i18next'; import { useTranslation } from 'react-i18next';
import { ExternalLinkIcon } from '@chakra-ui/icons'; import { ExternalLinkIcon } from '@chakra-ui/icons';
import { useAppToaster } from 'app/components/Toaster'; import { useAppToaster } from 'app/components/Toaster';
import { BoardRecord } from 'services/api'; import { BoardDTO } from 'services/api';
import { EntityId, createSelector } from '@reduxjs/toolkit'; import { EntityId, createSelector } from '@reduxjs/toolkit';
import { import {
selectFilteredImagesIds, selectFilteredImagesIds,
@ -17,7 +17,7 @@ import { defaultSelectorOptions } from '../../../app/store/util/defaultMemoizeOp
import { useSelector } from 'react-redux'; import { useSelector } from 'react-redux';
interface HoverableBoardProps { interface HoverableBoardProps {
board: BoardRecord; board: BoardDTO;
} }
/** /**

View File

@ -55,8 +55,8 @@ import {
} from '../store/imagesSlice'; } from '../store/imagesSlice';
import { receivedPageOfImages } from 'services/thunks/image'; import { receivedPageOfImages } from 'services/thunks/image';
import { boardSelector } from '../store/boardSelectors'; import { boardSelector } from '../store/boardSelectors';
import { BoardRecord, ImageDTO } from '../../../services/api'; import { BoardDTO, ImageDTO } from '../../../services/api';
import { isBoardRecord, isImageDTO } from '../../../services/types/guards'; import { isBoardDTO, isImageDTO } from '../../../services/types/guards';
import HoverableBoard from './HoverableBoard'; import HoverableBoard from './HoverableBoard';
import IAIInput from '../../../common/components/IAIInput'; import IAIInput from '../../../common/components/IAIInput';
import { boardCreated } from '../../../services/thunks/board'; import { boardCreated } from '../../../services/thunks/board';
@ -66,7 +66,7 @@ const itemSelector = createSelector(
(state) => { (state) => {
const { images, boards, gallery } = state; const { images, boards, gallery } = state;
let items: Array<ImageDTO | BoardRecord> = []; let items: Array<ImageDTO | BoardDTO> = [];
let areMoreAvailable = false; let areMoreAvailable = false;
let isLoading = true; let isLoading = true;
@ -78,7 +78,7 @@ const itemSelector = createSelector(
areMoreAvailable = items.length < images.total; areMoreAvailable = items.length < images.total;
isLoading = images.isLoading; isLoading = images.isLoading;
} else if (gallery.galleryView === 'boards') { } else if (gallery.galleryView === 'boards') {
items = Object.values(boards.entities) as BoardRecord[]; items = Object.values(boards.entities) as BoardDTO[];
areMoreAvailable = items.length < boards.total; areMoreAvailable = items.length < boards.total;
isLoading = boards.isLoading; isLoading = boards.isLoading;
} }
@ -365,7 +365,7 @@ const ImageGalleryContent = () => {
/> />
</Flex> </Flex>
); );
} else if (isBoardRecord(item)) { } else if (isBoardDTO(item)) {
return ( return (
<Flex sx={{ pb: 2 }}> <Flex sx={{ pb: 2 }}>
<HoverableBoard key={item.board_id} board={item} /> <HoverableBoard key={item.board_id} board={item} />
@ -395,7 +395,7 @@ const ImageGalleryContent = () => {
} }
/> />
); );
} else if (isBoardRecord(item)) { } else if (isBoardDTO(item)) {
return ( return (
<HoverableBoard key={item.board_id} board={item} /> <HoverableBoard key={item.board_id} board={item} />
); );

View File

@ -5,11 +5,11 @@ import {
createSlice, createSlice,
} from '@reduxjs/toolkit'; } from '@reduxjs/toolkit';
import { RootState } from 'app/store/store'; import { RootState } from 'app/store/store';
import { BoardRecord } from 'services/api'; import { BoardDTO } from 'services/api';
import { dateComparator } from 'common/util/dateComparator'; import { dateComparator } from 'common/util/dateComparator';
import { receivedBoards } from '../../../services/thunks/board'; import { receivedBoards } from '../../../services/thunks/board';
export const boardsAdapter = createEntityAdapter<BoardRecord>({ export const boardsAdapter = createEntityAdapter<BoardDTO>({
selectId: (board) => board.board_id, selectId: (board) => board.board_id,
sortComparer: (a, b) => dateComparator(b.updated_at, a.updated_at), sortComparer: (a, b) => dateComparator(b.updated_at, a.updated_at),
}); });
@ -35,10 +35,10 @@ const boardsSlice = createSlice({
name: 'boards', name: 'boards',
initialState: initialBoardsState, initialState: initialBoardsState,
reducers: { reducers: {
boardUpserted: (state, action: PayloadAction<BoardRecord>) => { boardUpserted: (state, action: PayloadAction<BoardDTO>) => {
boardsAdapter.upsertOne(state, action.payload); boardsAdapter.upsertOne(state, action.payload);
}, },
boardUpdatedOne: (state, action: PayloadAction<Update<BoardRecord>>) => { boardUpdatedOne: (state, action: PayloadAction<Update<BoardDTO>>) => {
boardsAdapter.updateOne(state, action.payload); boardsAdapter.updateOne(state, action.payload);
}, },
boardRemoved: (state, action: PayloadAction<string>) => { boardRemoved: (state, action: PayloadAction<string>) => {