Skip to content

Commit

Permalink
feat: Adapt the app for the new Lenra API (#38)
Browse files Browse the repository at this point in the history
  • Loading branch information
taorepoara authored Oct 16, 2023
1 parent 5a91e26 commit f699285
Show file tree
Hide file tree
Showing 26 changed files with 5,364 additions and 5,093 deletions.
4 changes: 3 additions & 1 deletion .github/workflows/lenra-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ jobs:
uses: ndeloof/[email protected]
- run: docker-compose --version
- name: Install Lenra CLI
run: wget -c https://github.com/lenra-io/lenra_cli/releases/latest/download/lenra-linux-x86_64.tar.gz -O - | tar -xz
run: wget -c https://github.com/lenra-io/lenra_cli/releases/latest/download/lenra-linux-x86_64 -O lenra
- name: Make Lenra CLI executable
run: chmod +x lenra
- name: Build app
run: ./lenra build
2 changes: 1 addition & 1 deletion .template
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
https://github.com/lenra-io/template-javascript
398416b76fc237291280de3efb719504c43cf563
aa877374123282219c6dae4b2aa04724b4bc6ae5
2 changes: 1 addition & 1 deletion lenra.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ generator:
- .
cmd:
- node
- node_modules/@lenra/app-server/dist/bin/app-lenra.js
- node_modules/@lenra/app/dist/bin/app-lenra.js
envs:
NODE_ENV: production
ports:
Expand Down
105 changes: 20 additions & 85 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 2 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,12 @@
"author": "Lenra",
"license": "MIT",
"dependencies": {
"@lenra/app-server": "^1.0.0-beta.3",
"@lenra/components": "^1.0.0-beta.7"
"@lenra/app": "^1.0.0"
},
"devDependencies": {
"@moox/markdown-to-json": "^1.0.0",
"camping-des-speakers": "github:RdvSpeakers/camping-des-speakers-website",
"front-matter": "^4.0.2",
"jest": "^29.5.0"
}
}
}
2 changes: 1 addition & 1 deletion src/classes/Favorite.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Data } from "@lenra/app-server";
import { Data } from "@lenra/app";

export class Favorite extends Data {
/**
Expand Down
2 changes: 1 addition & 1 deletion src/classes/Note.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Data } from "@lenra/app-server";
import { Data } from "@lenra/app";

export class Note extends Data {
/**
Expand Down
26 changes: 0 additions & 26 deletions src/index.gen.js

This file was deleted.

26 changes: 14 additions & 12 deletions src/listeners/favorite.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,31 @@ import { Favorite } from "../classes/Favorite.js";

/**
*
* @param {import("@lenra/app-server").props} props
* @param {import("@lenra/app-server").event} _event
* @param {import("@lenra/app-server").Api} api
* @param {import("@lenra/app").props} props
* @param {import("@lenra/app").event} _event
* @param {import("@lenra/app").Api} api
*/
export async function toggleFavorite(props, _event, api) {
const [fav] = await api.data.find(Favorite, { user: "@me" })
if (!fav) return api.data.createDoc(new Favorite([props.session], "@me"));
const collection = api.data.coll(Favorite);
const [fav] = await collection.find({ user: "@me" })
if (!fav) return collection.createDoc(new Favorite([props.session], "@me"));

if (fav.sessions.includes(props.session)) fav.sessions = fav.sessions.filter(s => s !== props.session);
else fav.sessions.push(props.session);
await api.data.updateDoc(fav);
await collection.updateDoc(fav);
}

/**
*
* @param {import("@lenra/app-server").props} props
* @param {import("@lenra/app-server").event} _event
* @param {import("@lenra/app-server").Api} api
* @param {import("@lenra/app").props} props
* @param {import("@lenra/app").event} _event
* @param {import("@lenra/app").Api} api
*/
export async function toggleFavoriteFilter(props, _event, api) {
console.log("_event", _event);
const [fav] = await api.data.find(Favorite, { user: "@me" })
if (!fav) return api.data.createDoc(new Favorite([], "@me", true));
const collection = api.data.coll(Favorite);
const [fav] = await collection.find({ user: "@me" })
if (!fav) return collection.createDoc(new Favorite([], "@me", true));
fav.filter = !fav.filter;
await api.data.updateDoc(fav);
await collection.updateDoc(fav);
}
22 changes: 12 additions & 10 deletions src/listeners/note.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,29 @@ import { Note } from "../classes/Note.js";

/**
*
* @param {import("@lenra/app-server").props} props
* @param {import("@lenra/app-server").event} event
* @param {import("@lenra/app-server").Api} api
* @param {import("@lenra/app").props} props
* @param {import("@lenra/app").event} event
* @param {import("@lenra/app").Api} api
*/
export async function saveNote(props, event, api) {
const collection = api.data.coll(Note);
if (props._id) {
props.note = event.value.note;
return api.data.updateDoc(props);
return collection.updateDoc(props);
}
return api.data.createDoc(new Note(props.session, "@me", event.value.note));
return collection.createDoc(new Note(props.session, "@me", event.value.note));
}

/**
*
* @param {import("@lenra/app-server").props} props
* @param {import("@lenra/app-server").event} event
* @param {import("@lenra/app-server").Api} api
* @param {import("@lenra/app").props} props
* @param {import("@lenra/app").event} event
* @param {import("@lenra/app").Api} api
*/
export async function deleteNote(props, event, api) {
const collection = api.data.coll(Note);
console.log(props);
let note = await api.data.getDoc(Note, props._id);
let note = await collection.getDoc(props._id);

return api.data.deleteDoc(note);
return collection.deleteDoc(note);
}
18 changes: 9 additions & 9 deletions src/listeners/systemEvents.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,29 @@

/**
*
* @param {import("@lenra/app-server").props} _props
* @param {import("@lenra/app-server").event} _event
* @param {import("@lenra/app-server").Api} _api
* @param {import("@lenra/app").props} _props
* @param {import("@lenra/app").event} _event
* @param {import("@lenra/app").Api} _api
*/
export async function onEnvStart(_props, _event, _api) {

}

/**
*
* @param {import("@lenra/app-server").props} _props
* @param {import("@lenra/app-server").event} _event
* @param {import("@lenra/app-server").Api} _api
* @param {import("@lenra/app").props} _props
* @param {import("@lenra/app").event} _event
* @param {import("@lenra/app").Api} _api
*/
export async function onUserFirstJoin(_props, _event, api) {

}

/**
*
* @param {import("@lenra/app-server").props} _props
* @param {import("@lenra/app-server").event} _event
* @param {import("@lenra/app-server").Api} _api
* @param {import("@lenra/app").props} _props
* @param {import("@lenra/app").event} _event
* @param {import("@lenra/app").Api} _api
*/
export async function onSessionStart(_props, _event, _api) {

Expand Down
Loading

0 comments on commit f699285

Please sign in to comment.