diff --git a/website/src/App.tsx b/website/src/App.tsx index fd0a692..efdce6a 100644 --- a/website/src/App.tsx +++ b/website/src/App.tsx @@ -592,6 +592,7 @@ class App extends Component { isolateEntry={this.handleIsolateEntry} optionsDispatch={this.handleOptionsUpdate} user={this.state.user} + loadUser={this.handleLoadUser} /> {this.state.user?.level === "editor" && diff --git a/website/src/screens/Wordlist.tsx b/website/src/screens/Wordlist.tsx index 5e3400a..13a8933 100644 --- a/website/src/screens/Wordlist.tsx +++ b/website/src/screens/Wordlist.tsx @@ -84,12 +84,15 @@ function amountOfWords(number: number): string { return `${number} word${number !== 1 ? "s" : ""}`; } -function Wordlist({ options, wordlist, isolateEntry, optionsDispatch, user }: { +let popupRef: Window | null = null; + +function Wordlist({ options, wordlist, isolateEntry, optionsDispatch, user, loadUser }: { options: Options, wordlist: WordlistWord[], isolateEntry: (ts: number) => void, optionsDispatch: (action: OptionsAction) => void, user: AT.LingdocsUser | undefined, + loadUser: () => void, }) { // @ts-ignore const [wordOpen, setWordOpen] = useState(undefined); @@ -104,6 +107,24 @@ function Wordlist({ options, wordlist, isolateEntry, optionsDispatch, user }: { const [monthsBackToKeep, setMonthsBackToKeep] = useState(6); const [wordsToDelete, setWordsToDelete] = useState([]); const [startedWithWordsToReview] = useState(forReview(wordlist).length !== 0); + useEffect(() => { + window.addEventListener("message", handleIncomingMessage); + return () => { + window.removeEventListener("message", handleIncomingMessage); + }; + // eslint-disable-next-line + }, []); + // TODO put the account url in an imported constant + function handleIncomingMessage(event: MessageEvent) { + if ( + event.origin === "https://account.lingdocs.com" + && (event.data === "signed in") + && popupRef + ) { + loadUser(); + popupRef.close(); + } + } useEffect(() => { window.addEventListener("scroll", handleScroll); return () => window.removeEventListener("scroll", handleScroll); @@ -164,6 +185,9 @@ function Wordlist({ options, wordlist, isolateEntry, optionsDispatch, user }: { deleteWordFromWordlist(toDelete); setShowingCleanup(false); } + function handleOpenSignup() { + popupRef = window.open("https://account.lingdocs.com", "account", "height=800,width=500,top=50,left=400"); + } function WordlistBrowsingWord({ word } : { word: WordlistWord }) { const [confirmDelete, setConfirmDelete] = useState(false); return
@@ -282,7 +306,7 @@ function Wordlist({ options, wordlist, isolateEntry, optionsDispatch, user }: {
  • $1/month or $10/year - cancel any time
  • : } - {!user && } + {!user && }
    ;