Skip to content

Commit

Permalink
Merge pull request #195 from cboard-org/fix-board-props
Browse files Browse the repository at this point in the history
Fixes for board download
  • Loading branch information
martinbedouret authored Aug 29, 2024
2 parents 93e5b63 + efbe8b4 commit dff7fec
Show file tree
Hide file tree
Showing 7 changed files with 75 additions and 17 deletions.
4 changes: 4 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,17 @@
"@mui/material": "^5.15.4",
"@mui/material-nextjs": "^5.15.3",
"@types/lodash.debounce": "^4.0.9",
"@types/moment": "^2.13.0",
"@types/nanoid": "^3.0.0",
"bufferutil": "^4.0.8",
"cboard-ai-engine": "^1.3.3",
"deepmerge": "^4.3.1",
"embla-carousel-react": "^8.0.2",
"lodash.debounce": "^4.0.8",
"lodash.pick": "^4.4.0",
"moment": "^2.30.1",
"mongoose": "^8.2.0",
"nanoid": "^5.0.7",
"next": "14.0.4",
"next-auth": "^4.24.5",
"next-intl": "^3.4.2",
Expand Down
8 changes: 7 additions & 1 deletion src/app/[locale]/dashboard/[id]/@promptForm/actions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -128,11 +128,17 @@ export async function submit(
throw new Error('No suggestions found');
}

const author = session.user?.name ? session.user.name : '';
const email = session.user?.email ? session.user.email : '';

const generatedBoard = await toCboardAdapter({
suggestions,
columns,
rows,
prompt: prompt,
prompt,
author,
email,
locale,
});

const savedPrompt = await savePrompt({
Expand Down
2 changes: 1 addition & 1 deletion src/intl/cbuilder.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
},
"PictogramGeneratorFormDialog": {
"title": "Use Pictonizer to generate pictograms",
"subtitle": "Generate 4 pictograms for",
"subtitle": "Generate pictograms for",
"cancelButton": "CANCEL",
"generateButton": "GENERATE",
"generatingPictogramsTo": "Generating 4 pictograms to:"
Expand Down
2 changes: 1 addition & 1 deletion src/intl/dictionaries/en-US.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
},
"PictogramGeneratorFormDialog": {
"title": "Use Pictonizer to generate pictograms",
"subtitle": "Generate 4 pictograms for",
"subtitle": "Generate pictograms for",
"cancelButton": "CANCEL",
"generateButton": "GENERATE",
"generatingPictogramsTo": "Generating 4 pictograms to:"
Expand Down
33 changes: 28 additions & 5 deletions src/lib/cboard-ai-engine/cboard-adapter.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
'use server';
import { BoardRecord } from '@/commonTypes/Board';
import { TileRecord } from '@/commonTypes/Tile';
import testBoard from '@/dashboard/@board/testBoard.json';
import moment from 'moment';
import { Suggestion, AIImage } from 'cboard-ai-engine';
import { nanoid } from 'nanoid';

const DEFAULT_TILE_BACKGROUND_COLOR = 'rgb(255, 241, 118)';

Expand Down Expand Up @@ -54,11 +55,17 @@ export const toCboardAdapter = async ({
columns,
rows,
prompt,
author,
email,
locale,
}: {
suggestions: Suggestion[];
columns: number;
rows: number;
prompt: string;
author: string;
email: string;
locale: string;
}): Promise<BoardRecord> => {
if (!suggestions.length || !columns || !rows)
throw new Error('Invalid input on Cboard adapter');
Expand All @@ -77,15 +84,31 @@ export const toCboardAdapter = async ({

return multidimensionalArray;
};

const tilesIds = tiles.map((tile) => tile.id);
const order = createMultidimensionalArray(tilesIds, columns);
return {
...testBoard[1],
createdAt: '',
updatedAt: '',
const newBoard: BoardRecord = {
isPublic: false,
id: nanoid(11),
createdAt: moment().format(),
updatedAt: moment().format(),
tiles,
grid: { order, rows, columns },
//Engine should provide the title to be used as name
name: prompt,
cellSize: 'medium',
locale: locale,
format: 'cboard',
description:
'Board Automatically generated using the Cboard AI Builder - Prompt used: ' +
prompt,
isFixed: true,
email: email,
author: author,
lastEdited: moment().format(),
hidden: false,
focusedTileId: tiles[0].id,
promptId: nanoid(),
};
return newBoard;
};
15 changes: 8 additions & 7 deletions src/lib/exportHelpers/cboardExportAdapter.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { BoardRecord } from '@/commonTypes/Board';
import { EXPORT_CONFIG_BY_TYPE } from './constants';
import moment from 'moment';

const getDatetimePrefix = () => new Date().toString();
const getDatetimePrefix = () => moment().format('YYYY-MM-DD_HH-mm-ss-');

declare global {
interface Navigator {
Expand All @@ -15,27 +16,27 @@ export async function cboardExportAdapter(boards: BoardRecord[]) {
});

if (jsonData) {
let prefix = getDatetimePrefix();
const prefix = getDatetimePrefix();
let name: string | undefined = prefix;
if (boards.length === 1) {
const name = boards[0].name?.split(' ').join('-').substring(0, 15);
prefix = name + '_';
name = name + boards[0].name?.replace(' ', '-').substring(0, 20) + ' ';
} else {
prefix = prefix + 'boardsset ';
name = name + 'boardsset ';
}

// IE11 & Edge
if (navigator.msSaveBlob) {
navigator.msSaveBlob(
jsonData,
prefix + EXPORT_CONFIG_BY_TYPE.cboard.filename,
name + EXPORT_CONFIG_BY_TYPE.cboard.filename,
);
} else {
// In FF link must be added to DOM to be clicked
const link = document.createElement('a');
link.href = window.URL.createObjectURL(jsonData);
link.setAttribute(
'download',
prefix + EXPORT_CONFIG_BY_TYPE.cboard.filename,
name + EXPORT_CONFIG_BY_TYPE.cboard.filename,
);
document.body.appendChild(link);
link.click();
Expand Down
28 changes: 26 additions & 2 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -756,6 +756,20 @@
resolved "https://registry.npmjs.org/@types/lodash/-/lodash-4.17.0.tgz"
integrity sha512-t7dhREVv6dbNj0q17X12j7yDG4bD/DHYX7o5/DbDxobP0HnGPgpRz2Ej77aL7TZT3DSw13fqUTj8J4mMnqa7WA==

"@types/moment@^2.13.0":
version "2.13.0"
resolved "https://registry.yarnpkg.com/@types/moment/-/moment-2.13.0.tgz#604ebd189bc3bc34a1548689404e61a2a4aac896"
integrity sha512-DyuyYGpV6r+4Z1bUznLi/Y7HpGn4iQ4IVcGn8zrr1P4KotKLdH0sbK1TFR6RGyX6B+G8u83wCzL+bpawKU/hdQ==
dependencies:
moment "*"

"@types/nanoid@^3.0.0":
version "3.0.0"
resolved "https://registry.yarnpkg.com/@types/nanoid/-/nanoid-3.0.0.tgz#c757b20f343f3a1dd76e80a9a431b6290fc20f35"
integrity sha512-UXitWSmXCwhDmAKe7D3hNQtQaHeHt5L8LO1CB8GF8jlYVzOv5cBWDNqiJ+oPEWrWei3i3dkZtHY/bUtd0R/uOQ==
dependencies:
nanoid "*"

"@types/node@^20":
version "20.12.7"
resolved "https://registry.npmjs.org/@types/node/-/node-20.12.7.tgz"
Expand Down Expand Up @@ -2722,6 +2736,11 @@ minimist@^1.2.0, minimist@^1.2.6:
resolved "https://registry.npmjs.org/minimist/-/minimist-1.2.8.tgz"
integrity sha512-2yyAR8qBkN3YuheJanUpWC5U3bb5osDywNB8RzDVlDwDHbocAJveqqj1u8+SVD7jkWT4yvsHCpWqqWqAxb0zCA==

moment@*, moment@^2.30.1:
version "2.30.1"
resolved "https://registry.yarnpkg.com/moment/-/moment-2.30.1.tgz#f8c91c07b7a786e30c59926df530b4eac96974ae"
integrity sha512-uEmtNhbDOrWPFS+hdjFCBfy9f2YoyzRpwcl+DqpC6taX21FzsTLQVbMV/W7PzNSX6x/bhC1zA3c2UQ5NzH6how==

mongodb-connection-string-url@^3.0.0:
version "3.0.0"
resolved "https://registry.npmjs.org/mongodb-connection-string-url/-/mongodb-connection-string-url-3.0.0.tgz"
Expand Down Expand Up @@ -2774,14 +2793,19 @@ [email protected], ms@^2.1.1:
resolved "https://registry.npmjs.org/ms/-/ms-2.1.3.tgz"
integrity sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA==

nanoid@*, nanoid@^5.0.6:
version "5.0.7"
resolved "https://registry.npmjs.org/nanoid/-/nanoid-5.0.7.tgz"
integrity sha512-oLxFY2gd2IqnjcYyOXD8XGCftpGtZP2AbHbOkthDkvRywH5ayNtPVy9YlOPcHckXzbLTCHpkb7FB+yuxKV13pQ==

nanoid@^3.3.6:
version "3.3.7"
resolved "https://registry.npmjs.org/nanoid/-/nanoid-3.3.7.tgz"
integrity sha512-eSRppjcPIatRIMC1U6UngP8XFcz8MQWGQdt1MTBQ7NaAmvXDfvNxbvWV3x2y6CdEUciCSsDHDQZbhYaB8QEo2g==

nanoid@^5.0.6:
nanoid@^5.0.7:
version "5.0.7"
resolved "https://registry.npmjs.org/nanoid/-/nanoid-5.0.7.tgz"
resolved "https://registry.yarnpkg.com/nanoid/-/nanoid-5.0.7.tgz#6452e8c5a816861fd9d2b898399f7e5fd6944cc6"
integrity sha512-oLxFY2gd2IqnjcYyOXD8XGCftpGtZP2AbHbOkthDkvRywH5ayNtPVy9YlOPcHckXzbLTCHpkb7FB+yuxKV13pQ==

natural-compare@^1.4.0:
Expand Down

0 comments on commit dff7fec

Please sign in to comment.