diff --git a/.gitignore b/.gitignore index decca83..6cad1a4 100644 --- a/.gitignore +++ b/.gitignore @@ -22,4 +22,7 @@ dist-ssr *.njsproj *.sln *.sw? -*.cache \ No newline at end of file +*.cache + +# Bundle Analyzer +stats.html \ No newline at end of file diff --git a/package-lock.json b/package-lock.json index 280179d..f04dd8d 100644 --- a/package-lock.json +++ b/package-lock.json @@ -9,7 +9,6 @@ "version": "0.0.0", "dependencies": { "browser-image-compression": "^2.0.2", - "dompurify": "^3.1.3", "dotenv": "^16.4.5", "firebase": "^10.12.0", "marked": "^12.0.2", @@ -25,6 +24,7 @@ "@types/node": "^20.12.12", "@vitejs/plugin-vue": "^5.0.4", "@vue/tsconfig": "^0.5.1", + "rollup-plugin-visualizer": "^5.12.0", "sass": "^1.77.1", "typescript": "^5.4.5", "vite": "^5.2.0" @@ -2156,10 +2156,14 @@ "resolved": "https://registry.npmjs.org/csstype/-/csstype-3.1.3.tgz", "integrity": "sha512-M1uQkMl8rQK/szD0LNhtqxIPLpimGm8sOBwU7lLnCpSbTyY3yeU1Vc7l4KT5zT4s/yOxHH5O7tIuuLOCnLADRw==" }, - "node_modules/dompurify": { - "version": "3.1.3", - "resolved": "https://registry.npmjs.org/dompurify/-/dompurify-3.1.3.tgz", - "integrity": "sha512-5sOWYSNPaxz6o2MUPvtyxTTqR4D3L77pr5rUQoWgD5ROQtVIZQgJkXbo1DLlK3vj11YGw5+LnF4SYti4gZmwng==" + "node_modules/define-lazy-prop": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/define-lazy-prop/-/define-lazy-prop-2.0.0.tgz", + "integrity": "sha512-Ds09qNh8yw3khSjiJjiUInaGX9xlqZDY7JVryGxdxV7NPeuqQfplOpQ66yJFZut3jLa5zOwkXw1g9EI2uKh4Og==", + "dev": true, + "engines": { + "node": ">=8" + } }, "node_modules/dotenv": { "version": "16.4.5", @@ -2358,6 +2362,21 @@ "node": ">=8" } }, + "node_modules/is-docker": { + "version": "2.2.1", + "resolved": "https://registry.npmjs.org/is-docker/-/is-docker-2.2.1.tgz", + "integrity": "sha512-F+i2BKsFrH66iaUFc0woD8sLy8getkwTwtOBjvs56Cx4CgJDeKQeqfz8wAYiSb8JOprWhHH5p77PbmYCvvUuXQ==", + "dev": true, + "bin": { + "is-docker": "cli.js" + }, + "engines": { + "node": ">=8" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, "node_modules/is-extglob": { "version": "2.1.1", "resolved": "https://registry.npmjs.org/is-extglob/-/is-extglob-2.1.1.tgz", @@ -2396,6 +2415,18 @@ "node": ">=0.12.0" } }, + "node_modules/is-wsl": { + "version": "2.2.0", + "resolved": "https://registry.npmjs.org/is-wsl/-/is-wsl-2.2.0.tgz", + "integrity": "sha512-fKzAra0rGJUUBwGBgNkHZuToZcn+TtXHpeCgmkMJMMYx1sQDYaCSyjJBSCa2nH1DGm7s3n1oBnohoVTBaN7Lww==", + "dev": true, + "dependencies": { + "is-docker": "^2.0.0" + }, + "engines": { + "node": ">=8" + } + }, "node_modules/linkify-it": { "version": "5.0.0", "resolved": "https://registry.npmjs.org/linkify-it/-/linkify-it-5.0.0.tgz", @@ -2736,6 +2767,58 @@ "fsevents": "~2.3.2" } }, + "node_modules/rollup-plugin-visualizer": { + "version": "5.12.0", + "resolved": "https://registry.npmjs.org/rollup-plugin-visualizer/-/rollup-plugin-visualizer-5.12.0.tgz", + "integrity": "sha512-8/NU9jXcHRs7Nnj07PF2o4gjxmm9lXIrZ8r175bT9dK8qoLlvKTwRMArRCMgpMGlq8CTLugRvEmyMeMXIU2pNQ==", + "dev": true, + "dependencies": { + "open": "^8.4.0", + "picomatch": "^2.3.1", + "source-map": "^0.7.4", + "yargs": "^17.5.1" + }, + "bin": { + "rollup-plugin-visualizer": "dist/bin/cli.js" + }, + "engines": { + "node": ">=14" + }, + "peerDependencies": { + "rollup": "2.x || 3.x || 4.x" + }, + "peerDependenciesMeta": { + "rollup": { + "optional": true + } + } + }, + "node_modules/rollup-plugin-visualizer/node_modules/open": { + "version": "8.4.2", + "resolved": "https://registry.npmjs.org/open/-/open-8.4.2.tgz", + "integrity": "sha512-7x81NCL719oNbsq/3mh+hVrAWmFuEYUqrq/Iw3kUzH8ReypT9QQ0BLoJS7/G9k6N81XjW4qHWtjWwe/9eLy1EQ==", + "dev": true, + "dependencies": { + "define-lazy-prop": "^2.0.0", + "is-docker": "^2.1.1", + "is-wsl": "^2.2.0" + }, + "engines": { + "node": ">=12" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/rollup-plugin-visualizer/node_modules/source-map": { + "version": "0.7.4", + "resolved": "https://registry.npmjs.org/source-map/-/source-map-0.7.4.tgz", + "integrity": "sha512-l3BikUxvPOcn5E74dZiq5BGsTb5yEwhaTSzccU6t4sDOH8NWJCstKO5QT2CvtFoK6F0saL7p9xHAqHOlCPJygA==", + "dev": true, + "engines": { + "node": ">= 8" + } + }, "node_modules/safe-buffer": { "version": "5.2.1", "resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.2.1.tgz", diff --git a/package.json b/package.json index 56a1ab1..b3aa2d6 100644 --- a/package.json +++ b/package.json @@ -10,7 +10,6 @@ }, "dependencies": { "browser-image-compression": "^2.0.2", - "dompurify": "^3.1.3", "dotenv": "^16.4.5", "firebase": "^10.12.0", "marked": "^12.0.2", @@ -26,6 +25,7 @@ "@types/node": "^20.12.12", "@vitejs/plugin-vue": "^5.0.4", "@vue/tsconfig": "^0.5.1", + "rollup-plugin-visualizer": "^5.12.0", "sass": "^1.77.1", "typescript": "^5.4.5", "vite": "^5.2.0" diff --git a/src/app.vue b/src/app.vue index 38f9072..54c3791 100644 --- a/src/app.vue +++ b/src/app.vue @@ -1,73 +1,16 @@ - diff --git a/src/main.ts b/src/main.ts index cb604dd..564cfcf 100644 --- a/src/main.ts +++ b/src/main.ts @@ -1,17 +1,24 @@ import { createApp } from "vue"; import App from "./app.vue"; import router from "./routes"; -import { VueShowdownPlugin } from "vue-showdown"; import { createPinia } from "pinia"; -import piniaPluginPersistedstate from "pinia-plugin-persistedstate"; +const app = createApp(App); const pinia = createPinia(); -pinia.use(piniaPluginPersistedstate); -createApp(App) - .use(pinia) - .use(router) - .use(VueShowdownPlugin, { +async function loadPlugins() { + // Dynamically import the VueShowdownPlugin + const { VueShowdownPlugin } = await import("vue-showdown"); + + // Dynamically import the piniaPluginPersistedstate + const { default: piniaPluginPersistedstate } = await import( + "pinia-plugin-persistedstate" + ); + + // Use the plugins + pinia.use(piniaPluginPersistedstate); + + app.use(VueShowdownPlugin, { flavor: "github", options: { emoji: true, @@ -28,5 +35,12 @@ createApp(App) requireSpaceBeforeHeadingText: true, ghMentions: true, }, - }) - .mount("#app"); + }); +} + +// Load plugins conditionally or based on some user interaction +loadPlugins().then(() => { + app.use(pinia); + app.use(router); + app.mount("#app"); +}); diff --git a/src/shared/components/navigation/navigation.vue b/src/shared/components/navigation/navigation.vue index b29277e..9cc7f34 100644 --- a/src/shared/components/navigation/navigation.vue +++ b/src/shared/components/navigation/navigation.vue @@ -11,12 +11,12 @@ Home Blogs Create Post - Login/Register @@ -75,12 +75,12 @@ Home Blogs Create Post - Login/Register @@ -93,15 +93,15 @@ import { ref, computed, defineComponent, onMounted, onBeforeMount } from "vue"; import { AuthService } from "../../services/auth.service"; import { useUserStore } from "../../../stores/users"; import { useRouter } from "vue-router"; -import { auth } from "../../firebase/firebaseInit"; +import { auth } from "../../firebase/firebase-auth"; export default defineComponent({ name: "navigation", props: { - user_login: { + isUserLogin: { type: Boolean, }, - admin: { + isAdmin: { type: Boolean, }, }, diff --git a/src/shared/firebase/firebase-app.ts b/src/shared/firebase/firebase-app.ts new file mode 100644 index 0000000..b37696a --- /dev/null +++ b/src/shared/firebase/firebase-app.ts @@ -0,0 +1,5 @@ +import { initializeApp } from "firebase/app"; +import { firebaseConfig } from "./firebase-config"; + +const firebaseApp = initializeApp(firebaseConfig); +export { firebaseApp }; diff --git a/src/shared/firebase/firebase-auth.ts b/src/shared/firebase/firebase-auth.ts new file mode 100644 index 0000000..6065569 --- /dev/null +++ b/src/shared/firebase/firebase-auth.ts @@ -0,0 +1,4 @@ +import { getAuth } from "firebase/auth"; +import { firebaseApp } from "./firebase-app"; +const auth = getAuth(firebaseApp); +export { auth }; diff --git a/src/shared/firebase/firebase-bucket.ts b/src/shared/firebase/firebase-bucket.ts new file mode 100644 index 0000000..c149e39 --- /dev/null +++ b/src/shared/firebase/firebase-bucket.ts @@ -0,0 +1,4 @@ +import { getStorage } from "firebase/storage"; +import { firebaseApp } from "./firebase-app"; +const bucket = getStorage(firebaseApp); +export { bucket }; diff --git a/src/shared/firebase/firebase-config.ts b/src/shared/firebase/firebase-config.ts new file mode 100644 index 0000000..0f5417a --- /dev/null +++ b/src/shared/firebase/firebase-config.ts @@ -0,0 +1,8 @@ +export const firebaseConfig = { + apiKey: "AIzaSyB9D51M_e4XkvBSoyFZPc8hTaKCTbgqBjk", + authDomain: "vuejs3-fireblog.firebaseapp.com", + projectId: "vuejs3-fireblog", + storageBucket: "vuejs3-fireblog.appspot.com", + messagingSenderId: "954680780309", + appId: "1:954680780309:web:147f187f86f99dc590901c", +}; diff --git a/src/shared/firebase/firebase-firestore.ts b/src/shared/firebase/firebase-firestore.ts new file mode 100644 index 0000000..a1c1ea2 --- /dev/null +++ b/src/shared/firebase/firebase-firestore.ts @@ -0,0 +1,5 @@ +import { firebaseApp } from "./firebase-app"; +import { getFirestore } from "firebase/firestore"; + +const firestore = getFirestore(firebaseApp); +export { firestore }; diff --git a/src/shared/firebase/firebaseInit.ts b/src/shared/firebase/firebaseInit.ts deleted file mode 100644 index 032a311..0000000 --- a/src/shared/firebase/firebaseInit.ts +++ /dev/null @@ -1,20 +0,0 @@ -import { initializeApp } from "firebase/app"; -import { getAuth } from "firebase/auth"; -import { getFirestore } from "firebase/firestore"; -import { getStorage } from "firebase/storage"; - -const firebaseConfig = { - apiKey: "AIzaSyB9D51M_e4XkvBSoyFZPc8hTaKCTbgqBjk", - authDomain: "vuejs3-fireblog.firebaseapp.com", - projectId: "vuejs3-fireblog", - storageBucket: "vuejs3-fireblog.appspot.com", - messagingSenderId: "954680780309", - appId: "1:954680780309:web:147f187f86f99dc590901c", -}; - -const firebaseApp = initializeApp(firebaseConfig); -const firestore = getFirestore(firebaseApp); -const bucket = getStorage(firebaseApp); -const auth = getAuth(firebaseApp); - -export { firebaseApp, firestore, bucket, auth }; diff --git a/src/shared/services/auth.service.ts b/src/shared/services/auth.service.ts index 82f13de..3b0bacf 100644 --- a/src/shared/services/auth.service.ts +++ b/src/shared/services/auth.service.ts @@ -4,7 +4,7 @@ import { signInWithEmailAndPassword, signOut, } from "firebase/auth"; -import { auth } from "../firebase/firebaseInit"; +import { auth } from "../firebase/firebase-auth"; export class AuthService { constructor() {} diff --git a/src/shared/services/post.service.ts b/src/shared/services/post.service.ts index a6829c0..7f7e671 100644 --- a/src/shared/services/post.service.ts +++ b/src/shared/services/post.service.ts @@ -1,6 +1,7 @@ import imageCompression from "browser-image-compression"; -import { collection, doc, getDoc, setDoc, updateDoc } from "firebase/firestore"; -import { bucket, firestore } from "../firebase/firebaseInit"; +import { collection, doc, getDoc, setDoc } from "firebase/firestore"; +import { bucket } from "../firebase/firebase-bucket"; +import { firestore } from "../firebase/firebase-firestore"; import { getDownloadURL, ref, uploadBytes } from "firebase/storage"; import { Post } from "../interfaces/post.interface"; diff --git a/src/stores/posts.ts b/src/stores/posts.ts index 36a714d..14ec34f 100644 --- a/src/stores/posts.ts +++ b/src/stores/posts.ts @@ -1,4 +1,4 @@ -import { firestore } from "../shared/firebase/firebaseInit"; +import { firestore } from "../shared/firebase/firebase-firestore"; import { defineStore } from "pinia"; import { Ref, ref } from "vue"; import { diff --git a/src/stores/users.ts b/src/stores/users.ts index bb79a7f..ef798a7 100644 --- a/src/stores/users.ts +++ b/src/stores/users.ts @@ -1,7 +1,7 @@ import { doc, getDoc } from "firebase/firestore"; import { defineStore } from "pinia"; import { ref } from "vue"; -import { firestore } from "../shared/firebase/firebaseInit"; +import { firestore } from "../shared/firebase/firebase-firestore"; export const useUserStore = defineStore( "users", @@ -14,6 +14,8 @@ export const useUserStore = defineStore( const profileUsername = ref(""); const profileId = ref(""); const profileInitials = ref(""); + const isUserLogin = ref(false); + const isAdmin = ref(false); // actions async function getProfileInfo(userUid: string) { @@ -28,6 +30,7 @@ export const useUserStore = defineStore( setFirstName(document.data().firstName); setLastName(document.data().lastName); setUsername(document.data().username); + setUserLogin(true); } // mutations @@ -60,6 +63,14 @@ export const useUserStore = defineStore( profileUsername.value = payload; } + function setUserLogin(payload: boolean) { + isUserLogin.value = payload; + } + + function setIsAdmin(payload: boolean) { + isAdmin.value = payload; + } + return { user, profileEmail, @@ -68,12 +79,16 @@ export const useUserStore = defineStore( profileUsername, profileId, profileInitials, + isUserLogin, + isAdmin, getProfileInfo, setProfileInitials, setUser, setFirstName, setLastName, setUsername, + setUserLogin, + setIsAdmin, }; }, { diff --git a/src/views/blogs/blogs.vue b/src/views/blogs/blogs.vue index add9fb2..0621f57 100644 --- a/src/views/blogs/blogs.vue +++ b/src/views/blogs/blogs.vue @@ -1,4 +1,5 @@