-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathindex.tsx
More file actions
142 lines (137 loc) · 4.15 KB
/
index.tsx
File metadata and controls
142 lines (137 loc) · 4.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
import Paper from '@mui/material/Paper';
import Step from '@mui/material/Step';
import StepContent from '@mui/material/StepContent';
import StepLabel from '@mui/material/StepLabel';
import Stepper from '@mui/material/Stepper';
import Typography from '@mui/material/Typography';
import clsx from 'clsx';
import Link from 'next/link';
import { useRef, useState } from 'react';
import { Download, Progress } from '@/components/Step';
import { AuthInfo } from '@/lib/gsi';
import Step1SignIn from '@/steps/1-sign-in';
import Step2Generate from '@/steps/2-generate';
import Step3Download from '@/steps/3-download';
import styles from '@/styles/index.module.css';
export default function Index(): JSX.Element {
const [authInfo, setAuthInfo] = useState<AuthInfo>();
const [googleReady, setGoogleReady] = useState(Promise.resolve(false));
const [docUrl, setDocUrl] = useState('');
const [error, setError] = useState('');
const [actionLoading, setActionLoading] = useState(false);
const [tokenClient, setTokenClient] = useState<
google.accounts.oauth2.TokenClient | undefined
>();
const tokenCallback =
useRef<(resp: google.accounts.oauth2.TokenResponse) => void>();
const [progress, setProgress] = useState<Progress>({
percent: 0,
status: 'Fetching doc revisions',
});
const [download, setDownload] = useState<Download>();
const [stepIndex, setStepIndex] = useState(0);
const back = (): void => {
setStepIndex(stepIndex - 1);
setError('');
setDownload(undefined);
};
const next = async (): Promise<void> => {
setStepIndex(stepIndex + 1);
};
const steps = [
{
title: 'Sign in with Google',
content: (
<Step1SignIn
authInfo={authInfo}
setAuthInfo={setAuthInfo}
setGoogleReady={setGoogleReady}
error={error}
setError={setError}
setTokenClient={setTokenClient}
tokenCallback={tokenCallback}
next={next}
/>
),
},
{
title: 'Enter the Google Doc URL or ID',
content: (
<Step2Generate
docUrl={docUrl}
setDocUrl={setDocUrl}
actionLoading={actionLoading}
setActionLoading={setActionLoading}
error={error}
setError={setError}
setDownload={setDownload}
googleReady={googleReady}
setProgress={setProgress}
tokenClient={tokenClient}
tokenCallback={tokenCallback}
next={next}
back={back}
/>
),
},
{
title: 'Download the repo',
content: (
<Step3Download
download={download}
progress={progress}
error={error}
setError={setError}
back={back}
/>
),
},
];
return (
<>
<Typography className={styles.intro}>
Google Docs keeps a detailed history of each doc, which tracks the
changes and can restore previous versions later, just like Git.
</Typography>
<Typography className={styles.intro}>
doc2git lets you create an actual Git repo from this history, with a
plain text version of your doc and a commit for each revision with the
correct time and author.
</Typography>
<Typography className={styles.intro}>
With the Git repo, you can use all your usual tools to examine the doc
history, including <span className={styles.code}>git blame</span>.
</Typography>
<Typography className={styles.intro}>
It all runs securely in your browser. Even the Git repo is created
client-side using{' '}
<Link
href="https://github.com/isomorphic-git/isomorphic-git"
target="_blank">
isomorphic-git
</Link>{' '}
and delivered as a .zip file you can download.
</Typography>
<Typography className={styles.intro}>
You can check out the code of{' '}
<Link href="https://github.com/repography/doc2git" target="_blank">
doc2git on GitHub
</Link>
, including instructions on how to host doc2git yourself.
</Typography>
<Paper elevation={3} className={styles.steps}>
<Stepper orientation="vertical" activeStep={stepIndex}>
{steps.map(({ title, content }, i) => (
<Step key={i}>
<StepLabel className={styles.stepTitle}>{title}</StepLabel>
<StepContent
className={clsx({ [styles.stepContent]: i === stepIndex })}>
{content}
</StepContent>
</Step>
))}
</Stepper>
</Paper>
</>
);
}