33 lines
1.6 KiB
JavaScript
33 lines
1.6 KiB
JavaScript
// When to offer the Symfony tutorial: once, right after a NEW Symfony project is made (New Project > Web site > Symfony).
|
|
// Pure logic over a small store ({get, set}); the dialog is in tutorial.js. "Don't offer it again" is a setting of the user
|
|
// (the IDE's, not the project's), undone in Settings; the tutorial stays reachable from Help anyway.
|
|
|
|
export const NEVER_KEY = 'tutorial:never-offer';
|
|
export const PENDING_KEY = 'tutorial:offer-pending';
|
|
export const OFFERED_KEY = 'tutorial:offered';
|
|
|
|
/** A Symfony project: the console is bin/console and the project has a Doctrine / Symfony layout. */
|
|
export function isSymfony(info) {
|
|
return !!info && info.capabilities?.console === 'bin/console';
|
|
}
|
|
|
|
/** The site was just made by New Project: remember its root so that the next opening of that project offers the tutorial. */
|
|
export function markCreated(store, root, type) {
|
|
if (type === 'symfony' && root) store.set(PENDING_KEY, root);
|
|
}
|
|
|
|
/** Is the offer to be shown for this opened project? Consumes the pending mark either way; offered once per project. */
|
|
export function shouldOffer(store, info) {
|
|
const pending = store.get(PENDING_KEY, null);
|
|
if (!pending || !info || pending !== (info.root || info.name)) return false;
|
|
store.set(PENDING_KEY, null);
|
|
if (store.get(NEVER_KEY, false)) return false;
|
|
if (!isSymfony(info)) return false;
|
|
const offered = store.get(OFFERED_KEY, []);
|
|
if (offered.includes(pending)) return false;
|
|
store.set(OFFERED_KEY, [...offered, pending]);
|
|
return true;
|
|
}
|
|
|
|
export function setNeverOffer(store, value) { store.set(NEVER_KEY, !!value); }
|
|
export function neverOffer(store) { return !!store.get(NEVER_KEY, false); }
|