Skip to content

Commit 35a76c6

Browse files
Pollepsjoepio
authored andcommitted
#283 Refactor client and parser
1 parent 9e969bb commit 35a76c6

34 files changed

+1381
-537
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ publish
1212
test-results
1313
*/nohup.out
1414
*/yarn-error.log
15+
lib/coverage
16+
react/coverage
17+
data-browser/coverage
1518
.yarn/*
1619
!.yarn/cache
1720
!.yarn/patches

CHANGELOG.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,18 @@
22

33
This changelog covers all three packages, as they are (for now) updated as a whole
44

5+
## v0.35.0
6+
7+
### @tomic/lib
8+
9+
- Add the ability to change the `fetch` function used to fetch resources over http.
10+
- `store.addResource` is depricated in favor of `store.addResources`.
11+
12+
#### Breaking Changes:
13+
14+
- `tryValidURL` and `isValidURL` are now static methods on `Client`.
15+
- Rename `store.fetchResource` to `store.fetchResourceFromServer`.
16+
517
## v0.34.10
618

719
- Don't use WebSocket in Node context #280

data-browser/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@
4141
"gh-pages": "^3.1.0",
4242
"lint-staged": "^10.5.4",
4343
"types-wm": "^1.1.0",
44-
"vite": "^3.0.5",
45-
"vite-plugin-pwa": "^0.13.1",
44+
"vite": "^4.0.4",
45+
"vite-plugin-pwa": "^0.14.1",
4646
"workbox-cli": "^6.4.1"
4747
},
4848
"homepage": "https://atomicdata.dev/",

data-browser/src/App.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,8 @@ if (agent) {
7171
}
7272

7373
/** Fetch all the Properties and Classes - this helps speed up the app. */
74-
store.fetchResource(urls.properties.getAll);
75-
store.fetchResource(urls.classes.getAll);
74+
store.fetchResourceFromServer(urls.properties.getAll);
75+
store.fetchResourceFromServer(urls.classes.getAll);
7676

7777
// Register global event handlers.
7878
registerHandlers(store);

data-browser/src/components/HotKeyWrapper.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { dataURL, editURL } from '../helpers/navigation';
33
import { useHotkeys } from 'react-hotkeys-hook';
44
import { useNavigate } from 'react-router-dom';
55
import { useCurrentSubject } from '../helpers/useCurrentSubject';
6-
import { isValidURL } from '@tomic/react';
6+
import { Client } from '@tomic/react';
77
import { useSettings } from '../helpers/AppSettings';
88
import { paths } from '../routes/paths';
99

@@ -71,7 +71,7 @@ function HotKeysWrapper({ children }: Props): JSX.Element {
7171
shortcuts.edit,
7272
e => {
7373
e.preventDefault();
74-
isValidURL(subject) && navigate(editURL(subject!));
74+
Client.isValidURL(subject) && navigate(editURL(subject!));
7575
},
7676
{},
7777
[subject],
@@ -80,7 +80,7 @@ function HotKeysWrapper({ children }: Props): JSX.Element {
8080
shortcuts.data,
8181
e => {
8282
e.preventDefault();
83-
isValidURL(subject) && navigate(dataURL(subject!));
83+
Client.isValidURL(subject) && navigate(dataURL(subject!));
8484
},
8585
{},
8686
[subject],

data-browser/src/components/ResourceContextMenu/index.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import React from 'react';
22
import { useLocation, useNavigate } from 'react-router-dom';
3-
import { isValidURL, useStore } from '@tomic/react';
3+
import { Client, useStore } from '@tomic/react';
44
import {
55
editURL,
66
dataURL,
@@ -50,7 +50,7 @@ function ResourceContextMenu({
5050
return null;
5151
}
5252

53-
if (!isValidURL(subject)) {
53+
if (!Client.isValidURL(subject)) {
5454
return null;
5555
}
5656

@@ -98,7 +98,7 @@ function ResourceContextMenu({
9898
label: 'refresh',
9999
helper:
100100
'Fetch the resouce again from the server, possibly see new changes.',
101-
onClick: () => store.fetchResource(subject),
101+
onClick: () => store.fetchResourceFromServer(subject),
102102
},
103103
]),
104104
{

data-browser/src/components/Searchbar.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { tryValidURL, useResource, useTitle } from '@tomic/react';
1+
import { Client, useResource, useTitle } from '@tomic/react';
22
import { transparentize } from 'polished';
33
import React, { useEffect, useState } from 'react';
44
import { useHotkeys } from 'react-hotkeys-hook';
@@ -41,7 +41,7 @@ export function Searchbar({
4141
setInput(e.target.value);
4242

4343
try {
44-
tryValidURL(e.target.value);
44+
Client.tryValidURL(e.target.value);
4545
// Replace instead of push to make the back-button behavior better.
4646
navigate(constructOpenURL(e.target.value), { replace: true });
4747
} catch (_err) {

data-browser/src/components/forms/FileDropzone/FileDropzone.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { useDropzone } from 'react-dropzone';
44
import { FaUpload } from 'react-icons/fa';
55
import styled, { keyframes } from 'styled-components';
66
import { ErrMessage } from '../InputStyles';
7-
import { useUpload } from './useUpload';
7+
import { useUpload } from '../../../hooks/useUpload';
88

99
export interface FileDropZoneProps {
1010
parentResource: Resource;

data-browser/src/components/forms/FileDropzone/FileDropzoneInput.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { useDropzone } from 'react-dropzone';
44
import { FaUpload } from 'react-icons/fa';
55
import styled from 'styled-components';
66
import { ErrMessage } from '../InputStyles';
7-
import { useUpload } from './useUpload';
7+
import { useUpload } from '../../../hooks/useUpload';
88

99
export interface FileDropzoneInputProps {
1010
parentResource: Resource;

data-browser/src/components/forms/ResourceForm.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import {
1010
urls,
1111
useDebounce,
1212
useCanWrite,
13-
isValidURL,
13+
Client,
1414
useStore,
1515
} from '@tomic/react';
1616
import styled from 'styled-components';
@@ -137,7 +137,7 @@ export function ResourceForm({
137137
function handleAddProp() {
138138
setNewPropErr(undefined);
139139

140-
if (!isValidURL(newProperty)) {
140+
if (!Client.isValidURL(newProperty)) {
141141
setNewPropErr(new Error('Invalid URL'));
142142

143143
return;

0 commit comments

Comments
 (0)