fork(1) download
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  6. <title>Multi-Functional App</title>
  7. <script src="https://c...content-available-to-author-only...s.com"></script>
  8. <link href="https://c...content-available-to-author-only...r.net/npm/daisyui@2.51.6/dist/full.css" rel="stylesheet" type="text/css" />
  9. <script src="https://c...content-available-to-author-only...r.net/npm/vue@2.6.14/dist/vue.js"></script>
  10. <script src="https://w...content-available-to-author-only...c.com/firebasejs/8.6.8/firebase-app.js"></script>
  11. <script src="https://w...content-available-to-author-only...c.com/firebasejs/8.6.8/firebase-auth.js"></script>
  12. <script src="https://w...content-available-to-author-only...c.com/firebasejs/8.6.8/firebase-storage.js"></script>
  13. <link href="https://f...content-available-to-author-only...s.com/icon?family=Material+Icons" rel="stylesheet">
  14. </head>
  15. <body class="bg-base-200">
  16. <div id="app" class="container mx-auto my-8">
  17. <div v-show="!user" class="flex justify-center">
  18. <div class="card bg-base-100 shadow-xl w-full max-w-md">
  19. <div class="card-body">
  20. <h2 class="card-title text-2xl font-bold mb-4 text-center">Multi-Functional App</h2>
  21. <div v-show="showLoginForm">
  22. <div class="form-control mb-4">
  23. <label for="loginEmail" class="label">Email</label>
  24. <input type="email" id="loginEmail" v-model="loginEmail" class="input input-bordered">
  25. </div>
  26. <div class="form-control mb-6">
  27. <label for="loginPassword" class="label">Password</label>
  28. <input type="password" id="loginPassword" v-model="loginPassword" class="input input-bordered">
  29. </div>
  30. <button @click="login" class="btn btn-primary btn-block">
  31. <span class="material-icons">login</span> Login
  32. </button>
  33. <button @click="loginAnonymously" class="btn btn-ghost btn-block mt-2">
  34. <span class="material-icons">person_outline</span> Login as Guest
  35. </button>
  36. </div>
  37. <div v-show="!showLoginForm">
  38. <div class="form-control mb-4">
  39. <label for="signupEmail" class="label">Email</label>
  40. <input type="email" id="signupEmail" v-model="signupEmail" class="input input-bordered">
  41. </div>
  42. <div class="form-control mb-6">
  43. <label for="signupPassword" class="label">Password</label>
  44. <input type="password" id="signupPassword" v-model="signupPassword" class="input input-bordered">
  45. </div>
  46. <button @click="signup" class="btn btn-success btn-block">
  47. <span class="material-icons">person_add</span> Signup
  48. </button>
  49. </div>
  50. <div class="text-center mt-6">
  51. <button @click="toggleForm" class="link link-primary">
  52. <span class="material-icons">{{ showLoginForm ? 'person_add' : 'login' }}</span> {{ showLoginForm ? 'Switch to Signup' : 'Switch to Login' }}
  53. </button>
  54. </div>
  55. </div>
  56. </div>
  57. </div>
  58. <div v-show="user">
  59. <div class="navbar bg-base-100 shadow-lg mb-6">
  60. <div class="flex-1">
  61. <h1 class="text-2xl font-bold">Multi-Functional App</h1>
  62. </div>
  63. <div class="flex-none">
  64. <button @click="logout" class="btn btn-primary">
  65. <span class="material-icons">logout</span> Logout
  66. </button>
  67. </div>
  68. </div>
  69. <div class="card bg-base-100 shadow-xl mb-6">
  70. <div class="card-body">
  71. <div class="form-control mb-4">
  72. <label for="imageInput" class="label">Upload Image</label>
  73. <input type="file" id="imageInput" @change="handleImageUpload" class="file-input file-input-bordered w-full">
  74. </div>
  75. <button @click="uploadImage" class="btn btn-primary">
  76. <span class="material-icons">cloud_upload</span> Upload
  77. </button>
  78. </div>
  79. </div>
  80. <div class="grid grid-cols-3 gap-4">
  81. <div v-for="image in images" :key="image.id" class="relative">
  82. <img :src="image.url" class="w-full h-64 object-cover rounded-lg">
  83. <div class="absolute top-2 right-2">
  84. <button @click="deleteImage(image.id)" class="btn btn-error btn-sm btn-circle">
  85. <span class="material-icons">delete</span>
  86. </button>
  87. </div>
  88. <div>
  89. <textarea class="textarea textarea-bordered w-full mt-2" v-model="commentText" placeholder="Add a comment"></textarea>
  90. <button @click="addComment(image.id)" class="btn btn-primary btn-sm mt-2">
  91. <span class="material-icons">send</span> Submit
  92. </button>
  93. <div v-for="comment in image.comments" :key="comment.id" class="mt-2">
  94. <p class="font-semibold">{{ comment.name }}</p>
  95. <p>{{ comment.text }}</p>
  96. </div>
  97. </div>
  98. </div>
  99. </div>
  100. </div>
  101. </div>
  102. <script>
  103. var firebaseConfig = {
  104. apiKey: "AIzaSyXXXXXX",
  105. authDomain: "your-project.firebaseapp.com",
  106. projectId: "your-project-id",
  107. storageBucket: "your-project.appspot.com",
  108. messagingSenderId: "your-sender-id",
  109. appId: "your-app-id"
  110. };
  111. firebase.initializeApp(firebaseConfig);
  112. const auth = firebase.auth();
  113. const storage = firebase.storage();
  114. new Vue({
  115. el: '#app',
  116. data: {
  117. user: null,
  118. showLoginForm: true,
  119. loginEmail: '',
  120. loginPassword: '',
  121. signupEmail: '',
  122. signupPassword: '',
  123. currentImage: null,
  124. images: [],
  125. commentText: ''
  126. },
  127. methods: {
  128. login() {
  129. auth.signInWithEmailAndPassword(this.loginEmail, this.loginPassword)
  130. .then((userCredential) => {
  131. this.user = userCredential.user;
  132. console.log('User logged in:', this.user);
  133. this.fetchImages();
  134. });
  135. },
  136. loginAnonymously() {
  137. auth.signInAnonymously()
  138. .then(() => {
  139. this.user = auth.currentUser;
  140. console.log('Anonymous user logged in');
  141. this.fetchImages();
  142. });
  143. },
  144. signup() {
  145. auth.createUserWithEmailAndPassword(this.signupEmail, this.signupPassword)
  146. .then((userCredential) => {
  147. this.user = userCredential.user;
  148. console.log('User signed up:', this.user);
  149. this.fetchImages();
  150. });
  151. },
  152. toggleForm() {
  153. this.showLoginForm = !this.showLoginForm;
  154. },
  155. logout() {
  156. auth.signOut()
  157. .then(() => {
  158. console.log('User logged out');
  159. this.user = null;
  160. this.images = [];
  161. });
  162. },
  163. handleImageUpload(event) {
  164. this.currentImage = event.target.files[0];
  165. },
  166. uploadImage() {
  167. if (this.currentImage) {
  168. const storageRef = storage.ref(`images/${this.user.uid}/${this.currentImage.name}`);
  169. storageRef.put(this.currentImage)
  170. .then(() => {
  171. storageRef.getDownloadURL()
  172. .then((url) => {
  173. this.images.push({ url: url, comments: [] });
  174. console.log('Image uploaded successfully');
  175. this.currentImage = null;
  176. });
  177. });
  178. }
  179. },
  180. fetchImages() {
  181. // Normally fetch images from storage here
  182. },
  183. deleteImage(id) {
  184. // Handle deletion logic
  185. },
  186. addComment(imageId) {
  187. // Handle add comment logic
  188. }
  189. },
  190. created() {
  191. auth.onAuthStateChanged((user) => {
  192. this.user = user;
  193. if (user) {
  194. this.fetchImages();
  195. }
  196. });
  197. }
  198. });
  199. </script>
  200. </body>
  201. </html>
Success #stdin #stdout 0.02s 25528KB
stdin
H
stdout
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Multi-Functional App</title>
    <script src="https://c...content-available-to-author-only...s.com"></script>
    <link href="https://c...content-available-to-author-only...r.net/npm/daisyui@2.51.6/dist/full.css" rel="stylesheet" type="text/css" />
    <script src="https://c...content-available-to-author-only...r.net/npm/vue@2.6.14/dist/vue.js"></script>
    <script src="https://w...content-available-to-author-only...c.com/firebasejs/8.6.8/firebase-app.js"></script>
    <script src="https://w...content-available-to-author-only...c.com/firebasejs/8.6.8/firebase-auth.js"></script>
    <script src="https://w...content-available-to-author-only...c.com/firebasejs/8.6.8/firebase-storage.js"></script>
    <link href="https://f...content-available-to-author-only...s.com/icon?family=Material+Icons" rel="stylesheet">
</head>
<body class="bg-base-200">
    <div id="app" class="container mx-auto my-8">
        <div v-show="!user" class="flex justify-center">
            <div class="card bg-base-100 shadow-xl w-full max-w-md">
                <div class="card-body">
                    <h2 class="card-title text-2xl font-bold mb-4 text-center">Multi-Functional App</h2>
                    <div v-show="showLoginForm">
                        <div class="form-control mb-4">
                            <label for="loginEmail" class="label">Email</label>
                            <input type="email" id="loginEmail" v-model="loginEmail" class="input input-bordered">
                        </div>
                        <div class="form-control mb-6">
                            <label for="loginPassword" class="label">Password</label>
                            <input type="password" id="loginPassword" v-model="loginPassword" class="input input-bordered">
                        </div>
                        <button @click="login" class="btn btn-primary btn-block">
                            <span class="material-icons">login</span> Login
                        </button>
                        <button @click="loginAnonymously" class="btn btn-ghost btn-block mt-2">
                            <span class="material-icons">person_outline</span> Login as Guest
                        </button>
                    </div>
                    <div v-show="!showLoginForm">
                        <div class="form-control mb-4">
                            <label for="signupEmail" class="label">Email</label>
                            <input type="email" id="signupEmail" v-model="signupEmail" class="input input-bordered">
                        </div>
                        <div class="form-control mb-6">
                            <label for="signupPassword" class="label">Password</label>
                            <input type="password" id="signupPassword" v-model="signupPassword" class="input input-bordered">
                        </div>
                        <button @click="signup" class="btn btn-success btn-block">
                            <span class="material-icons">person_add</span> Signup
                        </button>
                    </div>
                    <div class="text-center mt-6">
                        <button @click="toggleForm" class="link link-primary">
                            <span class="material-icons">{{ showLoginForm ? 'person_add' : 'login' }}</span> {{ showLoginForm ? 'Switch to Signup' : 'Switch to Login' }}
                        </button>
                    </div>
                </div>
            </div>
        </div>
        <div v-show="user">
            <div class="navbar bg-base-100 shadow-lg mb-6">
                <div class="flex-1">
                    <h1 class="text-2xl font-bold">Multi-Functional App</h1>
                </div>
                <div class="flex-none">
                    <button @click="logout" class="btn btn-primary">
                        <span class="material-icons">logout</span> Logout
                    </button>
                </div>
            </div>
            <div class="card bg-base-100 shadow-xl mb-6">
                <div class="card-body">
                    <div class="form-control mb-4">
                        <label for="imageInput" class="label">Upload Image</label>
                        <input type="file" id="imageInput" @change="handleImageUpload" class="file-input file-input-bordered w-full">
                    </div>
                    <button @click="uploadImage" class="btn btn-primary">
                        <span class="material-icons">cloud_upload</span> Upload
                    </button>
                </div>
            </div>
            <div class="grid grid-cols-3 gap-4">
                <div v-for="image in images" :key="image.id" class="relative">
                    <img :src="image.url" class="w-full h-64 object-cover rounded-lg">
                    <div class="absolute top-2 right-2">
                        <button @click="deleteImage(image.id)" class="btn btn-error btn-sm btn-circle">
                            <span class="material-icons">delete</span>
                        </button>
                    </div>
                    <div>
                        <textarea class="textarea textarea-bordered w-full mt-2" v-model="commentText" placeholder="Add a comment"></textarea>
                        <button @click="addComment(image.id)" class="btn btn-primary btn-sm mt-2">
                            <span class="material-icons">send</span> Submit
                        </button>
                        <div v-for="comment in image.comments" :key="comment.id" class="mt-2">
                            <p class="font-semibold">{{ comment.name }}</p>
                            <p>{{ comment.text }}</p>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <script>
        var firebaseConfig = {
            apiKey: "AIzaSyXXXXXX", 
            authDomain: "your-project.firebaseapp.com",
            projectId: "your-project-id",
            storageBucket: "your-project.appspot.com",
            messagingSenderId: "your-sender-id",
            appId: "your-app-id"
        };
        firebase.initializeApp(firebaseConfig);
        const auth = firebase.auth();
        const storage = firebase.storage();
        new Vue({
            el: '#app',
            data: {
                user: null,
                showLoginForm: true,
                loginEmail: '',
                loginPassword: '',
                signupEmail: '',
                signupPassword: '',
                currentImage: null,
                images: [],
                commentText: ''
            },
            methods: {
                login() {
                    auth.signInWithEmailAndPassword(this.loginEmail, this.loginPassword)
                        .then((userCredential) => {
                            this.user = userCredential.user;
                            console.log('User logged in:', this.user);
                            this.fetchImages();
                        });
                },
                loginAnonymously() {
                    auth.signInAnonymously()
                        .then(() => {
                            this.user = auth.currentUser;
                            console.log('Anonymous user logged in');
                            this.fetchImages();
                        });
                },
                signup() {
                    auth.createUserWithEmailAndPassword(this.signupEmail, this.signupPassword)
                        .then((userCredential) => {
                            this.user = userCredential.user;
                            console.log('User signed up:', this.user);
                            this.fetchImages();
                        });
                },
                toggleForm() {
                    this.showLoginForm = !this.showLoginForm;
                },
                logout() {
                    auth.signOut()
                        .then(() => {
                            console.log('User logged out');
                            this.user = null;
                            this.images = [];
                        });
                },
                handleImageUpload(event) {
                    this.currentImage = event.target.files[0];
                },
                uploadImage() {
                    if (this.currentImage) {
                        const storageRef = storage.ref(`images/${this.user.uid}/${this.currentImage.name}`);
                        storageRef.put(this.currentImage)
                            .then(() => {
                                storageRef.getDownloadURL()
                                    .then((url) => {
                                        this.images.push({ url: url, comments: [] });
                                        console.log('Image uploaded successfully');
                                        this.currentImage = null;
                                    });
                            });
                    }
                },
                fetchImages() {
                    // Normally fetch images from storage here
                },
                deleteImage(id) {
                    // Handle deletion logic
                },
                addComment(imageId) {
                    // Handle add comment logic
                }
            },
            created() {
                auth.onAuthStateChanged((user) => {
                    this.user = user;
                    if (user) {
                        this.fetchImages();
                    }
                });
            }
        });
    </script>
</body>
</html>