Skip to content

Commit

Permalink
Upgrade wouter & date-fns
Browse files Browse the repository at this point in the history
  • Loading branch information
stanlemon committed Feb 18, 2024
1 parent 4b3efe7 commit 20b5c9b
Show file tree
Hide file tree
Showing 18 changed files with 96 additions and 62 deletions.
90 changes: 65 additions & 25 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 5 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,12 @@
"@fortawesome/react-fontawesome": "^0.2.0",
"@reduxjs/toolkit": "^2.2.1",
"@sendgrid/mail": "^8.1.1",
"@stanlemon/webdev": "^0.1.165",
"@stanlemon/webdev": "^0.1.166",
"bcryptjs": "^2.4.3",
"client-sessions": "^0.8.0",
"compression": "^1.7.4",
"cookie-parser": "^1.4.6",
"date-fns": "^2.30.0",
"date-fns": "^3.3.1",
"express": "^4.18.2",
"express-rate-limit": "^7.1.5",
"express-session": "^1.18.0",
Expand All @@ -58,6 +58,7 @@
"passport": "~0.6.0",
"passport-jwt": "^4.0.1",
"passport-local": "^1.0.0",
"path-to-regexp": "^6.2.1",
"pg": "^8.11.3",
"prop-types": "^15.8.1",
"react": "^18.2.0",
Expand All @@ -69,7 +70,7 @@
"shortid": "^2.2.16",
"uuid": "^9.0.1",
"validator": "^13.11.0",
"wouter": "^2.12.1"
"wouter": "^3.0.0"
},
"devDependencies": {
"@testing-library/react": "^14.2.1",
Expand All @@ -82,4 +83,4 @@
"supertest": "^6.3.4",
"wait-for-expect": "^3.0.2"
}
}
}
2 changes: 1 addition & 1 deletion src/db/tags.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const format = require("date-fns/format");
const { format } = require("date-fns");
const knex = require("../connection");
const isEmpty = require("lodash/isEmpty");
const mapKeys = require("lodash/mapKeys");
Expand Down
3 changes: 1 addition & 2 deletions src/db/tasks.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ const omit = require("lodash/omit");
const includes = require("lodash/includes");
const isObject = require("lodash/isObject");
const isEmpty = require("lodash/isEmpty");
const format = require("date-fns/format");
const isDate = require("date-fns/isDate");
const { format, isDate } = require("date-fns");
const { upsertTags, getTagsByTaskId, getTagsForTaskIds } = require("./tags");

const columns = [
Expand Down
2 changes: 1 addition & 1 deletion src/db/users.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const bcrypt = require("bcryptjs");
const shortid = require("shortid");
const format = require("date-fns/format");
const { format } = require("date-fns");
const omit = require("lodash/omit");
const isEmpty = require("lodash/isEmpty");
const isObject = require("lodash/isObject");
Expand Down
2 changes: 1 addition & 1 deletion src/routes/auth/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ const express = require("express");
const router = express.Router();
const jwt = require("jsonwebtoken");
const isEmpty = require("lodash/isEmpty");
const addMinutes = require("date-fns/addMinutes");
const { addMinutes } = require("date-fns");
const passport = require("passport");
const { Strategy: LocalStrategy } = require("passport-local");
const { Strategy: JwtStrategy } = require("passport-jwt");
Expand Down
2 changes: 1 addition & 1 deletion src/utils.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const format = require("date-fns/format");
const { format } = require("date-fns");

const SQL_DATE_FORMAT = "yyyy-MM-dd'T'HH:mm:ss.SSSxxx";

Expand Down
2 changes: 1 addition & 1 deletion web/js/components/TaskForm.jsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import isBoolean from "lodash/isBoolean";
import format from "date-fns/format";
import { format } from "date-fns";
import React from "react";
import PropTypes from "prop-types";
import isEmpty from "lodash/isEmpty";
Expand Down
4 changes: 1 addition & 3 deletions web/js/components/TaskForm.test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import React from "react";
import parse from "date-fns/parse";
import parseISO from "date-fns/parseISO";
import isSameDay from "date-fns/isSameDay";
import { parse, parseISO, isSameDay } from "date-fns";
import { fireEvent, render, screen } from "@testing-library/react";
import TaskForm from "./TaskForm";

Expand Down
7 changes: 2 additions & 5 deletions web/js/components/TaskItem.jsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
import React from "react";
import PropTypes from "prop-types";
import isAfter from "date-fns/isAfter";
import isBefore from "date-fns/isBefore";
import addDays from "date-fns/addDays";
import format from "date-fns/format";
import { isAfter, isBefore, addDays, format } from "date-fns";
import { connect } from "react-redux";
import { FontAwesomeIcon as Icon } from "@fortawesome/react-fontawesome";
import { faTrash } from "@fortawesome/free-solid-svg-icons/faTrash";
Expand Down Expand Up @@ -51,7 +48,7 @@ export class TaskItem extends React.Component {
const styles = {
cursor: "pointer",
padding: 10,
textDecoration: !!task.completed ? "line-through" : "none",
textDecoration: task.completed ? "line-through" : "none",
color: getTaskTextColor(task),
};

Expand Down
5 changes: 1 addition & 4 deletions web/js/components/TaskItem.test.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
import React from "react";
import { fireEvent, render, screen } from "@testing-library/react";
import subDays from "date-fns/subDays";
import addDays from "date-fns/addDays";
import isSameDay from "date-fns/isSameDay";
import parseISO from "date-fns/parseISO";
import { subDays, addDays, isSameDay, parseISO } from "date-fns";
import { makeDateTime } from "../lib/Utils";
import { getCurrentPathname } from "../lib/Navigation";
import { TaskItem } from "./TaskItem";
Expand Down
2 changes: 1 addition & 1 deletion web/js/components/TaskView.jsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import includes from "lodash/includes";
import isEmpty from "lodash/isEmpty";
import format from "date-fns/format";
import { format } from "date-fns";
import React from "react";
import PropTypes from "prop-types";
import Error from "./Error";
Expand Down
2 changes: 1 addition & 1 deletion web/js/components/UpdateTaskForm.test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React from "react";
import { fireEvent, render, screen } from "@testing-library/react";
import { UpdateTaskForm } from "./UpdateTaskForm";
import parseISO from "date-fns/parseISO";
import { parseISO } from "date-fns";

describe("<UpdateTaskForm />", () => {
it("should render a form with an existing task and update it", () => {
Expand Down
1 change: 0 additions & 1 deletion web/js/components/VerifyEmailView.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ export class VerifyEmailViewContainer extends React.Component {

async componentDidMount() {
const token = getRouteParam(ROUTE_VERIFY, "token");

const response = await this.props.verify(token);

this.setState({ loaded: true, ...response });
Expand Down
15 changes: 11 additions & 4 deletions web/js/lib/Navigation.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const makeMatcher = require("wouter/matcher").default;
const { makeMatcher } = require("wouter");
const { pathToRegexp, match } = require("path-to-regexp");

// This file contains function that obscure route navigation during
// development so that there are no hard dependencies outside of this file
Expand All @@ -12,9 +13,15 @@ export function getCurrentPathname() {
}

export function getRouteParam(route, param) {
const matcher = makeMatcher();
const [, params] = matcher(route, window.location.pathname);
return params?.[param];
console.log(route, window.location.pathname);
const urlMatch = match(route, {
decode: decodeURIComponent,
});

console.log(urlMatch(window.location.pathname));
//=> { path: '/users/1234/photos', index: 0, params: { id: '1234', tab: 'photos' } }

return "";
}

export const history = window.history;
3 changes: 1 addition & 2 deletions web/js/lib/TaskService.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import mapValues from "lodash/mapValues";
import isDate from "date-fns/isDate";
import format from "date-fns/format";
import { isDate, format } from "date-fns";
import RestService from "./RestService";

export default class TaskService extends RestService {
Expand Down
4 changes: 1 addition & 3 deletions web/js/lib/Utils.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import formatISO from "date-fns/formatISO";
import isAfter from "date-fns/isAfter";
import isSameMinute from "date-fns/isSameMinute";
import { formatISO, isAfter, isSameMinute } from "date-fns";

export const DATE_FORMAT_LONG = "MMMM do yyyy, h:mma";

Expand Down
3 changes: 1 addition & 2 deletions web/js/lib/Utils.test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import addDays from "date-fns/addDays";
import subDays from "date-fns/subDays";
import { addDays, subDays } from "date-fns";
import shuffle from "lodash/shuffle";
import { makeDateTime, sortTasks } from "./Utils";

Expand Down

0 comments on commit 20b5c9b

Please sign in to comment.