Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updated client group and can launch but with errors #1

Merged
merged 1 commit into from
Apr 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 26 additions & 10 deletions client/src-sw.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
const { offlineFallback, warmStrategyCache } = require('workbox-recipes');
const { CacheFirst } = require('workbox-strategies');
const { registerRoute } = require('workbox-routing');
const { CacheableResponsePlugin } = require('workbox-cacheable-response');
const { ExpirationPlugin } = require('workbox-expiration');
const { precacheAndRoute } = require('workbox-precaching/precacheAndRoute');
const { offlineFallback, warmStrategyCache } = require("workbox-recipes");
const { CacheFirst } = require("workbox-strategies");
const { registerRoute } = require("workbox-routing");
const { CacheableResponsePlugin } = require("workbox-cacheable-response");
const { ExpirationPlugin } = require("workbox-expiration");
const { precacheAndRoute } = require("workbox-precaching/precacheAndRoute");

precacheAndRoute(self.__WB_MANIFEST);

const pageCache = new CacheFirst({
cacheName: 'page-cache',
cacheName: "page-cache",
plugins: [
new CacheableResponsePlugin({
statuses: [0, 200],
Expand All @@ -20,11 +20,27 @@ const pageCache = new CacheFirst({
});

warmStrategyCache({
urls: ['/index.html', '/'],
urls: ["/index.html", "/"],
strategy: pageCache,
});

registerRoute(({ request }) => request.mode === 'navigate', pageCache);
registerRoute(({ request }) => request.mode === "navigate", pageCache);

// TODO: Implement asset caching
registerRoute();
registerRoute(
({ request }) =>
request.destination === "style" ||
request.destination === "script" ||
request.destination === "font",
new CacheFirst({
cacheName: "asset-cache",
plugins: [
new CacheableResponsePlugin({
statuses: [0, 200],
}),
new ExpirationPlugin({
maxAgeSeconds: 30 * 24 * 60 * 60,
}),
],
})
);
29 changes: 21 additions & 8 deletions client/src/js/database.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,34 @@
import { openDB } from 'idb';
import { openDB } from "idb";

const initdb = async () =>
openDB('jate', 1, {
openDB("jate", 1, {
upgrade(db) {
if (db.objectStoreNames.contains('jate')) {
console.log('jate database already exists');
if (db.objectStoreNames.contains("jate")) {
console.log("jate database already exists");
return;
}
db.createObjectStore('jate', { keyPath: 'id', autoIncrement: true });
console.log('jate database created');
db.createObjectStore("jate", { keyPath: "id", autoIncrement: true });
console.log("jate database created");
},
});

// TODO: Add logic to a method that accepts some content and adds it to the database
export const putDb = async (content) => console.error('putDb not implemented');
export const putDb = async (content) => {
const db = await openDB("jate", 1);
const transaction = db.transaction("jate", "readwrite");
const store = transaction.objectStore("jate");
await store.add(content);
await transaction.done;
};

// TODO: Add logic for a method that gets all the content from the database
export const getDb = async () => console.error('getDb not implemented');
export const getDb = async () => {
const db = await openDB("jate", 1);
const transaction = db.transaction("jate", "readonly");
const store = transaction.objectStore("jate");
const content = await store.getAll();
await transaction.done;
return content;
};

initdb();
8 changes: 4 additions & 4 deletions client/src/js/install.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
const butInstall = document.getElementById('buttonInstall');
const butInstall = document.getElementById("buttonInstall");

// Logic for installing the PWA
// TODO: Add an event handler to the `beforeinstallprompt` event
window.addEventListener('beforeinstallprompt', (event) => {});
window.addEventListener("beforeinstallprompt", (event) => {});

// TODO: Implement a click event handler on the `butInstall` element
butInstall.addEventListener('click', async () => {});
butInstall.addEventListener("click", async () => {});

// TODO: Add an handler for the `appinstalled` event
window.addEventListener('appinstalled', (event) => {});
window.addEventListener("appinstalled", (event) => {});
69 changes: 58 additions & 11 deletions client/webpack.config.js
Original file line number Diff line number Diff line change
@@ -1,29 +1,76 @@
const HtmlWebpackPlugin = require('html-webpack-plugin');
const WebpackPwaManifest = require('webpack-pwa-manifest');
const path = require('path');
const { InjectManifest } = require('workbox-webpack-plugin');
const HtmlWebpackPlugin = require("html-webpack-plugin");
const WebpackPwaManifest = require("webpack-pwa-manifest");
const path = require("path");
const { InjectManifest } = require("workbox-webpack-plugin");

// TODO: Add and configure workbox plugins for a service worker and manifest file.
// TODO: Add CSS loaders and babel to webpack.

module.exports = () => {
return {
mode: 'development',
mode: "development",
entry: {
main: './src/js/index.js',
install: './src/js/install.js'
main: "./src/js/index.js",
install: "./src/js/install.js",
database: "./src/js/database.js",
editor: "./src/js/editor.js",
header: "./src/js/header.js",
},
output: {
filename: '[name].bundle.js',
path: path.resolve(__dirname, 'dist'),
filename: "[name].bundle.js",
path: path.resolve(__dirname, "dist"),
},
plugins: [

new HtmlWebpackPlugin({
template: "./index.html",
title: "Jate",
}),
// process.env.NODE_ENV === "production"
// ? [
// new InjectManifest({
// swSrc: "./src-sw.js",
// swDest: "src-sw.js",
// }),
// ]
// : [],
new InjectManifest({
swSrc: "./src-sw.js",
swDest: "src-sw.js",
}),
new WebpackPwaManifest({
name: "Just Another Text Editor",
inject: true,
fingerprints: false,
short_name: "JATE",
description: "Just Another Text Editor",
background_color: "#ffffff",
theme_color: "#000000",
icons: [
{
src: path.resolve("src/images/logo.png"),
sizes: [96, 128, 192, 256, 384, 512],
destination: path.join("assets", "icons"),
},
],
}),
],

module: {
rules: [

{
test: /\.css$/,
use: ["style-loader", "css-loader"],
},
{
test: /\.js$/,
exclude: /node_modules/,
use: {
loader: "babel-loader",
options: {
presets: ["@babel/preset-env"],
},
},
},
],
},
};
Expand Down
Loading