Skip to content

Commit a6e181c

Browse files
Merge pull request #2 from PromptExecution/feature/pinia
feature/pinia
2 parents c05dec4 + 972fddc commit a6e181c

File tree

9 files changed

+119
-24
lines changed

9 files changed

+119
-24
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,4 @@ dist/*
1818
**/*.pyc
1919

2020
bun.lockb
21+
*.mjs

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
},
1111
"dependencies": {
1212
"path": "^0.12.7",
13+
"pinia": "^2.1.7",
1314
"vue": "^3.3.8",
1415
"vue-command": "^35.2.1",
1516
"vue-cookie-law": "github:elasticdotventures/vue-cookie-law",

src/App.vue

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ import CookieBanner from './components/CookieBanner.vue';
66
import CommandLineInterface from './components/CommandLineInterface.vue';
77
import PromptExecutionLogo from './components/PromptExecutionLogo.vue';
88
9+
import { useMainStore } from './store';
10+
const mainStore = useMainStore();
11+
912
const showBanner = ref(true); // Or whatever logic you need to show/hide the banner
1013
1114
// Example of how you might control the visibility of the banner
@@ -26,7 +29,7 @@ import TheFooter from './components/TheFooter.vue';
2629
<CommandLineInterface />
2730
<TheFooter />
2831

29-
<CookieBanner v-if="showBanner" />
32+
<CookieBanner v-if="!mainStore.isCookieConsentSet" />
3033
</template>
3134

3235
<style scoped>

src/components/CommandLineInterface.vue

Lines changed: 26 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,29 @@
1+
<script setup lang="ts">
2+
import VueCommand, { createStdout } from "vue-command";
3+
import "vue-command/dist/vue-command.css";
4+
import { useMainStore } from '../store';
5+
import LoginPanel from './LoginPanel.vue';
6+
import DebugPanel from './DebugPanel.vue';
7+
8+
const mainStore = useMainStore();
9+
10+
const commands = {
11+
"help": () => createStdout("Available commands: hello, login, debug"),
12+
"login": () => {
13+
mainStore.toggleLogin();
14+
return createStdout("Login interface activated.");
15+
},
16+
"hello": () => createStdout("Hello world! #wip"),
17+
"debug": () => {
18+
mainStore.toggleDebugPanel();
19+
return createStdout("Debug panel activated.");
20+
},
21+
};
22+
</script>
23+
124
<template>
225
<div class="cli-container">
3-
<vue-command :commands="commands" :hide-buttons="true" :show-help="true" :cursor-position="0" :is-fullscreen="true">
26+
<vue-command :commands="commands" :hide-buttons="true" :show-help="true" :cursor-position="0" :is-fullscreen="true">
427
<template #title>Command Line Interface v0.1 -- type "help" for instructions</template>
528
<template #prompt>
629
<span class="prompt">
@@ -13,31 +36,12 @@
1336
<template #help-text>asdfasdf</template>
1437
<template #invert>true</template>
1538
<template #font></template>
16-
1739
</vue-command>
40+
<LoginPanel v-if="mainStore.showLogin" />
41+
<DebugPanel v-if="mainStore.showDebugPanel" />
1842
</div>
1943
</template>
2044

21-
<script lang="ts">
22-
// https://github.com/ndabAP/vue-command
23-
import VueCommand, { createStdout } from "vue-command";
24-
import "vue-command/dist/vue-command.css";
25-
26-
export default {
27-
components: {
28-
VueCommand,
29-
},
30-
31-
data: () => ({
32-
commands: {
33-
"help": () => createStdout("Available commands: hello, login"),
34-
"login": () => createStdout("Login not available (coming soon!)"),
35-
"hello": () => createStdout("Hello world! #wip"),
36-
},
37-
}),
38-
};
39-
</script>
40-
4145
<style scoped>
4246
.cli-container {
4347
/* Adjust the border-radius as needed */

src/components/CookieBanner.vue

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,23 +12,27 @@
1212
<script lang="ts">
1313
import useCookies from '../useCookies';
1414
import { defineComponent, getCurrentInstance } from 'vue';
15+
import { useMainStore } from '../store';
1516
1617
export default defineComponent({
1718
setup() {
1819
const instance = getCurrentInstance();
1920
const gtag = instance?.appContext.config.globalProperties.$gtag;
21+
const mainStore = useMainStore();
2022
2123
const { allowCookies } = useCookies(gtag);
2224
2325
const handleConsent = () => {
2426
allowCookies.value = true;
27+
mainStore.setCookieConsent('accepted');
2528
if (gtag) {
2629
gtag.optIn();
2730
}
2831
};
2932
3033
const handleReject = () => {
3134
allowCookies.value = false;
35+
mainStore.setCookieConsent('rejected');
3236
if (gtag) {
3337
gtag.optOut();
3438
}

src/components/DebugPanel.vue

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<!-- src/components/DebugPanel.vue -->
2+
<template>
3+
<div class="debug-panel">
4+
<pre>{{ state }}</pre>
5+
<button @click="resetCookieConsent">Reset Cookie Consent</button>
6+
</div>
7+
</template>
8+
9+
<script setup lang="ts">
10+
import { useMainStore } from '../store';
11+
12+
const mainStore = useMainStore();
13+
const state = mainStore.$state;
14+
15+
const resetCookieConsent = () => {
16+
mainStore.resetCookieConsent();
17+
};
18+
</script>
19+
20+
<style scoped>
21+
.debug-panel {
22+
/* Add your styles for the debug panel here */
23+
}
24+
</style>
25+

src/components/LoginPanel.vue

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<!-- src/components/LoginPanel.vue -->
2+
<template>
3+
<div class="login-buttons">
4+
<button>Sign in with Google</button>
5+
<button>Sign in with Facebook</button>
6+
<!-- More buttons as needed -->
7+
</div>
8+
</template>
9+
10+
<script setup lang="ts">
11+
// Add any script logic if needed
12+
</script>
13+
14+
<style scoped>
15+
.login-buttons {
16+
/* Add your styles for the login buttons here */
17+
}
18+
</style>
19+

src/main.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,14 @@ import App from './App.vue'
66
// https://matteo-gabriele.gitbook.io/vue-gtag/
77
import VueGtag from "vue-gtag";
88
import { VueCookieNext } from 'vue-cookie-next';
9-
import { useCookies } from './useCookies'
9+
import { createPinia } from 'pinia'
1010

1111
// An application instance won't render anything until its .mount() method is called
1212
const app = createApp(App);
13+
const pinia = createPinia()
1314

1415
app
16+
.use(pinia)
1517
.use(VueCookieNext)
1618
.use(VueGtag, {
1719
config: {
@@ -24,3 +26,4 @@ app
2426
})
2527
.provide('gtag', app.config.globalProperties.$gtag)
2628
.mount('#app')
29+

src/store.ts

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
// src/store.js
2+
import { defineStore } from 'pinia'
3+
4+
export const useMainStore = defineStore('main', {
5+
state: () => ({
6+
count: 0,
7+
// cookieConsent: null // null, 'accepted', or 'rejected'
8+
cookieConsent: localStorage.getItem('cookieConsent'),
9+
showLogin: false,
10+
showDebugPanel: false,
11+
}),
12+
actions: {
13+
increment() {
14+
this.count++
15+
},
16+
setCookieConsent(value) {
17+
this.cookieConsent = value
18+
localStorage.setItem('cookieConsent', value)
19+
},
20+
resetCookieConsent() {
21+
this.cookieConsent = null;
22+
localStorage.removeItem('cookieConsent');
23+
},
24+
toggleLogin(show) {
25+
this.showLogin = !this.showLogin;
26+
},
27+
toggleDebugPanel(show) {
28+
this.showDebugPanel = !this.showDebugPanel;
29+
}
30+
},
31+
getters: {
32+
isCookieConsentSet: (state) => state.cookieConsent !== null
33+
}
34+
})
35+

0 commit comments

Comments
 (0)