[verb て-form] + いるあいだに [verb て-form] + いたあいだに (past tense)
Polite form: [verb て-form] + いますあいだに
The grammar structure ~ているあいだに is used to express that something happens during the time that another action is ongoing. It combines the continuous form 〜~ている with あいだに ("during / while"), creating the meaning "while (someone) is doing ~, (something else happens)."
The first clause (before あいだに) describes an ongoing action or state, and the second clause describes an event that occurs at some point during that time.
あいだに and あいだ (without に) work differently.
あいだに emphasizes that a specific event occurs at some point during the duration. The event in the second clause does not last the entire time.
あいだ (without に) implies that the second action continues throughout the entire duration.
The subject of the first clause and the subject of the second clause are often different. When the same person is doing both actions, the sentence emphasizes that one thing happened in the middle of the other.
This pattern can also be used with states rather than actions: