Skip to content

Commit e8b9c51

Browse files
committed
added walltaker credential input
1 parent fa073c7 commit e8b9c51

8 files changed

+302
-111
lines changed

README.md

+2
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,9 @@ yarn
4343
yarn build
4444
yarn preview
4545
```
46+
4647
4. open one of the URLs listed in your browser
48+
4749
### Social
4850

4951
- We have an [e6 forum thread](https://e621.net/forum_topics/23796). We'd love to hear your feedback.

src/e621/E621Credentials.tsx

+5-17
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import styled from 'styled-components';
22
import { E621Service } from './E621Service';
33
import { useCallback, useMemo, useState } from 'react';
44
import {
5+
Button,
56
SettingsInfo,
67
SettingsLabel,
78
Space,
@@ -30,21 +31,6 @@ const StyledE621SaveCredentials = styled.div`
3031
align-items: center;
3132
`;
3233

33-
const StyledE621SaveCredentialsButton = styled.button`
34-
background: var(--button-background);
35-
color: var(--button-color);
36-
border-radius: var(--border-radius);
37-
padding: 4px 8px;
38-
transition:
39-
background 0.2s,
40-
opacity 0.2s;
41-
cursor: ${props => (props.disabled ? 'not-allowed' : 'pointer')};
42-
&:hover {
43-
background: var(--primary);
44-
}
45-
opacity: ${props => (props.disabled ? 0.5 : 1)};
46-
`;
47-
4834
export const E621CredentialsInput = ({
4935
service,
5036
initialValue,
@@ -85,6 +71,7 @@ export const E621CredentialsInput = ({
8571
<Space size='small' />
8672
<SettingsLabel>Username</SettingsLabel>
8773
<TextInput
74+
name='e621-username'
8875
style={{ gridColumn: '2 / -1' }}
8976
value={input?.username}
9077
onChange={username =>
@@ -100,6 +87,7 @@ export const E621CredentialsInput = ({
10087
<Space size='small' />
10188
<SettingsLabel>API Key</SettingsLabel>
10289
<TextInput
90+
name='e621-api-key'
10391
style={{ gridColumn: '2 / -1' }}
10492
value={input?.apiKey}
10593
onChange={apiKey =>
@@ -117,12 +105,12 @@ export const E621CredentialsInput = ({
117105
<StyledE621SaveCredentials>
118106
{loading && <Spinner />}
119107
<Space size='small' />
120-
<StyledE621SaveCredentialsButton
108+
<Button
121109
onClick={!loading ? onSave : undefined}
122110
disabled={!hasData || locked}
123111
>
124112
Save
125-
</StyledE621SaveCredentialsButton>
113+
</Button>
126114
</StyledE621SaveCredentials>
127115
</StyledE621CredentialsInput>
128116
);

src/e621/E621Search.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ export const E621Search = () => {
9494

9595
return (
9696
<StyledE621Search>
97-
<SettingsDescription>Add images from e621</SettingsDescription>
97+
<SettingsDescription>Add images from e621's search</SettingsDescription>
9898
<SettingsLabel htmlFor='tags'>Tags</SettingsLabel>
9999
<TextInput
100100
id='tags'

src/local/LocalImport.tsx

+3-1
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,9 @@ export const LocalImport = () => {
8686

8787
return (
8888
<StyledLocalImport>
89-
<SettingsDescription>Add images from your device</SettingsDescription>
89+
<SettingsDescription>
90+
Add images from your device storage
91+
</SettingsDescription>
9092
<Space size='medium' />
9193
<input
9294
type='file'
+104
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
import styled from 'styled-components';
2+
import { useCallback, useMemo, useState } from 'react';
3+
import { Button, SettingsLabel, Space, Spinner, TextInput } from '../common';
4+
import { WalltakerService } from './WalltakerService';
5+
import { WalltakerCredentials } from './WalltakerProvider';
6+
7+
export interface WalltakerCredentialsInputProps {
8+
service: WalltakerService;
9+
initialValue?: Partial<WalltakerCredentials>;
10+
onSaved?: (credentials: WalltakerCredentials) => void;
11+
disabled?: boolean;
12+
}
13+
14+
const StyledE621CredentialsInput = styled.div`
15+
grid-column: 1 / -1;
16+
display: grid;
17+
grid-template-columns: auto 1fr auto;
18+
`;
19+
20+
const StyledE621SaveCredentials = styled.div`
21+
grid-column: 1 / -1;
22+
display: flex;
23+
justify-content: flex-end;
24+
align-items: center;
25+
`;
26+
27+
export const WalltakerCredentialsInput = ({
28+
service,
29+
initialValue,
30+
onSaved,
31+
disabled,
32+
}: WalltakerCredentialsInputProps) => {
33+
const [input, setInput] = useState<Partial<WalltakerCredentials>>({
34+
...initialValue,
35+
username: '',
36+
apiKey: '',
37+
});
38+
const [loading, setLoading] = useState(false);
39+
40+
const onSave = useCallback(async () => {
41+
const credentials = input as WalltakerCredentials;
42+
setLoading(true);
43+
const valid = await service.testCredentials(credentials);
44+
if (valid) {
45+
onSaved?.(credentials);
46+
}
47+
}, [input, onSaved, service]);
48+
49+
const hasData = useMemo(
50+
() => input?.username && input?.apiKey,
51+
[input?.username, input?.apiKey]
52+
);
53+
54+
const locked = useMemo(() => loading || disabled, [loading, disabled]);
55+
56+
return (
57+
<StyledE621CredentialsInput>
58+
<Space size='small' />
59+
<SettingsLabel>Username</SettingsLabel>
60+
<TextInput
61+
name='walltaker-username'
62+
style={{ gridColumn: '2 / -1' }}
63+
value={input?.username}
64+
onChange={username =>
65+
setInput({
66+
...input,
67+
username,
68+
})
69+
}
70+
placeholder='Username'
71+
autoComplete='username'
72+
disabled={locked}
73+
/>
74+
<Space size='small' />
75+
<SettingsLabel>API Key</SettingsLabel>
76+
<TextInput
77+
name='walltaker-api-key'
78+
style={{ gridColumn: '2 / -1' }}
79+
value={input?.apiKey}
80+
onChange={apiKey =>
81+
setInput({
82+
...input,
83+
apiKey,
84+
})
85+
}
86+
placeholder='API Key'
87+
type='password'
88+
autoComplete='current-password'
89+
disabled={locked}
90+
/>
91+
<Space size='small' />
92+
<StyledE621SaveCredentials>
93+
{loading && <Spinner />}
94+
<Space size='small' />
95+
<Button
96+
onClick={!loading ? onSave : undefined}
97+
disabled={!hasData || locked}
98+
>
99+
Save
100+
</Button>
101+
</StyledE621SaveCredentials>
102+
</StyledE621CredentialsInput>
103+
);
104+
};

src/walltaker/WalltakerProvider.tsx

+6-1
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,14 @@ import { uniqBy } from 'lodash';
1414
import { useImages } from '../settings';
1515
import { ImageServiceType, ImageType } from '../types';
1616

17+
export interface WalltakerCredentials {
18+
username: string;
19+
apiKey?: string;
20+
}
21+
1722
export interface WalltakerSettings {
1823
enabled?: boolean;
19-
username?: string;
24+
credentials?: WalltakerCredentials;
2025
ids?: number[];
2126
}
2227

0 commit comments

Comments
 (0)