The NavigationMixin solution should work as well, with minor modification. According to this blog post, rather than using NavigationMixin.Navigate with type argument standard__namedPage and ContentDocumentId, you should be using standard__webPage along with the file URL.
previewFile(file){
if(!this.usedInCommunity){
this[NavigationMixin.Navigate]({
type: 'standard__namedPage',
attributes: {
pageName: 'filePreview'
},
state : {
selectedRecordId: file.ContentDocumentId
}
});
} else if(this.usedInCommunity){
this[NavigationMixin.Navigate]({
type: 'standard__webPage',
attributes: {
url: file.fileUrl
}
}, false );
}
}