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

Typescript #92

Merged
merged 11 commits into from
Apr 24, 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
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,6 @@

# Dependency directories (remove the comment below to include it)
# vendor/
node_modules
.DS_Store
dist
6 changes: 0 additions & 6 deletions net/web/babel.config.js

This file was deleted.

21 changes: 21 additions & 0 deletions net/web/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<link rel="icon" href="/favicon.ico" />
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
<meta name="theme-color" content="#000000" />
<meta
name="Databag"
content="Communication for the Decentralized Web"
/>
<link rel="apple-touch-icon" href="/logo192.png" />
<link rel="manifest" href="/manifest.json" />
<title>Databag</title>
</head>
<body>
<noscript>You need to enable JavaScript to run this app.</noscript>
<div id="root"></div>
<script type="module" src="/src/index.tsx"></script>
</body>
</html>
12 changes: 12 additions & 0 deletions net/web/jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/** @type {import('ts-jest').JestConfigWithTsJest} */
export default {
preset: 'ts-jest',
testEnvironment: 'jsdom',
modulePaths: ['<rootDir>/src/'],
testMatch: ['**/test/**'],
moduleNameMapper: {
'\\.(jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$': '<rootDir>/mock/fileMock.js',
'\\.(css|less|scss|sass)$': 'identity-obj-proxy',
// "(.*)": "<rootDir>/src/$1",
},
};
6 changes: 0 additions & 6 deletions net/web/jsconfig.json

This file was deleted.

41 changes: 19 additions & 22 deletions net/web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,7 @@
"name": "databag",
"version": "0.1.0",
"private": true,
"jest": {
"testEnvironment": "jsdom",
"modulePaths": [
"<rootDir>/src/"
],
"testMatch": [
"**/test/**"
],
"moduleNameMapper": {
"\\.(jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$": "<rootDir>/mock/fileMock.js",
"\\.(css|less|scss|sass)$": "identity-obj-proxy"
}
},
"type": "module",
"dependencies": {
"@charliewilco/gluejar": "^1.0.0",
"@testing-library/jest-dom": "^5.14.1",
Expand All @@ -33,15 +21,13 @@
"react-image-file-resizer": "^0.4.8",
"react-resize-detector": "^7.0.0",
"react-router-dom": "^6.2.2",
"react-scripts": "5.0.0",
"styled-components": "^5.3.3",
"web-vitals": "^2.1.0"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject"
"start": "vite",
"build": "vite build",
"test": "jest"
},
"eslintConfig": {
"extends": [
Expand All @@ -62,14 +48,25 @@
]
},
"devDependencies": {
"@babel/preset-env": "^7.20.2",
"@babel/preset-react": "^7.18.6",
"@testing-library/dom": "^8.19.1",
"@testing-library/react": "^13.4.0",
"@types/jest": "^29.5.12",
"@types/react": "^18.2.66",
"@types/react-dom": "^18.2.22",
"@typescript-eslint/eslint-plugin": "^7.2.0",
"@typescript-eslint/parser": "^7.2.0",
"@vitejs/plugin-react-swc": "^3.5.0",
"babel-jest": "^29.3.1",
"eslint": "^8.57.0",
"eslint-plugin-react-hooks": "^4.6.0",
"eslint-plugin-react-refresh": "^0.4.6",
"identity-obj-proxy": "^3.0.0",
"jest": "^29.3.1",
"jest": "^29.7.0",
"jest-environment-jsdom": "^29.3.1",
"react-test-renderer": "^18.2.0"
"react-test-renderer": "^18.2.0",
"ts-jest": "^29.1.2",
"typescript": "^5.4.5",
"vite": "^5.2.0",
"vite-tsconfig-paths": "^4.3.2"
}
}
43 changes: 0 additions & 43 deletions net/web/public/index.html

This file was deleted.

File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export function useAdmin() {
placeholder: '',
unclaimed: null,
busy: false,
strings: {},
strings: {} as Record<string, string>,
menuStyle: {},
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export function useCreateAccount() {
busy: false,
validatetatus: 'success',
help: '',
strings: {},
strings: {} as Record<string,string>,
menuStyle: {},
});

Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export function useLogin() {
availableSet: false,
disabled: true,
busy: false,
strings: {},
strings: {} as Record<string,string>,
menuStyle: {},
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export function useAccess() {
themes: [],
language: null,
languages: [],
strings: {},
strings: {} as Record<string,string>,
});

const navigate = useNavigate();
Expand All @@ -32,7 +32,7 @@ export function useAccess() {
}, [app.state, navigate]);

useEffect(() => {
let params = new URLSearchParams(location);
let params = new URLSearchParams(location+"");
let token = params.get("access");
if (token) {
const access = async () => {
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
8 changes: 4 additions & 4 deletions net/web/src/api/fetchUtil.js → net/web/src/api/fetchUtil.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,17 @@ export function checkResponse(response) {
}
}

export async function fetchWithTimeout(url, options) {
export async function fetchWithTimeout(url, options):Promise<Response> {
return Promise.race([
fetch(url, options).catch(err => { throw new Error(url + ' failed'); }),
new Promise((_, reject) => setTimeout(() => reject(new Error(url + ' timeout')), TIMEOUT))
new Promise<Response>((_, reject) => setTimeout(() => reject(new Error(url + ' timeout')), TIMEOUT))
]);
}

export async function fetchWithCustomTimeout(url, options, timeout) {
export async function fetchWithCustomTimeout(url, options, timeout):Promise<Response> {
return Promise.race([
fetch(url, options).catch(err => { throw new Error(url + ' failed'); }),
new Promise((_, reject) => setTimeout(() => reject(new Error(url + ' timeout')), timeout))
new Promise<Response>((_, reject) => setTimeout(() => reject(new Error(url + ' timeout')), timeout))
]);
}

File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { checkResponse, fetchWithTimeout } from './fetchUtil';

export async function getContactChannels(server, token, viewRevision, channelRevision) {
export async function getContactChannels(server, token, viewRevision?, channelRevision?) {
let host = "";
if (server) {
host = `https://${server}`;
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,21 @@ import React, { useState, useEffect, useRef } from 'react';
import { CarouselWrapper } from './Carousel.styled';
import { CloseOutlined } from '@ant-design/icons';
import ReactResizeDetector from 'react-resize-detector';
interface Props {
pad?:any
items?:any
itemRenderer?:any
itemRemove?:any

export function Carousel({ pad, items, itemRenderer, itemRemove }) {
}
export function Carousel({ pad, items, itemRenderer, itemRemove }:Props) {
const [slots, setSlots] = useState([]);

let carousel = useRef();
let carousel = useRef<any>();

const RemoveItem = ({ index }) => {
if (itemRemove) {
return <div class="delitem" onClick={() => itemRemove(index)}><CloseOutlined /></div>
return <div className="delitem" onClick={() => itemRemove(index)}><CloseOutlined /></div>
}
return <></>
}
Expand All @@ -22,8 +28,8 @@ export function Carousel({ pad, items, itemRenderer, itemRemove }) {
<ReactResizeDetector handleWidth={true} handleHeight={false}>
{({ width, height }) => {
return (
<div class="item noselect">
<div class="asset">{ itemRenderer(items[i], i) }</div>
<div className="item noselect">
<div className="asset">{ itemRenderer(items[i], i) }</div>
<RemoveItem index={i} />
</div>
);
Expand All @@ -32,14 +38,14 @@ export function Carousel({ pad, items, itemRenderer, itemRemove }) {
));
}
if (items.length > 0) {
assets.push(<div class="space"></div>)
assets.push(<div className="space"></div>)
}
setSlots(assets);
}, [items, itemRenderer]);

return (
<CarouselWrapper>
<div class="carousel" style={{ paddingLeft: pad + 32 }} ref={carousel}>
<div className="carousel" style={{ paddingLeft: pad + 32 }} ref={carousel}>
{slots}
</div>
</CarouselWrapper>
Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { createContext } from 'react';
import { useAccountContext } from './useAccountContext.hook';
import { defaultAccountContext, useAccountContext } from './useAccountContext.hook';

export const AccountContext = createContext({});
export const AccountContext = createContext(defaultAccountContext);

export function AccountContextProvider({ children }) {
const { state, actions } = useAccountContext();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { createContext } from 'react';
import { useAppContext } from './useAppContext.hook';
import { defaultAppContext, useAppContext } from './useAppContext.hook';

export const AppContext = createContext({});
export const AppContext = createContext(defaultAppContext);

export function AppContextProvider({ children }) {
const { state, actions } = useAppContext();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { createContext } from 'react';
import { useCardContext } from './useCardContext.hook';
import { defaultCardContext, useCardContext } from './useCardContext.hook';

export const CardContext = createContext({});
export const CardContext = createContext(defaultCardContext);

export function CardContextProvider({ children }) {
const { state, actions } = useCardContext();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { createContext } from 'react';
import { useChannelContext } from './useChannelContext.hook';
import { defaultChannelContext, useChannelContext } from './useChannelContext.hook';

export const ChannelContext = createContext({});
export const ChannelContext = createContext(defaultChannelContext);

export function ChannelContextProvider({ children }) {
const { state, actions } = useChannelContext();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { createContext } from 'react';
import { useConversationContext } from './useConversationContext.hook';
import { defaultConversionContext, useConversationContext } from './useConversationContext.hook';

export const ConversationContext = createContext({});
export const ConversationContext = createContext(defaultConversionContext);

export function ConversationContextProvider({ children }) {
const { state, actions } = useConversationContext();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { createContext } from 'react';
import { useProfileContext } from './useProfileContext.hook';
import { defaultProfileContext, useProfileContext } from './useProfileContext.hook';

export const ProfileContext = createContext({});
export const ProfileContext = createContext(defaultProfileContext);

export function ProfileContextProvider({ children }) {
const { state, actions } = useProfileContext();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { createContext } from 'react';
import { useRingContext } from './useRingContext.hook';
import { defaultRingContext, useRingContext } from './useRingContext.hook';

export const RingContext = createContext({});
export const RingContext = createContext(defaultRingContext);

export function RingContextProvider({ children }) {
const { state, actions } = useRingContext();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { createContext } from 'react';
import { useSettingsContext } from './useSettingsContext.hook';
import { defaultSettingsContext, useSettingsContext } from './useSettingsContext.hook';

export const SettingsContext = createContext({});
export const SettingsContext = createContext(defaultSettingsContext);

export function SettingsContextProvider({ children }) {
const { state, actions } = useSettingsContext();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { createContext } from 'react';
import { useStoreContext } from './useStoreContext.hook';
import { defaultStoreContext, useStoreContext } from './useStoreContext.hook';

export const StoreContext = createContext({});
export const StoreContext = createContext(defaultStoreContext);

export function StoreContextProvider({ children }) {
const { state, actions } = useStoreContext();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { createContext } from 'react';
import { useUploadContext } from './useUploadContext.hook';
import { defaultUploadContext, useUploadContext } from './useUploadContext.hook';

export const UploadContext = createContext({});
export const UploadContext = createContext(defaultUploadContext);

export function UploadContextProvider({ children }) {
const { state, actions } = useUploadContext();
Expand Down
File renamed without changes.
File renamed without changes.
Loading
Loading