WIP
continuous-integration/drone/push Build is failing Details

This commit is contained in:
Simon 2023-04-27 22:26:41 +02:00
parent 58a6da1d94
commit 71fe473dda
17 changed files with 371 additions and 28 deletions

6
.gitignore vendored
View File

@ -15,7 +15,7 @@ coverage
*.local *.local
/cypress/videos/ /cypress/videos/
/cypress/screenshots/ /cypress/screenshots
# Editor directories and files # Editor directories and files
.vscode/* .vscode/*
@ -29,4 +29,6 @@ coverage
# app # app
src/data.json src/data.json
public/answers public/answers/
public/log.png
public/favicon/*.png

View File

@ -2,7 +2,22 @@
<html lang="fr"> <html lang="fr">
<head> <head>
<meta charset="UTF-8" /> <meta charset="UTF-8" />
<link rel="icon" href="/favicon.ico" /> <link rel="apple-touch-icon" sizes="57x57" href="/favicon/apple-icon-57x57.png">
<link rel="apple-touch-icon" sizes="60x60" href="/favicon/apple-icon-60x60.png">
<link rel="apple-touch-icon" sizes="72x72" href="/favicon/apple-icon-72x72.png">
<link rel="apple-touch-icon" sizes="76x76" href="/favicon/apple-icon-76x76.png">
<link rel="apple-touch-icon" sizes="114x114" href="/favicon/apple-icon-114x114.png">
<link rel="apple-touch-icon" sizes="120x120" href="/favicon/apple-icon-120x120.png">
<link rel="apple-touch-icon" sizes="144x144" href="/favicon/apple-icon-144x144.png">
<link rel="apple-touch-icon" sizes="152x152" href="/favicon/apple-icon-152x152.png">
<link rel="apple-touch-icon" sizes="180x180" href="/favicon/apple-icon-180x180.png">
<link rel="icon" type="image/png" sizes="192x192" href="/favicon/android-icon-192x192.png">
<link rel="icon" type="image/png" sizes="32x32" href="/favicon/favicon-32x32.png">
<link rel="icon" type="image/png" sizes="96x96" href="/favicon/favicon-96x96.png">
<link rel="icon" type="image/png" sizes="16x16" href="/favicon/favicon-16x16.png">
<link rel="manifest" href="/favicon/manifest.json">
<meta name="msapplication-TileColor" content="#ffffff">
<meta name="msapplication-TileImage" content="/favicon/ms-icon-144x144.png">
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> <meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Scores Ceiba</title> <title>Scores Ceiba</title>
</head> </head>

83
package-lock.json generated
View File

@ -9,6 +9,7 @@
"version": "0.1.0", "version": "0.1.0",
"dependencies": { "dependencies": {
"@splidejs/vue-splide": "^0.5.18", "@splidejs/vue-splide": "^0.5.18",
"html2canvas": "^1.4.1",
"pinia": "^2.0.11", "pinia": "^2.0.11",
"pinia-plugin-persist": "^1.0.0", "pinia-plugin-persist": "^1.0.0",
"sass": "^1.49.9", "sass": "^1.49.9",
@ -542,6 +543,14 @@
"integrity": "sha512-3oSeUO0TMV67hN1AmbXsK4yaqU7tjiHlbxRDZOpH0KW9+CeX4bRAaX0Anxt0tx2MrpRpWwQaPwIlISEJhYU5Pw==", "integrity": "sha512-3oSeUO0TMV67hN1AmbXsK4yaqU7tjiHlbxRDZOpH0KW9+CeX4bRAaX0Anxt0tx2MrpRpWwQaPwIlISEJhYU5Pw==",
"dev": true "dev": true
}, },
"node_modules/base64-arraybuffer": {
"version": "1.0.2",
"resolved": "https://registry.npmjs.org/base64-arraybuffer/-/base64-arraybuffer-1.0.2.tgz",
"integrity": "sha512-I3yl4r9QB5ZRY3XuJVEPfc2XhZO6YweFPI+UovAzn+8/hb3oJ6lnysaFcjVpkCPfVWFUDvoZ8kmVDP7WyRtYtQ==",
"engines": {
"node": ">= 0.6.0"
}
},
"node_modules/base64-js": { "node_modules/base64-js": {
"version": "1.5.1", "version": "1.5.1",
"resolved": "https://registry.npmjs.org/base64-js/-/base64-js-1.5.1.tgz", "resolved": "https://registry.npmjs.org/base64-js/-/base64-js-1.5.1.tgz",
@ -844,6 +853,14 @@
"node": ">= 8" "node": ">= 8"
} }
}, },
"node_modules/css-line-break": {
"version": "2.1.0",
"resolved": "https://registry.npmjs.org/css-line-break/-/css-line-break-2.1.0.tgz",
"integrity": "sha512-FHcKFCZcAha3LwfVBhCQbW2nCNbkZXn7KVUJcsT5/P8YmfsVja0FMPJr0B903j/E69HUphKiV9iQArX8SDYA4w==",
"dependencies": {
"utrie": "^1.0.2"
}
},
"node_modules/csstype": { "node_modules/csstype": {
"version": "2.6.20", "version": "2.6.20",
"resolved": "https://registry.npmjs.org/csstype/-/csstype-2.6.20.tgz", "resolved": "https://registry.npmjs.org/csstype/-/csstype-2.6.20.tgz",
@ -1779,6 +1796,18 @@
"resolved": "https://registry.npmjs.org/has-unicode/-/has-unicode-2.0.1.tgz", "resolved": "https://registry.npmjs.org/has-unicode/-/has-unicode-2.0.1.tgz",
"integrity": "sha1-4Ob+aijPUROIVeCG0Wkedx3iqLk=" "integrity": "sha1-4Ob+aijPUROIVeCG0Wkedx3iqLk="
}, },
"node_modules/html2canvas": {
"version": "1.4.1",
"resolved": "https://registry.npmjs.org/html2canvas/-/html2canvas-1.4.1.tgz",
"integrity": "sha512-fPU6BHNpsyIhr8yyMpTLLxAbkaK8ArIBcmZIRiBLiDhjeqvXolaEmDGmELFuX9I4xDcaKKcJl+TKZLqruBbmWA==",
"dependencies": {
"css-line-break": "^2.1.0",
"text-segmentation": "^1.0.3"
},
"engines": {
"node": ">=8.0.0"
}
},
"node_modules/ieee754": { "node_modules/ieee754": {
"version": "1.2.1", "version": "1.2.1",
"resolved": "https://registry.npmjs.org/ieee754/-/ieee754-1.2.1.tgz", "resolved": "https://registry.npmjs.org/ieee754/-/ieee754-1.2.1.tgz",
@ -3059,6 +3088,14 @@
"node": ">= 8" "node": ">= 8"
} }
}, },
"node_modules/text-segmentation": {
"version": "1.0.3",
"resolved": "https://registry.npmjs.org/text-segmentation/-/text-segmentation-1.0.3.tgz",
"integrity": "sha512-iOiPUo/BGnZ6+54OsWxZidGCsdU8YbE4PSpdPinp7DeMtUJNJBoJ/ouUSTJjHkh1KntHaltHl/gDs2FC4i5+Nw==",
"dependencies": {
"utrie": "^1.0.2"
}
},
"node_modules/text-table": { "node_modules/text-table": {
"version": "0.2.0", "version": "0.2.0",
"resolved": "https://registry.npmjs.org/text-table/-/text-table-0.2.0.tgz", "resolved": "https://registry.npmjs.org/text-table/-/text-table-0.2.0.tgz",
@ -3124,6 +3161,14 @@
"resolved": "https://registry.npmjs.org/util-deprecate/-/util-deprecate-1.0.2.tgz", "resolved": "https://registry.npmjs.org/util-deprecate/-/util-deprecate-1.0.2.tgz",
"integrity": "sha1-RQ1Nyfpw3nMnYvvS1KKJgUGaDM8=" "integrity": "sha1-RQ1Nyfpw3nMnYvvS1KKJgUGaDM8="
}, },
"node_modules/utrie": {
"version": "1.0.2",
"resolved": "https://registry.npmjs.org/utrie/-/utrie-1.0.2.tgz",
"integrity": "sha512-1MLa5ouZiOmQzUbjbu9VmjLzn1QLXBhwpUa7kdLUQK+KQ5KA9I1vk5U4YHe/X2Ch7PYnJfWuWT+VbuxbGwljhw==",
"dependencies": {
"base64-arraybuffer": "^1.0.2"
}
},
"node_modules/v8-compile-cache": { "node_modules/v8-compile-cache": {
"version": "2.3.0", "version": "2.3.0",
"resolved": "https://registry.npmjs.org/v8-compile-cache/-/v8-compile-cache-2.3.0.tgz", "resolved": "https://registry.npmjs.org/v8-compile-cache/-/v8-compile-cache-2.3.0.tgz",
@ -3814,6 +3859,11 @@
"integrity": "sha512-3oSeUO0TMV67hN1AmbXsK4yaqU7tjiHlbxRDZOpH0KW9+CeX4bRAaX0Anxt0tx2MrpRpWwQaPwIlISEJhYU5Pw==", "integrity": "sha512-3oSeUO0TMV67hN1AmbXsK4yaqU7tjiHlbxRDZOpH0KW9+CeX4bRAaX0Anxt0tx2MrpRpWwQaPwIlISEJhYU5Pw==",
"dev": true "dev": true
}, },
"base64-arraybuffer": {
"version": "1.0.2",
"resolved": "https://registry.npmjs.org/base64-arraybuffer/-/base64-arraybuffer-1.0.2.tgz",
"integrity": "sha512-I3yl4r9QB5ZRY3XuJVEPfc2XhZO6YweFPI+UovAzn+8/hb3oJ6lnysaFcjVpkCPfVWFUDvoZ8kmVDP7WyRtYtQ=="
},
"base64-js": { "base64-js": {
"version": "1.5.1", "version": "1.5.1",
"resolved": "https://registry.npmjs.org/base64-js/-/base64-js-1.5.1.tgz", "resolved": "https://registry.npmjs.org/base64-js/-/base64-js-1.5.1.tgz",
@ -4019,6 +4069,14 @@
"which": "^2.0.1" "which": "^2.0.1"
} }
}, },
"css-line-break": {
"version": "2.1.0",
"resolved": "https://registry.npmjs.org/css-line-break/-/css-line-break-2.1.0.tgz",
"integrity": "sha512-FHcKFCZcAha3LwfVBhCQbW2nCNbkZXn7KVUJcsT5/P8YmfsVja0FMPJr0B903j/E69HUphKiV9iQArX8SDYA4w==",
"requires": {
"utrie": "^1.0.2"
}
},
"csstype": { "csstype": {
"version": "2.6.20", "version": "2.6.20",
"resolved": "https://registry.npmjs.org/csstype/-/csstype-2.6.20.tgz", "resolved": "https://registry.npmjs.org/csstype/-/csstype-2.6.20.tgz",
@ -4622,6 +4680,15 @@
"resolved": "https://registry.npmjs.org/has-unicode/-/has-unicode-2.0.1.tgz", "resolved": "https://registry.npmjs.org/has-unicode/-/has-unicode-2.0.1.tgz",
"integrity": "sha1-4Ob+aijPUROIVeCG0Wkedx3iqLk=" "integrity": "sha1-4Ob+aijPUROIVeCG0Wkedx3iqLk="
}, },
"html2canvas": {
"version": "1.4.1",
"resolved": "https://registry.npmjs.org/html2canvas/-/html2canvas-1.4.1.tgz",
"integrity": "sha512-fPU6BHNpsyIhr8yyMpTLLxAbkaK8ArIBcmZIRiBLiDhjeqvXolaEmDGmELFuX9I4xDcaKKcJl+TKZLqruBbmWA==",
"requires": {
"css-line-break": "^2.1.0",
"text-segmentation": "^1.0.3"
}
},
"ieee754": { "ieee754": {
"version": "1.2.1", "version": "1.2.1",
"resolved": "https://registry.npmjs.org/ieee754/-/ieee754-1.2.1.tgz", "resolved": "https://registry.npmjs.org/ieee754/-/ieee754-1.2.1.tgz",
@ -5490,6 +5557,14 @@
"terser": "^5.7.2" "terser": "^5.7.2"
} }
}, },
"text-segmentation": {
"version": "1.0.3",
"resolved": "https://registry.npmjs.org/text-segmentation/-/text-segmentation-1.0.3.tgz",
"integrity": "sha512-iOiPUo/BGnZ6+54OsWxZidGCsdU8YbE4PSpdPinp7DeMtUJNJBoJ/ouUSTJjHkh1KntHaltHl/gDs2FC4i5+Nw==",
"requires": {
"utrie": "^1.0.2"
}
},
"text-table": { "text-table": {
"version": "0.2.0", "version": "0.2.0",
"resolved": "https://registry.npmjs.org/text-table/-/text-table-0.2.0.tgz", "resolved": "https://registry.npmjs.org/text-table/-/text-table-0.2.0.tgz",
@ -5540,6 +5615,14 @@
"resolved": "https://registry.npmjs.org/util-deprecate/-/util-deprecate-1.0.2.tgz", "resolved": "https://registry.npmjs.org/util-deprecate/-/util-deprecate-1.0.2.tgz",
"integrity": "sha1-RQ1Nyfpw3nMnYvvS1KKJgUGaDM8=" "integrity": "sha1-RQ1Nyfpw3nMnYvvS1KKJgUGaDM8="
}, },
"utrie": {
"version": "1.0.2",
"resolved": "https://registry.npmjs.org/utrie/-/utrie-1.0.2.tgz",
"integrity": "sha512-1MLa5ouZiOmQzUbjbu9VmjLzn1QLXBhwpUa7kdLUQK+KQ5KA9I1vk5U4YHe/X2Ch7PYnJfWuWT+VbuxbGwljhw==",
"requires": {
"base64-arraybuffer": "^1.0.2"
}
},
"v8-compile-cache": { "v8-compile-cache": {
"version": "2.3.0", "version": "2.3.0",
"resolved": "https://registry.npmjs.org/v8-compile-cache/-/v8-compile-cache-2.3.0.tgz", "resolved": "https://registry.npmjs.org/v8-compile-cache/-/v8-compile-cache-2.3.0.tgz",

View File

@ -11,6 +11,7 @@
}, },
"dependencies": { "dependencies": {
"@splidejs/vue-splide": "^0.5.18", "@splidejs/vue-splide": "^0.5.18",
"html2canvas": "^1.4.1",
"pinia": "^2.0.11", "pinia": "^2.0.11",
"pinia-plugin-persist": "^1.0.0", "pinia-plugin-persist": "^1.0.0",
"sass": "^1.49.9", "sass": "^1.49.9",

Binary file not shown.

Before

Width:  |  Height:  |  Size: 26 KiB

View File

@ -0,0 +1,2 @@
<?xml version="1.0" encoding="utf-8"?>
<browserconfig><msapplication><tile><square70x70logo src="/favicon/ms-icon-70x70.png"/><square150x150logo src="/favicon/ms-icon-150x150.png"/><square310x310logo src="/favicon/ms-icon-310x310.png"/><TileColor>#ffffff</TileColor></tile></msapplication></browserconfig>

View File

@ -0,0 +1,41 @@
{
"name": "App",
"icons": [
{
"src": "\/favicon\/android-icon-36x36.png",
"sizes": "36x36",
"type": "image\/png",
"density": "0.75"
},
{
"src": "\/favicon\/android-icon-48x48.png",
"sizes": "48x48",
"type": "image\/png",
"density": "1.0"
},
{
"src": "\/favicon\/android-icon-72x72.png",
"sizes": "72x72",
"type": "image\/png",
"density": "1.5"
},
{
"src": "\/favicon\/android-icon-96x96.png",
"sizes": "96x96",
"type": "image\/png",
"density": "2.0"
},
{
"src": "\/favicon\/android-icon-144x144.png",
"sizes": "144x144",
"type": "image\/png",
"density": "3.0"
},
{
"src": "\/favicon\/android-icon-192x192.png",
"sizes": "192x192",
"type": "image\/png",
"density": "4.0"
}
]
}

BIN
public/homepage.webp Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 43 KiB

BIN
public/logo.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 168 KiB

View File

@ -30,7 +30,7 @@ async function fetchAsset(uuid) {
return fetch(url); return fetch(url);
} }
async function fetchData() { async function fetchScoresData() {
const fields = [ const fields = [
"*", "*",
"translations.*", "translations.*",
@ -72,18 +72,7 @@ async function fetchData() {
for (const answer of question.questions_id.answers) { for (const answer of question.questions_id.answers) {
const uuid = answer.answers_id.image; const uuid = answer.answers_id.image;
if (uuid) { if (uuid) {
console.log(`${folder}/${uuid}`); await downloadImage(uuid, `${folder}/${uuid}.webp`, { height: 200 })
const response = await fetchAsset(uuid);
try {
const thumbnail = sharp().resize({ height: 200 }).webp();
await streamPipeline(
response.body,
thumbnail,
createWriteStream(`${folder}/${uuid}.webp`)
);
} catch (err) {
console.log(err);
}
} }
} }
} }
@ -92,4 +81,97 @@ async function fetchData() {
// await sharp('src/assets/arbre.png').resize({ width: 440, height: 690 }).webp().toFile('public/arbre.webp') // await sharp('src/assets/arbre.png').resize({ width: 440, height: 690 }).webp().toFile('public/arbre.webp')
} }
async function transformImage(response, path, options, format = 'webp') {
try {
let thumbnail
console.log(path)
if (format == 'webp') {
thumbnail = sharp().resize(options).webp();
} else {
thumbnail = sharp().resize(options).toFormat('png');
}
const stream = createWriteStream(path)
await streamPipeline(
response.body,
thumbnail,
stream
)
await stream
} catch (err) {
console.log(err);
}
}
async function downloadImage(uuid, path, options, format = 'webp') {
const response = await fetchAsset(uuid);
await transformImage(response, path, options, format);
}
async function downloadFavicon(uuid) {
const response = await fetchAsset(uuid);
const favicons = [
{path: `public/favicon/android-icon-192x192.png`, options: { width: 192, height: 192, }, format: 'png'},
{path: `public/favicon/apple-icon-57x57.png`, options: { width: 57, height: 57, }, format: 'png'},
// {path: `public/favicon/apple-icon-60x60.png`, options: { width: 60, height: 60, }, format: 'png'},
// {path: `public/favicon/apple-icon-72x72.png`, options: { width: 72, height: 72, }, format: 'png'},
// {path: `public/favicon/apple-icon-76x76.png`, options: { width: 76, height: 76, }, format: 'png'},
// {path: `public/favicon/apple-icon-114x114.png`, options: { width: 114, height: 114, }, format: 'png'},
// {path: `public/favicon/apple-icon-120x120.png`, options: { width: 120, height: 120, }, format: 'png'},
// {path: `public/favicon/apple-icon-144x144.png`, options: { width: 144, height: 144, }, format: 'png'},
// {path: `public/favicon/apple-icon-152x152.png`, options: { width: 152, height: 152, }, format: 'png'},
// {path: `public/favicon/apple-icon-180x180.png`, options: { width: 180, height: 180, }, format: 'png'},
// {path: `public/favicon/favicon-16x16.png`, options: { width: 16, height: 16, }, format: 'png'},
// {path: `public/favicon/favicon-32x32.png`, options: { width: 32, height: 32, }, format: 'png'},
// {path: `public/favicon/favicon-96x96.png`, options: { width: 96, height: 96, }, format: 'png'},
// {path: `public/favicon/favicon-256x256.png`, options: { width: 256, height: 256, }, format: 'png'},
// {path: `public/favicon/ms-icon-70x70.png`, options: { width: 70, height: 70, }, format: 'png'},
// {path: `public/favicon/ms-icon-144x144.png`, options: { width: 144, height: 144, }, format: 'png'},
// {path: `public/favicon/ms-icon-150x150.png`, options: { width: 150, height: 150, }, format: 'png'},
// {path: `public/favicon/ms-icon-310x310.png`, options: { width: 310, height: 310, }, format: 'png'},
]
for (const favicon of favicons) {
transformImage(response, favicon.path, favicon.options, favicon.format)
}
}
async function fetchHomepageData() {
const fields = [
"*",
];
const url = `/items/homepage?${fields
.map((item) => `fields[]=${item}`)
.join("&")}`;
const homepage = (await fetchJSONApi(url)).data;
await downloadImage(homepage.image, `public/homepage.webp`, { width: 1280, height: 720, fit: sharp.fit.cover })
const favicons = [
{path: `public/favicon/android-icon-192x192.png`, options: { width: 192, height: 192, fit: sharp.fit.contain, background: { r: 255, g: 255, b: 255, alpha: 0 } }, format: 'png'},
{path: `public/favicon/apple-icon-57x57.png`, options: { width: 57, height: 57, fit: sharp.fit.contain, background: { r: 255, g: 255, b: 255, alpha: 0 } }, format: 'png'},
{path: `public/favicon/apple-icon-60x60.png`, options: { width: 60, height: 60, fit: sharp.fit.contain, background: { r: 255, g: 255, b: 255, alpha: 0 } }, format: 'png'},
{path: `public/favicon/apple-icon-72x72.png`, options: { width: 72, height: 72, fit: sharp.fit.contain, background: { r: 255, g: 255, b: 255, alpha: 0 } }, format: 'png'},
{path: `public/favicon/apple-icon-76x76.png`, options: { width: 76, height: 76, fit: sharp.fit.contain, background: { r: 255, g: 255, b: 255, alpha: 0 } }, format: 'png'},
{path: `public/favicon/apple-icon-114x114.png`, options: { width: 114, height: 114, fit: sharp.fit.contain, background: { r: 255, g: 255, b: 255, alpha: 0 } }, format: 'png'},
{path: `public/favicon/apple-icon-120x120.png`, options: { width: 120, height: 120, fit: sharp.fit.contain, background: { r: 255, g: 255, b: 255, alpha: 0 } }, format: 'png'},
{path: `public/favicon/apple-icon-144x144.png`, options: { width: 144, height: 144, fit: sharp.fit.contain, background: { r: 255, g: 255, b: 255, alpha: 0 } }, format: 'png'},
{path: `public/favicon/apple-icon-152x152.png`, options: { width: 152, height: 152, fit: sharp.fit.contain, background: { r: 255, g: 255, b: 255, alpha: 0 } }, format: 'png'},
{path: `public/favicon/apple-icon-180x180.png`, options: { width: 180, height: 180, fit: sharp.fit.contain, background: { r: 255, g: 255, b: 255, alpha: 0 } }, format: 'png'},
{path: `public/favicon/favicon-16x16.png`, options: { width: 16, height: 16, fit: sharp.fit.contain, background: { r: 255, g: 255, b: 255, alpha: 0 } }, format: 'png'},
{path: `public/favicon/favicon-32x32.png`, options: { width: 32, height: 32, fit: sharp.fit.contain, background: { r: 255, g: 255, b: 255, alpha: 0 }, }, format: 'png'},
{path: `public/favicon/favicon-96x96.png`, options: { width: 96, height: 96, fit: sharp.fit.contain, background: { r: 255, g: 255, b: 255, alpha: 0 } }, format: 'png'},
{path: `public/favicon/favicon-256x256.png`, options: { width: 256, height: 256, fit: sharp.fit.contain, background: { r: 255, g: 255, b: 255, alpha: 0 } }, format: 'png'},
{path: `public/favicon/ms-icon-70x70.png`, options: { width: 70, height: 70, fit: sharp.fit.contain, background: { r: 255, g: 255, b: 255, alpha: 0 } }, format: 'png'},
{path: `public/favicon/ms-icon-144x144.png`, options: { width: 144, height: 144, fit: sharp.fit.contain, background: { r: 255, g: 255, b: 255, alpha: 0 } }, format: 'png'},
{path: `public/favicon/ms-icon-150x150.png`, options: { width: 150, height: 150, fit: sharp.fit.contain, background: { r: 255, g: 255, b: 255, alpha: 0 } }, format: 'png'},
{path: `public/favicon/ms-icon-310x310.png`, options: { width: 310, height: 310, fit: sharp.fit.contain, background: { r: 255, g: 255, b: 255, alpha: 0 } }, format: 'png'},
]
for (const favicon of favicons) {
downloadImage(homepage.logo, favicon.path, favicon.options, favicon.format)
}
}
async function fetchData() {
await fetchHomepageData();
}
fetchData(); fetchData();

Binary file not shown.

Before

Width:  |  Height:  |  Size: 626 KiB

View File

@ -108,7 +108,7 @@ legend
text-align: center text-align: center
font-size: 1.4rem font-size: 1.4rem
line-height: 2rem line-height: 2rem
margin: 1rem margin: 0 1rem
.choices .choices
list-style-type: none list-style-type: none
@ -140,10 +140,12 @@ legend
left: 3px left: 3px
width: calc(1rem - 6px) width: calc(1rem - 6px)
height: calc(1rem - 6px) height: calc(1rem - 6px)
&:checked + label
font-weight: bold
&:checked + label::before &:checked + label::before
background-color: white
&:checked + label::after
background-color: var(--color-green) background-color: var(--color-green)
&:checked + label::after
background-color: white
.main .main
height: 100% height: 100%

View File

@ -9,6 +9,7 @@ import { Splide, SplideSlide } from "@splidejs/vue-splide";
import Question from "./Question.vue"; import Question from "./Question.vue";
import "@splidejs/splide/dist/css/splide.min.css"; import "@splidejs/splide/dist/css/splide.min.css";
import ScoreHeader from "./ScoreHeader.vue"; import ScoreHeader from "./ScoreHeader.vue";
import html2canvas from "html2canvas"
const props = defineProps({ const props = defineProps({
id: { id: {
@ -110,6 +111,12 @@ function nextQuestion() {
console.log(slides); console.log(slides);
}, 100); }, 100);
} }
async function share() {
console.log(document.querySelector(".latest"))
const canvas = await html2canvas(document.querySelector(".latest"))
await navigator.share(canvas);
}
</script> </script>
<template> <template>
@ -135,7 +142,7 @@ function nextQuestion() {
@nextQuestion="nextQuestion" @nextQuestion="nextQuestion"
/> />
</SplideSlide> </SplideSlide>
<SplideSlide class="latest" id="details"> <SplideSlide class="latest">
<template v-if="displayScoreResult && result"> <template v-if="displayScoreResult && result">
<div> <div>
<h2 class="center">Probabilité d'échec</h2> <h2 class="center">Probabilité d'échec</h2>
@ -162,7 +169,7 @@ function nextQuestion() {
</li> </li>
</ul> </ul>
</div> </div>
<button>Partager</button> <button @click="() => share()">Partager</button>
</div> </div>
</template> </template>
<template v-else> <template v-else>
@ -258,9 +265,9 @@ label
.details .details
text-align: left text-align: left
font-size: 1.1rem font-size: .9rem
border: 1px solid var(--color-highlight-text) border: 1px solid var(--color-highlight-text)
background: var(--color-text) background: var(--color-highlight-background)
margin: 1rem margin: 1rem
padding: 1rem padding: 1rem

View File

@ -123,6 +123,7 @@ function getTranslation(translations, key) {
</ul> </ul>
</header> </header>
<main> <main>
<img src="/homepage.webp" class="homeImage">
<div class="container" v-if="scores"> <div class="container" v-if="scores">
<ul> <ul>
<template v-for="(score, index) in scores" :key="score.id"> <template v-for="(score, index) in scores" :key="score.id">
@ -177,14 +178,24 @@ header
main main
width: 100% width: 100%
height: calc(100% - var(--header-size)) height: calc(100% - var(--header-size))
padding: 1rem background-color: var(--color-background)
flex-direction: column
overflow: auto
.homeImage
height: 30vh
width: calc(100% + 2rem)
padding: 0
object-fit: contain
margin-left: -1rem
.container
display: flex display: flex
justify-content: center justify-content: center
align-items: center align-items: center
overflow: hidden overflow: hidden
background-color: var(--color-background) padding: 1rem
.container
ul ul
margin: 0 margin: 0
padding: 0 padding: 0
@ -193,6 +204,7 @@ main
flex-wrap: wrap flex-wrap: wrap
justify-content: center justify-content: center
max-width: 404px max-width: 404px
border: 1px solid var(--color-green)
li li
height: 202px height: 202px
@ -206,6 +218,7 @@ main
a a
font-size: 2rem font-size: 2rem
line-height: 2rem
color: var(--color-green) color: var(--color-green)
display: block display: block
width: 100% width: 100%
@ -215,4 +228,5 @@ main
justify-content: center justify-content: center
text-align: center text-align: center
padding: 1rem padding: 1rem
text-decoration: none
</style> </style>

View File

@ -1,14 +1,20 @@
import { createRouter, createWebHashHistory } from "vue-router"; import { createRouter, createWebHistory } from "vue-router";
import HomeView from "@/views/HomeView.vue"; import HomeView from "@/views/HomeView.vue";
import { useAuthStore } from "@/stores";
const router = createRouter({ const router = createRouter({
history: createWebHashHistory(import.meta.env.BASE_URL), history: createWebHistory(import.meta.env.BASE_URL),
routes: [ routes: [
{ {
path: "/", path: "/",
name: "home", name: "home",
component: HomeView, component: HomeView,
}, },
{
path: "/login",
name: "login",
component: () => import("./views/LoginView.vue"),
},
{ {
path: "/scores/:id", path: "/scores/:id",
name: "score", name: "score",
@ -18,4 +24,19 @@ const router = createRouter({
], ],
}); });
router.beforeEach((to, from) => {
// instead of having to check every route record with
// to.matched.some(record => record.meta.requiresAuth)
const auth = useAuthStore();
if (to.meta.requiresAuth && !auth.user) {
// this route requires auth, check if logged in
// if not, redirect to login page.
return {
path: "/login",
// save the location we were at to come back later
query: { redirect: to.fullPath },
};
}
});
export default router; export default router;

View File

@ -30,3 +30,31 @@ export const useStore = defineStore({
}, },
}, },
}); });
export const useAuthStore = defineStore({
id: "auth",
state: () => ({
// initialize state from local storage to enable user to stay logged in
user: JSON.parse(localStorage.getItem("user")),
returnUrl: null,
}),
actions: {
async login(username, password) {
const user = "test";
// update pinia state
this.user = user;
// store user details and jwt in local storage to keep user logged in between page refreshes
localStorage.setItem("user", JSON.stringify(user));
// redirect to previous url or default to home page
router.push(this.returnUrl || "/");
},
logout() {
this.user = null;
localStorage.removeItem("user");
router.push("/login");
},
},
});

45
src/views/LoginView.vue Normal file
View File

@ -0,0 +1,45 @@
<script setup></script>
<template>
<div>
<div class="alert alert-info">
Username: test<br />
Password: test
</div>
<h2>Login</h2>
<form @submit="onSubmit" :validation-schema="schema">
<div class="form-group">
<label>Username</label>
<input
name="username"
type="text"
class="form-control"
:class="{ 'is-invalid': errors.username }"
/>
<div class="invalid-feedback">{{ errors.username }}</div>
</div>
<div class="form-group">
<label>Password</label>
<input
name="password"
type="password"
class="form-control"
:class="{ 'is-invalid': errors.password }"
/>
<div class="invalid-feedback">{{ errors.password }}</div>
</div>
<div class="form-group">
<button class="btn btn-primary" :disabled="isSubmitting">
<span
v-show="isSubmitting"
class="spinner-border spinner-border-sm mr-1"
></span>
Login
</button>
</div>
<div v-if="errors.apiError" class="alert alert-danger mt-3 mb-0">
{{ errors.apiError }}
</div>
</form>
</div>
</template>