Skip to content

Commit

Permalink
version store changelog new file checker
Browse files Browse the repository at this point in the history
  • Loading branch information
riccardoperra committed Dec 11, 2023
1 parent 4af79e6 commit 6eb4561
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 18 deletions.
16 changes: 9 additions & 7 deletions apps/codeimage/src/components/Changelog/resolveChangelog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,20 @@ interface ChangelogEntry {
path: string;
component: () => Promise<{default: Component}>;
}

export function parseChangelogFilePath(path: string) {
const [version, date] = (path.split('/').at(-1) as string)
.replace('.mdx', '')
.split('_');
return {version: version.replaceAll('-', '.'), date};
}
export function resolveChangelog(props: ChangelogEntry) {
const Component = (mdxProps: MDXProps) =>
createComponent(lazy(props.component), mdxProps);

const data = () => {
const [version, date] = (props.path.split('/').at(-1) as string)
.replace('.mdx', '')
.split('_');
return {version, date};
};
const data = () => parseChangelogFilePath(props.path);

const version = () => data().version.replaceAll('-', '.');
const version = () => data().version;

const date = () => {
const [month, day, year] = data()
Expand Down
37 changes: 26 additions & 11 deletions apps/codeimage/src/state/version/version.store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import {getUmami} from '@core/constants/umami';
import {createControlledDialog} from '@core/hooks/createControlledDialog';
import {
Accessor,
batch,
createEffect,
createSignal,
getOwner,
Expand All @@ -16,6 +15,7 @@ import {
import {unwrap} from 'solid-js/store';
import {defineStore} from 'statebuilder';
import {Changelog} from '../../components/Changelog/Changelog';
import {parseChangelogFilePath} from '../../components/Changelog/resolveChangelog';

interface Feature {
name: string;
Expand All @@ -39,6 +39,10 @@ interface VersionStore {

export type FeatureName = 'fontPicker' | 'windowStylePicker';

const ChangelogFiles = Object.keys(
import.meta.glob('../../../changelog/*.mdx'),
).map(parseChangelogFilePath);

function initialValue(): VersionStore {
return {
appVersion: appEnvironment.version,
Expand All @@ -62,9 +66,13 @@ export const VersionStore = defineStore<VersionStore>(initialValue)
const [ready, setReady] = createSignal(false);
const controlledDialog = createControlledDialog();

function seeLatestVersion() {
const currentVersion = appEnvironment.version;
_.set('seen', seen => [...new Set([...seen, currentVersion])]);
function updateWithLatestVersionSeen(
currentVersion: string,
data: VersionStore,
): VersionStore {
const versionSeen = new Set([...data.seen, currentVersion]);
data.seen = [...versionSeen];
return data;
}

onMount(() => {
Expand All @@ -89,15 +97,22 @@ export const VersionStore = defineStore<VersionStore>(initialValue)
});
}
if (isFirstTime || hasNewUpdate) {
controlledDialog(Changelog, {latest: false});
batch(() => {
seeLatestVersion();
const fileVersions = ChangelogFiles.map(({version}) => version);
const hasNewVersionToSee = fileVersions.includes(data.appVersion);
console.log(isFirstTime, hasNewUpdate, hasNewVersionToSee);

if (isFirstTime || hasNewVersionToSee) {
controlledDialog(Changelog, {latest: true});
const updatedData = updateWithLatestVersionSeen(
currentVersion,
data,
);
_.set(() => updatedData);
} else {
_.set(() => data);
});
}
} else {
const versionSeen = new Set([...data.seen, currentVersion]);
data.seen = [...versionSeen];
_.set(() => data);
_.set(() => updateWithLatestVersionSeen(currentVersion, data));
}
setReady(true);
}
Expand Down

0 comments on commit 6eb4561

Please sign in to comment.