@upstash/react-redis-browser 0.1.2 → 0.1.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -2790,13 +2790,21 @@ var units = {
2790
2790
  second: 1e3
2791
2791
  };
2792
2792
  function formatTime(seconds) {
2793
+ let milliseconds = seconds * 1e3;
2794
+ const parts = [];
2793
2795
  for (const [unit, value] of Object.entries(units)) {
2794
- const interval = seconds * 1e3 / value;
2795
- if (interval >= 1) {
2796
- return `${Math.floor(interval)} ${unit}${interval > 1 && unit !== "min" ? "s" : ""}`;
2796
+ if (milliseconds >= value) {
2797
+ const amount = Math.floor(milliseconds / value);
2798
+ const plural = amount > 1 ? "s" : "";
2799
+ const label = unit === "month" ? ` month${plural}` : unit === "year" ? ` year${plural}` : unit[0];
2800
+ parts.push(`${amount}${label}`);
2801
+ milliseconds %= value;
2797
2802
  }
2798
2803
  }
2799
- return "just now";
2804
+ if (parts.length === 0) {
2805
+ parts.push("0s");
2806
+ }
2807
+ return parts.slice(0, 2).join(" ");
2800
2808
  }
2801
2809
 
2802
2810
  // src/components/ui/toast.tsx
@@ -3037,14 +3045,7 @@ var PaginationCache = (_class = class {
3037
3045
  var KeysContext = _react.createContext.call(void 0, void 0);
3038
3046
  var FETCH_KEYS_QUERY_KEY = "use-fetch-keys";
3039
3047
  var KeysProvider = ({ children }) => {
3040
- const { search: searchState } = useDatabrowserStore();
3041
- const search = _react.useMemo.call(void 0,
3042
- () => ({
3043
- key: searchState.key.includes("*") ? searchState.key : `*${searchState.key}*`,
3044
- type: searchState.type
3045
- }),
3046
- [searchState]
3047
- );
3048
+ const { search } = useDatabrowserStore();
3048
3049
  const { fetchKeys, resetCache } = useFetchKeys(search);
3049
3050
  const pageRef = _react.useRef.call(void 0, 0);
3050
3051
  const query = _reactquery.useInfiniteQuery.call(void 0, {
@@ -5432,16 +5433,29 @@ var KeyItem = ({ data, nextKey }) => {
5432
5433
  // src/components/databrowser/components/sidebar/search-input.tsx
5433
5434
 
5434
5435
 
5436
+
5435
5437
  var SearchInput = () => {
5436
5438
  const { setSearchKey, search } = useDatabrowserStore();
5439
+ const [state, setState] = _react.useState.call(void 0, search.key);
5440
+ const submit = (value) => {
5441
+ if (value.trim() !== "" && !value.includes("*")) value = `${value}*`;
5442
+ setSearchKey(value);
5443
+ setState(value);
5444
+ };
5437
5445
  return /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "div", { className: "relative grow", children: [
5438
5446
  /* @__PURE__ */ _jsxruntime.jsx.call(void 0,
5439
5447
  Input,
5440
5448
  {
5441
5449
  placeholder: "Search",
5442
5450
  className: "rounded-l-none border-zinc-300 font-normal",
5443
- onChange: (e) => setSearchKey(e.target.value),
5444
- value: search.key
5451
+ onKeyDown: (e) => {
5452
+ if (e.key === "Enter") submit(e.currentTarget.value);
5453
+ },
5454
+ onChange: (e) => {
5455
+ setState(e.currentTarget.value);
5456
+ if (e.currentTarget.value.trim() === "") submit("");
5457
+ },
5458
+ value: state
5445
5459
  }
5446
5460
  ),
5447
5461
  search.key && /* @__PURE__ */ _jsxruntime.jsxs.call(void 0,
@@ -5506,7 +5520,22 @@ function Sidebar() {
5506
5520
  /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "div", { className: "flex h-10 items-center justify-between pl-1", children: [
5507
5521
  /* @__PURE__ */ _jsxruntime.jsx.call(void 0, DisplayDbSize, {}),
5508
5522
  /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "div", { className: "flex gap-1", children: [
5509
- /* @__PURE__ */ _jsxruntime.jsx.call(void 0, Button, { className: "h-7 w-7 px-0", onClick: refetch, children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, Spinner, { isLoading: query.isFetching, children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _iconsreact.IconRefresh, { size: 16 }) }) }),
5523
+ /* @__PURE__ */ _jsxruntime.jsx.call(void 0,
5524
+ Button,
5525
+ {
5526
+ className: "h-7 w-7 px-0",
5527
+ onClick: () => {
5528
+ refetch();
5529
+ queryClient.invalidateQueries({
5530
+ queryKey: [FETCH_LIST_ITEMS_QUERY_KEY]
5531
+ });
5532
+ queryClient.invalidateQueries({
5533
+ queryKey: [FETCH_DB_SIZE_QUERY_KEY]
5534
+ });
5535
+ },
5536
+ children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, Spinner, { isLoading: query.isFetching, children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _iconsreact.IconRefresh, { size: 16 }) })
5537
+ }
5538
+ ),
5510
5539
  /* @__PURE__ */ _jsxruntime.jsx.call(void 0, AddKeyModal, {})
5511
5540
  ] })
5512
5541
  ] }),
package/dist/index.mjs CHANGED
@@ -2790,13 +2790,21 @@ var units = {
2790
2790
  second: 1e3
2791
2791
  };
2792
2792
  function formatTime(seconds) {
2793
+ let milliseconds = seconds * 1e3;
2794
+ const parts = [];
2793
2795
  for (const [unit, value] of Object.entries(units)) {
2794
- const interval = seconds * 1e3 / value;
2795
- if (interval >= 1) {
2796
- return `${Math.floor(interval)} ${unit}${interval > 1 && unit !== "min" ? "s" : ""}`;
2796
+ if (milliseconds >= value) {
2797
+ const amount = Math.floor(milliseconds / value);
2798
+ const plural = amount > 1 ? "s" : "";
2799
+ const label = unit === "month" ? ` month${plural}` : unit === "year" ? ` year${plural}` : unit[0];
2800
+ parts.push(`${amount}${label}`);
2801
+ milliseconds %= value;
2797
2802
  }
2798
2803
  }
2799
- return "just now";
2804
+ if (parts.length === 0) {
2805
+ parts.push("0s");
2806
+ }
2807
+ return parts.slice(0, 2).join(" ");
2800
2808
  }
2801
2809
 
2802
2810
  // src/components/ui/toast.tsx
@@ -3037,14 +3045,7 @@ import { jsx as jsx4 } from "react/jsx-runtime";
3037
3045
  var KeysContext = createContext2(void 0);
3038
3046
  var FETCH_KEYS_QUERY_KEY = "use-fetch-keys";
3039
3047
  var KeysProvider = ({ children }) => {
3040
- const { search: searchState } = useDatabrowserStore();
3041
- const search = useMemo2(
3042
- () => ({
3043
- key: searchState.key.includes("*") ? searchState.key : `*${searchState.key}*`,
3044
- type: searchState.type
3045
- }),
3046
- [searchState]
3047
- );
3048
+ const { search } = useDatabrowserStore();
3048
3049
  const { fetchKeys, resetCache } = useFetchKeys(search);
3049
3050
  const pageRef = useRef2(0);
3050
3051
  const query = useInfiniteQuery({
@@ -5430,18 +5431,31 @@ var KeyItem = ({ data, nextKey }) => {
5430
5431
  };
5431
5432
 
5432
5433
  // src/components/databrowser/components/sidebar/search-input.tsx
5434
+ import { useState as useState10 } from "react";
5433
5435
  import { IconX } from "@tabler/icons-react";
5434
5436
  import { jsx as jsx38, jsxs as jsxs27 } from "react/jsx-runtime";
5435
5437
  var SearchInput = () => {
5436
5438
  const { setSearchKey, search } = useDatabrowserStore();
5439
+ const [state, setState] = useState10(search.key);
5440
+ const submit = (value) => {
5441
+ if (value.trim() !== "" && !value.includes("*")) value = `${value}*`;
5442
+ setSearchKey(value);
5443
+ setState(value);
5444
+ };
5437
5445
  return /* @__PURE__ */ jsxs27("div", { className: "relative grow", children: [
5438
5446
  /* @__PURE__ */ jsx38(
5439
5447
  Input,
5440
5448
  {
5441
5449
  placeholder: "Search",
5442
5450
  className: "rounded-l-none border-zinc-300 font-normal",
5443
- onChange: (e) => setSearchKey(e.target.value),
5444
- value: search.key
5451
+ onKeyDown: (e) => {
5452
+ if (e.key === "Enter") submit(e.currentTarget.value);
5453
+ },
5454
+ onChange: (e) => {
5455
+ setState(e.currentTarget.value);
5456
+ if (e.currentTarget.value.trim() === "") submit("");
5457
+ },
5458
+ value: state
5445
5459
  }
5446
5460
  ),
5447
5461
  search.key && /* @__PURE__ */ jsxs27(
@@ -5506,7 +5520,22 @@ function Sidebar() {
5506
5520
  /* @__PURE__ */ jsxs30("div", { className: "flex h-10 items-center justify-between pl-1", children: [
5507
5521
  /* @__PURE__ */ jsx41(DisplayDbSize, {}),
5508
5522
  /* @__PURE__ */ jsxs30("div", { className: "flex gap-1", children: [
5509
- /* @__PURE__ */ jsx41(Button, { className: "h-7 w-7 px-0", onClick: refetch, children: /* @__PURE__ */ jsx41(Spinner, { isLoading: query.isFetching, children: /* @__PURE__ */ jsx41(IconRefresh, { size: 16 }) }) }),
5523
+ /* @__PURE__ */ jsx41(
5524
+ Button,
5525
+ {
5526
+ className: "h-7 w-7 px-0",
5527
+ onClick: () => {
5528
+ refetch();
5529
+ queryClient.invalidateQueries({
5530
+ queryKey: [FETCH_LIST_ITEMS_QUERY_KEY]
5531
+ });
5532
+ queryClient.invalidateQueries({
5533
+ queryKey: [FETCH_DB_SIZE_QUERY_KEY]
5534
+ });
5535
+ },
5536
+ children: /* @__PURE__ */ jsx41(Spinner, { isLoading: query.isFetching, children: /* @__PURE__ */ jsx41(IconRefresh, { size: 16 }) })
5537
+ }
5538
+ ),
5510
5539
  /* @__PURE__ */ jsx41(AddKeyModal, {})
5511
5540
  ] })
5512
5541
  ] }),
package/package.json CHANGED
@@ -1 +1 @@
1
- { "name": "@upstash/react-redis-browser", "version": "v0.1.2", "main": "./dist/index.js", "types": "./dist/index.d.ts", "license": "MIT", "private": false, "publishConfig": { "access": "public" }, "bugs": { "url": "https://github.com/upstash/react-redis-browser/issues" }, "homepage": "https://github.com/upstash/react-redis-browser", "files": [ "./dist/**" ], "scripts": { "build": "tsup", "dev": "vite", "lint": "tsc && eslint", "fmt": "prettier --write ./src" }, "lint-staged": { "**/*.{js,ts,tsx}": [ "prettier --write", "eslint --fix" ] }, "dependencies": { "@ianvs/prettier-plugin-sort-imports": "^4.4.0", "@monaco-editor/react": "^4.6.0", "@radix-ui/react-alert-dialog": "^1.0.5", "@radix-ui/react-context-menu": "^2.2.2", "@radix-ui/react-dialog": "^1.0.5", "@radix-ui/react-dropdown-menu": "^2.1.2", "@radix-ui/react-icons": "1.3.0", "@radix-ui/react-popover": "^1.0.7", "@radix-ui/react-portal": "^1.1.2", "@radix-ui/react-scroll-area": "^1.0.3", "@radix-ui/react-select": "^2.0.0", "@radix-ui/react-slot": "^1.0.2", "@radix-ui/react-toast": "^1.1.5", "@radix-ui/react-tooltip": "^1.0.7", "@tabler/icons-react": "^3.19.0", "@tanstack/react-query": "^5.32.0", "@types/bytes": "^3.1.4", "@upstash/redis": "^1.34.3", "bytes": "^3.1.2", "react-hook-form": "^7.53.0", "react-resizable-panels": "^2.1.4", "zustand": "5.0.0" }, "devDependencies": { "postcss-prefix-selector": "^2.1.0", "@types/node": "^22.8.4", "@types/react": "^18.3.12", "@types/react-dom": "^18.3.1", "@typescript-eslint/eslint-plugin": "8.4.0", "@typescript-eslint/parser": "8.4.0", "@vitejs/plugin-react": "^4.1.0", "autoprefixer": "^10.4.14", "class-variance-authority": "^0.7.0", "clsx": "^2.0.0", "eslint": "9.10.0", "eslint-plugin-unicorn": "55.0.0", "postcss": "^8.4.31", "prettier": "^3.0.3", "prettier-plugin-tailwindcss": "^0.5.5", "react": "^18.3.1", "react-dom": "^18.3.1", "tailwind-merge": "^2.5.4", "tailwindcss": "^3.4.14", "tailwindcss-animate": "^1.0.7", "tsup": "^8.3.5", "typescript": "^5.0.4", "vite": "^5.4.10", "vite-tsconfig-paths": "^5.0.1" }, "peerDependencies": { "react": "^18.2.0 || ^19", "react-dom": "^18.2.0 || ^19" } }
1
+ { "name": "@upstash/react-redis-browser", "version": "v0.1.4", "main": "./dist/index.js", "types": "./dist/index.d.ts", "license": "MIT", "private": false, "publishConfig": { "access": "public" }, "bugs": { "url": "https://github.com/upstash/react-redis-browser/issues" }, "homepage": "https://github.com/upstash/react-redis-browser", "files": [ "./dist/**" ], "scripts": { "build": "tsup", "dev": "vite", "lint": "tsc && eslint", "fmt": "prettier --write ./src" }, "lint-staged": { "**/*.{js,ts,tsx}": [ "prettier --write", "eslint --fix" ] }, "dependencies": { "@ianvs/prettier-plugin-sort-imports": "^4.4.0", "@monaco-editor/react": "^4.6.0", "@radix-ui/react-alert-dialog": "^1.0.5", "@radix-ui/react-context-menu": "^2.2.2", "@radix-ui/react-dialog": "^1.0.5", "@radix-ui/react-dropdown-menu": "^2.1.2", "@radix-ui/react-icons": "1.3.0", "@radix-ui/react-popover": "^1.0.7", "@radix-ui/react-portal": "^1.1.2", "@radix-ui/react-scroll-area": "^1.0.3", "@radix-ui/react-select": "^2.0.0", "@radix-ui/react-slot": "^1.0.2", "@radix-ui/react-toast": "^1.1.5", "@radix-ui/react-tooltip": "^1.0.7", "@tabler/icons-react": "^3.19.0", "@tanstack/react-query": "^5.32.0", "@types/bytes": "^3.1.4", "@upstash/redis": "^1.34.3", "bytes": "^3.1.2", "react-hook-form": "^7.53.0", "react-resizable-panels": "^2.1.4", "zustand": "5.0.0" }, "devDependencies": { "postcss-prefix-selector": "^2.1.0", "@types/node": "^22.8.4", "@types/react": "^18.3.12", "@types/react-dom": "^18.3.1", "@typescript-eslint/eslint-plugin": "8.4.0", "@typescript-eslint/parser": "8.4.0", "@vitejs/plugin-react": "^4.1.0", "autoprefixer": "^10.4.14", "class-variance-authority": "^0.7.0", "clsx": "^2.0.0", "eslint": "9.10.0", "eslint-plugin-unicorn": "55.0.0", "postcss": "^8.4.31", "prettier": "^3.0.3", "prettier-plugin-tailwindcss": "^0.5.5", "react": "^18.3.1", "react-dom": "^18.3.1", "tailwind-merge": "^2.5.4", "tailwindcss": "^3.4.14", "tailwindcss-animate": "^1.0.7", "tsup": "^8.3.5", "typescript": "^5.0.4", "vite": "^5.4.10", "vite-tsconfig-paths": "^5.0.1" }, "peerDependencies": { "react": "^18.2.0 || ^19", "react-dom": "^18.2.0 || ^19" } }